]> git.proxmox.com Git - proxmox-backup.git/blob - www/config/ACLView.js
gui: add API token ACLs
[proxmox-backup.git] / www / config / ACLView.js
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) {
8 return `${data.path} for ${data.ugid} - ${data.roleid}`;
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
26 title: gettext('Permissions'),
27
28 aclPath: undefined,
29 aclExact: undefined,
30
31 controller: {
32 xclass: 'Ext.app.ViewController',
33
34 addUserACL: function() {
35 let me = this;
36 let view = me.getView();
37 Ext.create('PBS.window.ACLEdit', {
38 path: view.aclPath,
39 aclType: 'user',
40 listeners: {
41 destroy: function() {
42 me.reload();
43 },
44 },
45 }).show();
46 },
47
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
63 removeACL: function(btn, event, rec) {
64 let me = this;
65 Proxmox.Utils.API2Request({
66 url: '/access/acl',
67 method: 'PUT',
68 params: {
69 'delete': 1,
70 path: rec.data.path,
71 role: rec.data.roleid,
72 auth_id: rec.data.ugid,
73 },
74 callback: function() {
75 me.reload();
76 },
77 failure: function(response, opts) {
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);
96 Proxmox.Utils.monStoreErrors(view, view.getStore().rstore);
97 },
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 },
108 },
109
110 store: {
111 type: 'diff',
112 autoDestroy: true,
113 autoDestroyRstore: true,
114 sorters: 'aclid',
115 rstore: {
116 type: 'update',
117 storeid: 'pmx-acls',
118 model: 'pmx-acls',
119 interval: 5000,
120 },
121 },
122
123 tbar: [
124 {
125 text: gettext('Add'),
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 },
141 },
142 {
143 xtype: 'proxmoxStdRemoveButton',
144 handler: 'removeACL',
145 callback: 'reload',
146 },
147 ],
148
149 columns: [
150 {
151 header: gettext('Path'),
152 width: 200,
153 sortable: true,
154 renderer: Ext.String.htmlEncode,
155 dataIndex: 'path',
156 },
157 {
158 header: gettext('User/Group/API Token'),
159 width: 100,
160 sortable: true,
161 renderer: Ext.String.htmlEncode,
162 dataIndex: 'ugid',
163 },
164 {
165 header: gettext('Role'),
166 width: 80,
167 sortable: true,
168 dataIndex: 'roleid',
169 },
170 {
171 header: gettext('Propagate'),
172 width: 150,
173 sortable: true,
174 renderer: Proxmox.Utils.format_boolean,
175 dataIndex: 'propagate',
176 },
177 ],
178
179 });