public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-manager] ui: custom cpu models view: disable edits if missing permissions
Date: Wed, 20 May 2026 07:25:52 +0200	[thread overview]
Message-ID: <20260520052552.72701-1-a.bied-charreton@proxmox.com> (raw)

Until now, the custom CPU models view would let a user lacking
Mapping.Modify permissions go through the whole custom model
creation/edit flow and only fail on submit.

Disable the buttons if the user lacks the required permissions.

Reported-by: Michael Köppl <m.koeppl@proxmox.com>
Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
 www/manager6/dc/CPUTypeView.js | 62 ++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/www/manager6/dc/CPUTypeView.js b/www/manager6/dc/CPUTypeView.js
index d60c1330..11882b3c 100644
--- a/www/manager6/dc/CPUTypeView.js
+++ b/www/manager6/dc/CPUTypeView.js
@@ -103,36 +103,6 @@ Ext.define('PVE.dc.CPUTypeView', {
         },
     ],
 
-    tbar: [
-        {
-            text: gettext('Add'),
-            handler: 'onAdd',
-        },
-        '-',
-        {
-            xtype: 'proxmoxStdRemoveButton',
-            baseurl: '/api2/extjs/cluster/qemu/custom-cpu-models/',
-            getRecordName: (rec) => rec.data.cputype,
-            getUrl: function (rec) {
-                let me = this;
-                return me.baseurl + rec.data.cputype;
-            },
-            confirmMsg: function (rec) {
-                return Ext.String.format(
-                    gettext("Are you sure you want to remove the custom CPU model '{0}'?"),
-                    rec.data.cputype.replace(/^custom-/, ''),
-                );
-            },
-            callback: 'reload',
-        },
-        {
-            xtype: 'proxmoxButton',
-            text: gettext('Edit'),
-            disabled: true,
-            handler: 'onEdit',
-        },
-    ],
-
     selModel: {
         xtype: 'rowmodel',
     },
@@ -146,6 +116,38 @@ Ext.define('PVE.dc.CPUTypeView', {
 
     initComponent: function () {
         let me = this;
+        let caps = Ext.state.Manager.get('GuiCap');
+        let canEdit = !!caps.mapping['Mapping.Modify'];
+
+        me.tbar = [
+            { text: gettext('Add'), handler: 'onAdd', disabled: !canEdit },
+            '-',
+            {
+                xtype: 'proxmoxStdRemoveButton',
+                baseurl: '/api2/extjs/cluster/qemu/custom-cpu-models/',
+                enableFn: (rec) => canEdit,
+                getRecordName: (rec) => rec.data.cputype,
+                getUrl: function (rec) {
+                    let me = this;
+                    return me.baseurl + rec.data.cputype;
+                },
+                confirmMsg: function (rec) {
+                    return Ext.String.format(
+                        gettext("Are you sure you want to remove the custom CPU model '{0}'?"),
+                        rec.data.cputype.replace(/^custom-/, ''),
+                    );
+                },
+                callback: 'reload',
+            },
+            {
+                xtype: 'proxmoxButton',
+                text: gettext('Edit'),
+                disabled: true,
+                enableFn: (_) => canEdit,
+                handler: 'onEdit',
+            },
+        ];
+
         me.callParent();
         Proxmox.Utils.monStoreErrors(me, me.store);
     },
-- 
2.47.3




                 reply	other threads:[~2026-05-20  5:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260520052552.72701-1-a.bied-charreton@proxmox.com \
    --to=a.bied-charreton@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal