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