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