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