]>
Commit | Line | Data |
---|---|---|
0542cfdf DC |
1 | Ext.define('pmx-acls', { |
2 | extend: 'Ext.data.Model', | |
3 | fields: [ | |
4 | 'path', 'ugid', 'ugid_type', 'roleid', 'propagate', | |
5 | { | |
6 | name: 'aclid', | |
7 | calculate: function(data) { | |
bfa0146c | 8 | return `${data.path} for ${data.ugid} - ${data.roleid}`; |
0542cfdf DC |
9 | }, |
10 | }, | |
11 | ], | |
12 | idProperty: 'aclid', | |
13 | proxy: { | |
14 | type: 'proxmox', | |
15 | url: '/api2/json/access/acl', | |
16 | }, | |
17 | }); | |
18 | ||
19 | Ext.define('PBS.config.ACLView', { | |
20 | extend: 'Ext.grid.GridPanel', | |
21 | alias: 'widget.pbsACLView', | |
22 | ||
23 | stateful: true, | |
24 | stateId: 'grid-acls', | |
25 | ||
ee1458b6 | 26 | title: gettext('Permissions'), |
0542cfdf DC |
27 | |
28 | aclPath: undefined, | |
29 | aclExact: undefined, | |
30 | ||
31 | controller: { | |
32 | xclass: 'Ext.app.ViewController', | |
33 | ||
184a3763 | 34 | addUserACL: function() { |
0542cfdf DC |
35 | let me = this; |
36 | let view = me.getView(); | |
184a3763 | 37 | Ext.create('PBS.window.ACLEdit', { |
0542cfdf | 38 | path: view.aclPath, |
184a3763 | 39 | aclType: 'user', |
0542cfdf DC |
40 | listeners: { |
41 | destroy: function() { | |
42 | me.reload(); | |
43 | }, | |
44 | }, | |
184a3763 | 45 | }).show(); |
0542cfdf DC |
46 | }, |
47 | ||
184a3763 FG |
48 | addTokenACL: function() { |
49 | let me = this; | |
50 | let view = me.getView(); | |
51 | Ext.create('PBS.window.ACLEdit', { | |
52 | path: view.aclPath, | |
53 | aclType: 'token', | |
54 | listeners: { | |
55 | destroy: function() { | |
56 | me.reload(); | |
57 | }, | |
58 | }, | |
59 | }).show(); | |
60 | }, | |
61 | ||
62 | ||
0542cfdf DC |
63 | removeACL: function(btn, event, rec) { |
64 | let me = this; | |
65 | Proxmox.Utils.API2Request({ | |
65b0cea6 | 66 | url: '/access/acl', |
0542cfdf DC |
67 | method: 'PUT', |
68 | params: { | |
69 | 'delete': 1, | |
70 | path: rec.data.path, | |
71 | role: rec.data.roleid, | |
8b600f99 | 72 | 'auth-id': rec.data.ugid, |
0542cfdf DC |
73 | }, |
74 | callback: function() { | |
75 | me.reload(); | |
76 | }, | |
65b0cea6 | 77 | failure: function(response, opts) { |
0542cfdf DC |
78 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); |
79 | }, | |
80 | }); | |
81 | }, | |
82 | ||
83 | reload: function() { this.getView().getStore().rstore.load(); }, | |
84 | ||
85 | init: function(view) { | |
86 | let proxy = view.getStore().rstore.getProxy(); | |
87 | ||
88 | let params = {}; | |
89 | if (view.aclPath !== undefined) { | |
90 | params.path = view.aclPath; | |
91 | } | |
92 | if (view.aclExact !== undefined) { | |
93 | params.exact = view.aclExact; | |
94 | } | |
95 | proxy.setExtraParams(params); | |
12710fd3 | 96 | Proxmox.Utils.monStoreErrors(view, view.getStore().rstore); |
0542cfdf | 97 | }, |
ed216fd7 TL |
98 | control: { |
99 | '#': { // view | |
100 | activate: function() { | |
101 | this.getView().getStore().rstore.startUpdate(); | |
102 | }, | |
103 | deactivate: function() { | |
104 | this.getView().getStore().rstore.stopUpdate(); | |
105 | }, | |
106 | }, | |
107 | }, | |
0542cfdf DC |
108 | }, |
109 | ||
110 | store: { | |
111 | type: 'diff', | |
112 | autoDestroy: true, | |
113 | autoDestroyRstore: true, | |
bfa0146c | 114 | sorters: 'aclid', |
0542cfdf DC |
115 | rstore: { |
116 | type: 'update', | |
117 | storeid: 'pmx-acls', | |
118 | model: 'pmx-acls', | |
0542cfdf DC |
119 | interval: 5000, |
120 | }, | |
121 | }, | |
122 | ||
123 | tbar: [ | |
124 | { | |
0542cfdf | 125 | text: gettext('Add'), |
184a3763 FG |
126 | menu: { |
127 | xtype: 'menu', | |
128 | items: [ | |
129 | { | |
130 | text: gettext('User Permission'), | |
131 | iconCls: 'fa fa-fw fa-user', | |
132 | handler: 'addUserACL', | |
133 | }, | |
134 | { | |
135 | text: gettext('API Token Permission'), | |
136 | iconCls: 'fa fa-fw fa-user-o', | |
137 | handler: 'addTokenACL', | |
138 | }, | |
139 | ], | |
140 | }, | |
0542cfdf DC |
141 | }, |
142 | { | |
143 | xtype: 'proxmoxStdRemoveButton', | |
144 | handler: 'removeACL', | |
145 | callback: 'reload', | |
146 | }, | |
147 | ], | |
148 | ||
149 | columns: [ | |
150 | { | |
151 | header: gettext('Path'), | |
ba2e4b15 | 152 | width: 250, |
0542cfdf DC |
153 | sortable: true, |
154 | renderer: Ext.String.htmlEncode, | |
155 | dataIndex: 'path', | |
156 | }, | |
157 | { | |
184a3763 | 158 | header: gettext('User/Group/API Token'), |
ba2e4b15 | 159 | width: 150, |
0542cfdf DC |
160 | sortable: true, |
161 | renderer: Ext.String.htmlEncode, | |
162 | dataIndex: 'ugid', | |
163 | }, | |
164 | { | |
165 | header: gettext('Role'), | |
ba2e4b15 | 166 | width: 100, |
0542cfdf DC |
167 | sortable: true, |
168 | dataIndex: 'roleid', | |
169 | }, | |
170 | { | |
171 | header: gettext('Propagate'), | |
ba2e4b15 | 172 | flex: 1, // last element flex looks better |
0542cfdf DC |
173 | sortable: true, |
174 | renderer: Proxmox.Utils.format_boolean, | |
175 | dataIndex: 'propagate', | |
176 | }, | |
177 | ], | |
0542cfdf | 178 | }); |