]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/dc/ACLView.js
ui: fix missing htmlEncodes
[pve-manager.git] / www / manager6 / dc / ACLView.js
1 Ext.define('PVE.dc.ACLAdd', {
2 extend: 'Proxmox.window.Edit',
3 alias: ['widget.pveACLAdd'],
4 url: '/access/acl',
5 method: 'PUT',
6 isAdd: true,
7 initComponent : function() {
8
9 var me = this;
10
11 me.isCreate = true;
12
13 var 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: 'pveRoleSelector',
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 var 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
78 Ext.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 var me = this;
93
94 var 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: function(item) {
109 if (item.data.path === me.path) {
110 return true;
111 }
112 }
113 }));
114 }
115
116 var render_ugid = function(ugid, metaData, record) {
117 if (record.data.type == 'group') {
118 return '@' + ugid;
119 }
120
121 return Ext.String.htmlEncode(ugid);
122 };
123
124 var columns = [
125 {
126 header: gettext('User') + '/' + gettext('Group') + '/' + gettext('API Token'),
127 flex: 1,
128 sortable: true,
129 renderer: render_ugid,
130 dataIndex: 'ugid'
131 },
132 {
133 header: gettext('Role'),
134 flex: 1,
135 sortable: true,
136 dataIndex: 'roleid'
137 }
138 ];
139
140 if (!me.path) {
141 columns.unshift({
142 header: gettext('Path'),
143 flex: 1,
144 sortable: true,
145 dataIndex: 'path'
146 });
147 columns.push({
148 header: gettext('Propagate'),
149 width: 80,
150 sortable: true,
151 dataIndex: 'propagate'
152 });
153 }
154
155 var sm = Ext.create('Ext.selection.RowModel', {});
156
157 var reload = function() {
158 store.load();
159 };
160
161 var remove_btn = new Proxmox.button.Button({
162 text: gettext('Remove'),
163 disabled: true,
164 selModel: sm,
165 confirmMsg: gettext('Are you sure you want to remove this entry'),
166 handler: function(btn, event, rec) {
167 var params = {
168 'delete': 1,
169 path: rec.data.path,
170 roles: rec.data.roleid
171 };
172 if (rec.data.type === 'group') {
173 params.groups = rec.data.ugid;
174 } else if (rec.data.type === 'user') {
175 params.users = rec.data.ugid;
176 } else if (rec.data.type === 'token') {
177 params.tokens = rec.data.ugid;
178 } else {
179 throw 'unknown data type';
180 }
181
182 Proxmox.Utils.API2Request({
183 url: '/access/acl',
184 params: params,
185 method: 'PUT',
186 waitMsgTarget: me,
187 callback: function() {
188 reload();
189 },
190 failure: function (response, opts) {
191 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
192 }
193 });
194 }
195 });
196
197 Proxmox.Utils.monStoreErrors(me, store);
198
199 Ext.apply(me, {
200 store: store,
201 selModel: sm,
202 tbar: [
203 {
204 text: gettext('Add'),
205 menu: {
206 xtype: 'menu',
207 items: [
208 {
209 text: gettext('Group Permission'),
210 iconCls: 'fa fa-fw fa-group',
211 handler: function() {
212 var win = Ext.create('PVE.dc.ACLAdd',{
213 aclType: 'group',
214 path: me.path
215 });
216 win.on('destroy', reload);
217 win.show();
218 }
219 },
220 {
221 text: gettext('User Permission'),
222 iconCls: 'fa fa-fw fa-user',
223 handler: function() {
224 var win = Ext.create('PVE.dc.ACLAdd',{
225 aclType: 'user',
226 path: me.path
227 });
228 win.on('destroy', reload);
229 win.show();
230 }
231 },
232 {
233 text: gettext('API Token Permission'),
234 iconCls: 'fa fa-fw fa-user-o',
235 handler: function() {
236 var win = Ext.create('PVE.dc.ACLAdd',{
237 aclType: 'token',
238 path: me.path
239 });
240 win.on('destroy', reload);
241 win.show();
242 }
243 }
244 ]
245 }
246 },
247 remove_btn
248 ],
249 viewConfig: {
250 trackOver: false
251 },
252 columns: columns,
253 listeners: {
254 activate: reload
255 }
256 });
257
258 me.callParent();
259 }
260 }, function() {
261
262 Ext.define('pve-acl', {
263 extend: 'Ext.data.Model',
264 fields: [
265 'path', 'type', 'ugid', 'roleid',
266 {
267 name: 'propagate',
268 type: 'boolean'
269 }
270 ]
271 });
272
273 });