]> git.proxmox.com Git - pmg-gui.git/blame - js/UserView.js
rules/objects: add mode selector dropdown
[pmg-gui.git] / js / UserView.js
CommitLineData
ec1dd829
DM
1Ext.define('pmg-users', {
2 extend: 'Ext.data.Model',
3 fields: [
c87d46fb 4 'userid', 'firstname', 'lastname', 'email', 'comment',
4195a809 5 'role', 'keys', 'realm', 'totp-lock',
ec1dd829 6 { type: 'boolean', name: 'enable' },
c87d46fb 7 { type: 'date', dateFormat: 'timestamp', name: 'expire' },
ec1dd829
DM
8 ],
9 proxy: {
10 type: 'proxmox',
c87d46fb 11 url: "/api2/json/access/users",
ec1dd829 12 },
c87d46fb 13 idProperty: 'userid',
ec1dd829
DM
14});
15
16Ext.define('PMG.UserView', {
17 extend: 'Ext.grid.GridPanel',
18 alias: 'widget.pmgUserView',
19
8f5de6bf
DM
20 store: {
21 autoLoad: true,
22 model: 'pmg-users',
23 sorters: [
24 {
25 property: 'realm',
c87d46fb 26 direction: 'ASC',
8f5de6bf
DM
27 },
28 {
29 property: 'userid',
c87d46fb
TL
30 direction: 'ASC',
31 },
32 ],
8f5de6bf
DM
33 },
34
4468e69c 35 controller: {
ec1dd829 36
4468e69c 37 xclass: 'Ext.app.ViewController',
ec1dd829 38
e93402ee
DM
39 init: function(view) {
40 Proxmox.Utils.monStoreErrors(view, view.store);
41 },
42
4468e69c 43 renderUsername: function(userid) {
fb511cb2 44 return Ext.htmlEncode(userid.match(/^(.+)(@[^@]+)$/)[1]);
4468e69c 45 },
ec1dd829 46
4468e69c
DM
47 renderFullName: function(firstname, metaData, record) {
48 var first = firstname || '';
49 var last = record.data.lastname || '';
fb511cb2 50 return Ext.htmlEncode(first + " " + last);
4468e69c 51 },
ec1dd829 52
4468e69c
DM
53 onAdd: function() {
54 var view = this.getView();
55
56 var win = Ext.create('PMG.UserEdit', {});
131ba4f6 57 win.on('destroy', function() { view.reload(); });
4468e69c
DM
58 win.show();
59 },
60
61 onEdit: function() {
62 var view = this.getView();
ec1dd829 63
4468e69c 64 var rec = view.selModel.getSelection()[0];
ec1dd829
DM
65
66 var win = Ext.create('PMG.UserEdit', {
c87d46fb 67 userid: rec.data.userid,
ec1dd829 68 });
131ba4f6 69 win.on('destroy', function() { view.reload(); });
ec1dd829 70 win.show();
4468e69c
DM
71 },
72
73 onPassword: function(btn, event, rec) {
74 var view = this.getView();
ec1dd829 75
c87d46fb
TL
76 var win = Ext.create('Proxmox.window.PasswordEdit', {
77 userid: rec.data.userid,
4468e69c 78 });
131ba4f6 79 win.on('destroy', function() { view.reload(); });
4468e69c
DM
80 win.show();
81 },
82
83 onAfterRemove: function(btn, res) {
84 var view = this.getView();
85 view.reload();
c87d46fb 86 },
1533ccff
WB
87
88 onUnlockTfa: function(btn, event, rec) {
89 let me = this;
90 let view = me.getView();
91 Ext.Msg.confirm(
92 Ext.String.format(gettext('Unlock TFA authentication for {0}'), rec.data.userid),
93 gettext("Locked 2nd factors can happen if the user's password was leaked. Are you sure you want to unlock the user?"),
94 function(btn_response) {
95 if (btn_response === 'yes') {
96 Proxmox.Utils.API2Request({
97 url: `/access/users/${rec.data.userid}/unlock-tfa`,
98 waitMsgTarget: view,
99 method: 'PUT',
100 failure: function(response, options) {
101 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
102 },
103 success: function(response, options) {
104 view.reload();
105 },
106 });
107 }
108 },
109 );
110 },
4468e69c
DM
111 },
112
113 listeners: {
114 scope: 'controller',
c87d46fb 115 itemdblclick: 'onEdit',
4468e69c
DM
116 },
117
118 tbar: [
119 {
120 text: gettext('Add'),
121 reference: 'addBtn',
c87d46fb 122 handler: 'onAdd',
4468e69c
DM
123 },
124 {
125 xtype: 'proxmoxButton',
ec1dd829
DM
126 text: gettext('Edit'),
127 disabled: true,
c87d46fb 128 handler: 'onEdit',
4468e69c
DM
129 },
130 {
131 xtype: 'proxmoxStdRemoveButton',
132 baseurl: '/access/users',
133 reference: 'removeBtn',
134 callback: 'onAfterRemove',
c87d46fb 135 waitMsgTarget: true,
4468e69c
DM
136 },
137 {
138 xtype: 'proxmoxButton',
ec1dd829
DM
139 text: gettext('Password'),
140 disabled: true,
c87d46fb
TL
141 handler: 'onPassword',
142 },
1533ccff
WB
143 '-',
144 {
145 xtype: 'proxmoxButton',
146 text: gettext('Unlock TFA'),
147 handler: 'onUnlockTfa',
ff37520d 148 disabled: true,
1533ccff
WB
149 enableFn: ({ data }) =>
150 data['totp-locked'] || (data['tfa-locked-until'] > (new Date().getTime() / 1000)),
151 },
4468e69c 152 ],
ec1dd829 153
4468e69c
DM
154 columns: [
155 {
156 header: gettext('User name'),
157 width: 200,
158 sortable: true,
159 renderer: 'renderUsername',
c87d46fb 160 dataIndex: 'userid',
4468e69c
DM
161 },
162 {
163 header: gettext('Realm'),
164 width: 100,
165 sortable: true,
c87d46fb 166 dataIndex: 'realm',
4468e69c 167 },
7818f0a3
DM
168 {
169 header: gettext('Role'),
170 width: 150,
171 sortable: true,
172 renderer: PMG.Utils.format_user_role,
c87d46fb 173 dataIndex: 'role',
7818f0a3 174 },
4468e69c
DM
175 {
176 header: gettext('Enabled'),
177 width: 80,
178 sortable: true,
179 renderer: Proxmox.Utils.format_boolean,
c87d46fb 180 dataIndex: 'enable',
4468e69c
DM
181 },
182 {
183 header: gettext('Expire'),
184 width: 80,
185 sortable: true,
186 renderer: Proxmox.Utils.format_expire,
c87d46fb 187 dataIndex: 'expire',
4468e69c
DM
188 },
189 {
190 header: gettext('Name'),
191 width: 150,
192 sortable: true,
193 renderer: 'renderFullName',
c87d46fb 194 dataIndex: 'firstname',
4468e69c 195 },
4195a809
WB
196 {
197 header: gettext('TFA Lock'),
198 width: 120,
199 sortable: true,
200 dataIndex: 'totp-locked',
201 renderer: function(v, metaData, record) {
202 let locked_until = record.data['tfa-locked-until'];
203 if (locked_until !== undefined) {
204 let now = new Date().getTime() / 1000;
205 if (locked_until > now) {
206 return gettext('Locked');
207 }
208 }
209
210 if (record.data['totp-locked']) {
211 return gettext('TOTP Locked');
212 }
213
214 return Proxmox.Utils.noText;
215 },
216 },
4468e69c
DM
217 {
218 header: gettext('Comment'),
219 sortable: false,
220 renderer: Ext.String.htmlEncode,
221 dataIndex: 'comment',
c87d46fb
TL
222 flex: 1,
223 },
4468e69c 224 ],
ec1dd829 225
4468e69c
DM
226 reload: function() {
227 var me = this;
ec1dd829 228
4468e69c 229 me.store.load();
c87d46fb 230 },
ec1dd829 231});