]> git.proxmox.com Git - pve-manager.git/blame_incremental - www/manager6/dc/ACLView.js
ui: dc/UserEdit: eslint fixes and code cleanup/refactoring
[pve-manager.git] / www / manager6 / dc / ACLView.js
... / ...
CommitLineData
1Ext.define('PVE.dc.ACLAdd', {
2 extend: 'Proxmox.window.Edit',
3 alias: ['widget.pveACLAdd'],
4
5 url: '/access/acl',
6 method: 'PUT',
7 isAdd: true,
8 isCreate: true,
9
10 initComponent: function() {
11 let me = this;
12
13 let items = [
14 {
15 xtype: me.path ? 'hiddenfield' : 'pvePermPathSelector',
16 name: 'path',
17 value: me.path,
18 allowBlank: false,
19 fieldLabel: gettext('Path'),
20 },
21 ];
22
23 if (me.aclType === 'group') {
24 me.subject = gettext("Group Permission");
25 items.push({
26 xtype: 'pveGroupSelector',
27 name: 'groups',
28 fieldLabel: gettext('Group'),
29 });
30 } else if (me.aclType === 'user') {
31 me.subject = gettext("User Permission");
32 items.push({
33 xtype: 'pveUserSelector',
34 name: 'users',
35 fieldLabel: gettext('User'),
36 });
37 } else if (me.aclType === 'token') {
38 me.subject = gettext("API Token Permission");
39 items.push({
40 xtype: 'pveTokenSelector',
41 name: 'tokens',
42 fieldLabel: gettext('API Token'),
43 });
44 } else {
45 throw "unknown ACL type";
46 }
47
48 items.push({
49 xtype: 'pmxRoleSelector',
50 name: 'roles',
51 value: 'NoAccess',
52 fieldLabel: gettext('Role'),
53 });
54
55 if (!me.path) {
56 items.push({
57 xtype: 'proxmoxcheckbox',
58 name: 'propagate',
59 checked: true,
60 uncheckedValue: 0,
61 fieldLabel: gettext('Propagate'),
62 });
63 }
64
65 let ipanel = Ext.create('Proxmox.panel.InputPanel', {
66 items: items,
67 onlineHelp: 'pveum_permission_management',
68 });
69
70 Ext.apply(me, {
71 items: [ipanel],
72 });
73
74 me.callParent();
75 },
76});
77
78Ext.define('PVE.dc.ACLView', {
79 extend: 'Ext.grid.GridPanel',
80
81 alias: ['widget.pveACLView'],
82
83 onlineHelp: 'chapter_user_management',
84
85 stateful: true,
86 stateId: 'grid-acls',
87
88 // use fixed path
89 path: undefined,
90
91 initComponent: function() {
92 let me = this;
93
94 let store = Ext.create('Ext.data.Store', {
95 model: 'pve-acl',
96 proxy: {
97 type: 'proxmox',
98 url: "/api2/json/access/acl",
99 },
100 sorters: {
101 property: 'path',
102 order: 'DESC',
103 },
104 });
105
106 if (me.path) {
107 store.addFilter(Ext.create('Ext.util.Filter', {
108 filterFn: item => item.data.path === me.path,
109 }));
110 }
111
112 let render_ugid = function(ugid, metaData, record) {
113 if (record.data.type === 'group') {
114 return '@' + ugid;
115 }
116
117 return Ext.String.htmlEncode(ugid);
118 };
119
120 let columns = [
121 {
122 header: gettext('User') + '/' + gettext('Group') + '/' + gettext('API Token'),
123 flex: 1,
124 sortable: true,
125 renderer: render_ugid,
126 dataIndex: 'ugid',
127 },
128 {
129 header: gettext('Role'),
130 flex: 1,
131 sortable: true,
132 dataIndex: 'roleid',
133 },
134 ];
135
136 if (!me.path) {
137 columns.unshift({
138 header: gettext('Path'),
139 flex: 1,
140 sortable: true,
141 dataIndex: 'path',
142 });
143 columns.push({
144 header: gettext('Propagate'),
145 width: 80,
146 sortable: true,
147 dataIndex: 'propagate',
148 });
149 }
150
151 let sm = Ext.create('Ext.selection.RowModel', {});
152
153 let remove_btn = new Proxmox.button.Button({
154 text: gettext('Remove'),
155 disabled: true,
156 selModel: sm,
157 confirmMsg: gettext('Are you sure you want to remove this entry'),
158 handler: function(btn, event, rec) {
159 var params = {
160 'delete': 1,
161 path: rec.data.path,
162 roles: rec.data.roleid,
163 };
164 if (rec.data.type === 'group') {
165 params.groups = rec.data.ugid;
166 } else if (rec.data.type === 'user') {
167 params.users = rec.data.ugid;
168 } else if (rec.data.type === 'token') {
169 params.tokens = rec.data.ugid;
170 } else {
171 throw 'unknown data type';
172 }
173
174 Proxmox.Utils.API2Request({
175 url: '/access/acl',
176 params: params,
177 method: 'PUT',
178 waitMsgTarget: me,
179 callback: () => store.load(),
180 failure: response => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
181 });
182 },
183 });
184
185 Proxmox.Utils.monStoreErrors(me, store);
186
187 Ext.apply(me, {
188 store: store,
189 selModel: sm,
190 tbar: [
191 {
192 text: gettext('Add'),
193 menu: {
194 xtype: 'menu',
195 items: [
196 {
197 text: gettext('Group Permission'),
198 iconCls: 'fa fa-fw fa-group',
199 handler: function() {
200 var win = Ext.create('PVE.dc.ACLAdd', {
201 aclType: 'group',
202 path: me.path,
203 });
204 win.on('destroy', () => store.load());
205 win.show();
206 },
207 },
208 {
209 text: gettext('User Permission'),
210 iconCls: 'fa fa-fw fa-user',
211 handler: function() {
212 var win = Ext.create('PVE.dc.ACLAdd', {
213 aclType: 'user',
214 path: me.path,
215 });
216 win.on('destroy', () => store.load());
217 win.show();
218 },
219 },
220 {
221 text: gettext('API Token Permission'),
222 iconCls: 'fa fa-fw fa-user-o',
223 handler: function() {
224 let win = Ext.create('PVE.dc.ACLAdd', {
225 aclType: 'token',
226 path: me.path,
227 });
228 win.on('destroy', () => store.load());
229 win.show();
230 },
231 },
232 ],
233 },
234 },
235 remove_btn,
236 ],
237 viewConfig: {
238 trackOver: false,
239 },
240 columns: columns,
241 listeners: {
242 activate: () => store.load(),
243 },
244 });
245
246 me.callParent();
247 },
248}, function() {
249 Ext.define('pve-acl', {
250 extend: 'Ext.data.Model',
251 fields: [
252 'path', 'type', 'ugid', 'roleid',
253 {
254 name: 'propagate',
255 type: 'boolean',
256 },
257 ],
258 });
259});