all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Nicolas Frey <n.frey@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-access-control 1/2] api: token: fix #6890: add ability to remove comment with empty string
Date: Wed,  8 Oct 2025 13:19:19 +0200	[thread overview]
Message-ID: <20251008111930.55867-2-n.frey@proxmox.com> (raw)
In-Reply-To: <20251008111930.55867-1-n.frey@proxmox.com>

Beforehand, if the comment was an empty string, it would not update
the token to have it's comment deleted. Adds missing defined check
instead of checking truthy value (i.e. an empty string being falsy).
The comment is also explicitly deleted, because the response would
otherwise return the comment as empty, not deleted:

┌─────────┬───────┐
│ key     │ value │
╞═════════╪═══════╡
│ comment │       │
├─────────┼───────┤
│ expire  │ 0     │
├─────────┼───────┤
│ privsep │ 1     │
└─────────┴───────┘

instead of:

┌─────────┬───────┐
│ key     │ value │
╞═════════╪═══════╡
│ expire  │ 0     │
├─────────┼───────┤
│ privsep │ 1     │
└─────────┴───────┘

Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=6890
Signed-off-by: Nicolas Frey <n.frey@proxmox.com>
---
 src/PVE/API2/User.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/PVE/API2/User.pm b/src/PVE/API2/User.pm
index 5041fbe..e7c895e 100644
--- a/src/PVE/API2/User.pm
+++ b/src/PVE/API2/User.pm
@@ -870,7 +870,8 @@ __PACKAGE__->register_method({
 
                 $token->{privsep} = $param->{privsep} if defined($param->{privsep});
                 $token->{expire} = $param->{expire} if defined($param->{expire});
-                $token->{comment} = $param->{comment} if $param->{comment};
+                $token->{comment} = $param->{comment} if defined($param->{comment});
+                delete $token->{comment} if (!length $token->{comment});
 
                 $usercfg->{users}->{$userid}->{tokens}->{$tokenid} = $token;
                 cfs_write_file("user.cfg", $usercfg);
-- 
2.47.3


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

  reply	other threads:[~2025-10-08 11:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-08 11:19 [pve-devel] [PATCH pve-access-control 0/2] api: token: fix #6890: allow comment removal via delete parameter or " Nicolas Frey
2025-10-08 11:19 ` Nicolas Frey [this message]
2025-10-08 11:19 ` [pve-devel] [PATCH pve-access-control 2/2] api: token: add delete parameter for comment Nicolas Frey

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=20251008111930.55867-2-n.frey@proxmox.com \
    --to=n.frey@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal