]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - src/panel/PermissionView.js
add EOL notice component
[proxmox-widget-toolkit.git] / src / panel / PermissionView.js
CommitLineData
b99a771b
FG
1Ext.define('pmx-permissions', {
2 extend: 'Ext.data.TreeModel',
3 fields: [
4 'text', 'type',
5 {
6 type: 'boolean', name: 'propagate',
7 },
8 ],
9});
10
11Ext.define('Proxmox.panel.PermissionViewPanel', {
12 extend: 'Ext.tree.Panel',
13 xtype: 'proxmoxPermissionViewPanel',
14
15 scrollable: true,
16 layout: 'fit',
17 rootVisible: false,
18 animate: false,
19 sortableColumns: false,
20
21 auth_id_name: "userid",
22 auth_id: undefined,
23
24 columns: [
25 {
26 xtype: 'treecolumn',
27 header: gettext('Path') + '/' + gettext('Permission'),
28 dataIndex: 'text',
29 flex: 6,
30 },
31 {
32 header: gettext('Propagate'),
33 dataIndex: 'propagate',
34 flex: 1,
35 renderer: function(value) {
36 if (Ext.isDefined(value)) {
37 return Proxmox.Utils.format_boolean(value);
38 }
39 return '';
40 },
41 },
42 ],
43
44 initComponent: function() {
45 let me = this;
46
47 Proxmox.Utils.API2Request({
48 url: '/access/permissions?' + encodeURIComponent(me.auth_id_name) + '=' + encodeURIComponent(me.auth_id),
49 method: 'GET',
50 failure: function(response, opts) {
51 Proxmox.Utils.setErrorMask(me, response.htmlStatus);
52 },
53 success: function(response, opts) {
54 Proxmox.Utils.setErrorMask(me, false);
55 let result = Ext.decode(response.responseText);
56 let data = result.data || {};
57
58 let root = {
59 name: '__root',
60 expanded: true,
61 children: [],
62 };
63 let idhash = {
64 '/': {
65 children: [],
66 text: '/',
67 type: 'path',
68 },
69 };
70 Ext.Object.each(data, function(path, perms) {
71 let path_item = {
72 text: path,
73 type: 'path',
74 children: [],
75 };
76 Ext.Object.each(perms, function(perm, propagate) {
77 let perm_item = {
78 text: perm,
79 type: 'perm',
80 propagate: propagate === 1 || propagate === true,
81 iconCls: 'fa fa-fw fa-unlock',
82 leaf: true,
83 };
84 path_item.children.push(perm_item);
85 path_item.expandable = true;
86 });
87 idhash[path] = path_item;
88 });
89
90 Ext.Object.each(idhash, function(path, item) {
91 let parent_item = idhash['/'];
92 if (path === '/') {
93 parent_item = root;
94 item.expanded = true;
95 } else {
96 let split_path = path.split('/');
97 while (split_path.pop()) {
98 let parent_path = split_path.join('/');
99 if (idhash[parent_path]) {
100 parent_item = idhash[parent_path];
101 break;
102 }
103 }
104 }
105 parent_item.children.push(item);
106 });
107
108 me.setRootNode(root);
109 },
110 });
111
112 me.callParent();
113
114 me.store.sorters.add(new Ext.util.Sorter({
115 sorterFn: function(rec1, rec2) {
116 let v1 = rec1.data.text,
117 v2 = rec2.data.text;
118 if (rec1.data.type !== rec2.data.type) {
119 v2 = rec1.data.type;
120 v1 = rec2.data.type;
121 }
122 if (v1 > v2) {
123 return 1;
124 } else if (v1 < v2) {
125 return -1;
126 }
127 return 0;
128 },
129 }));
130 },
131});
132
133Ext.define('Proxmox.PermissionView', {
134 extend: 'Ext.window.Window',
135 alias: 'widget.userShowPermissionWindow',
136 mixins: ['Proxmox.Mixin.CBind'],
137
138 scrollable: true,
139 width: 800,
140 height: 600,
141 layout: 'fit',
142 cbind: {
143 title: (get) => Ext.String.htmlEncode(get('auth_id')) +
144 ` - ${gettext('Granted Permissions')}`,
145 },
146 items: [{
147 xtype: 'proxmoxPermissionViewPanel',
148 cbind: {
149 auth_id: '{auth_id}',
150 auth_id_name: '{auth_id_name}',
151 },
152 }],
153});