[pve-devel] [PATCH manager 4/4] ui: api token: allow unprivileged users to modify their own api tokens
Daniel Kral
d.kral at proxmox.com
Thu Oct 31 14:46:29 CET 2024
Allows unprivileged users to edit and remove their own API tokens, as
this is already allowed by the respective PUT and DELETE methods on the
API endpoint `/access/users/{userid}/token/{tokenid}`.
Signed-off-by: Daniel Kral <d.kral at proxmox.com>
---
As this cannot be seen in the diff directly: The run_editor is also used
when double-clicking the record item (in addition when clicking the Edit
button while the record item is selected).
This has not been requested in the BugZilla #5722, but has similar
intentions and made sense to include into this patch series as well.
www/manager6/dc/TokenView.js | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/www/manager6/dc/TokenView.js b/www/manager6/dc/TokenView.js
index d275a1c5..f71ab905 100644
--- a/www/manager6/dc/TokenView.js
+++ b/www/manager6/dc/TokenView.js
@@ -57,8 +57,12 @@ Ext.define('PVE.dc.TokenView', {
return `/access/users/${uid}/token/${tid}`;
};
+ let hasTokenCRUDPermissions = function(userid) {
+ return userid === Proxmox.UserName || !!caps.access['User.Modify'];
+ };
+
let run_editor = function(rec) {
- if (!caps.access['User.Modify']) {
+ if (!hasTokenCRUDPermissions(rec.data.userid)) {
return;
}
@@ -88,14 +92,14 @@ Ext.define('PVE.dc.TokenView', {
xtype: 'proxmoxButton',
text: gettext('Edit'),
disabled: true,
- enableFn: (rec) => !!caps.access['User.Modify'],
+ enableFn: (rec) => hasTokenCRUDPermissions(rec.data.userid),
selModel: sm,
handler: (btn, e, rec) => run_editor(rec),
},
{
xtype: 'proxmoxStdRemoveButton',
selModel: sm,
- enableFn: (rec) => !!caps.access['User.Modify'],
+ enableFn: (rec) => hasTokenCRUDPermissions(rec.data.userid),
callback: reload,
getUrl: urlFromRecord,
},
--
2.39.5
More information about the pve-devel
mailing list