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