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