From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id A0EC51FF13F for ; Thu, 26 Mar 2026 12:16:17 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E234CF201; Thu, 26 Mar 2026 12:16:38 +0100 (CET) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 26 Mar 2026 12:16:04 +0100 Message-Id: Subject: Re: [RFC PATCH datacenter-manager 2/3] ui: acl: list granular level permission paths for views To: "Shan Shaji" X-Mailer: aerc 0.20.0 References: <20260325153535.286380-1-s.shaji@proxmox.com> <20260325153535.286380-3-s.shaji@proxmox.com> In-Reply-To: <20260325153535.286380-3-s.shaji@proxmox.com> From: "Shannon Sterz" X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1774523716038 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.121 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: NMUPNC7XJHL6J6KFD47ZJH426J6YJUFE X-Message-ID-Hash: NMUPNC7XJHL6J6KFD47ZJH426J6YJUFE X-MailFrom: s.sterz@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: pdm-devel@lists.proxmox.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: some comments in-line. On Wed Mar 25, 2026 at 4:35 PM CET, Shan Shaji wrote: > Previously, users were unable to assign permissions to individual views. > Resolved this by loading the views list and extending permission paths > to include specific view routes. > > Signed-off-by: Shan Shaji > --- > .../configuration/permission_path_selector.rs | 80 +++++++++++++++---- > 1 file changed, 64 insertions(+), 16 deletions(-) > > diff --git a/ui/src/configuration/permission_path_selector.rs b/ui/src/co= nfiguration/permission_path_selector.rs > index 59bdabb..a0fec86 100644 > --- a/ui/src/configuration/permission_path_selector.rs > +++ b/ui/src/configuration/permission_path_selector.rs > @@ -1,12 +1,15 @@ > use std::rc::Rc; > > +use anyhow::Error; > use yew::html::IntoPropValue; > > -use pwt::prelude::*; > use pwt::widget::form::Combobox; > +use pwt::{prelude::*, AsyncPool}; > > use pwt_macros::{builder, widget}; > > +use crate::pdm_client; > + > static PREDEFINED_PATHS: &[&str] =3D &[ > "/", > "/access", > @@ -44,33 +47,78 @@ impl PermissionPathSelector { > } > } > > -enum Msg {} > +enum Msg { > + Prefetched(Vec), > + PrefetchFailed, > +} > > struct PdmPermissionPathSelector { > items: Rc>, > + async_pool: AsyncPool, > } > > -impl PdmPermissionPathSelector {} > +impl PdmPermissionPathSelector { > + async fn get_view_paths() -> Result, Error> { > + let views =3D pdm_client().list_views().await?; > + let paths: Vec =3D views > + .iter() > + .map(|cfg| format!("/view/{}", cfg.id)) > + .collect(); > + Ok(paths) > + } > + > + async fn get_paths() -> Result, Error> { > + let paths =3D Self::get_view_paths().await?; > + Ok(paths) > + } > +} > > impl Component for PdmPermissionPathSelector { > type Message =3D Msg; > type Properties =3D PermissionPathSelector; > > - fn create(_ctx: &Context) -> Self { > - // TODO: fetch resources & remotes from the backend to improve t= he pre-defined selection of > - // acl paths > - Self { > - items: Rc::new( > - PREDEFINED_PATHS > - .iter() > - .map(|i| AttrValue::from(*i)) > - .collect(), > - ), > - } > + fn create(ctx: &Context) -> Self { > + let base_items: Vec =3D PREDEFINED_PATHS > + .iter() > + .map(|i| AttrValue::from(*i)) > + .collect(); > + > + let this =3D Self { > + items: Rc::new(base_items), > + async_pool: AsyncPool::new(), > + }; > + > + let link =3D ctx.link().clone(); > + this.async_pool.spawn(async move { > + let paths =3D Self::get_paths().await; > + match paths { > + Ok(paths) =3D> { > + link.send_message(Msg::Prefetched(paths)); > + } > + Err(_) =3D> { > + link.send_message(Msg::PrefetchFailed); > + } this is minor, but at least for me cargo fmt will also accept the following formatting: match paths { Ok(paths) =3D> link.send_message(Msg::Prefetched(paths)), Err(_) =3D> link.send_message(Msg::PrefetchFailed), } imo that's a little neater. > + } > + }); im generally not too big of a fan of this "this" pattern in rust and here there is no need for it, you can simply do: let async_pool =3D AsyncPool::new(); async_pool.spawn(..); Self { items: Rc::new(..), async_pool, } you may need to change `async_pool` in the struct to `_async_pool` because then this member is never directly accessed. > + > + this > } > > - fn update(&mut self, _ctx: &Context, _msg: Self::Message) -> b= ool { > - false > + fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bo= ol { > + match msg { > + Msg::Prefetched(paths) =3D> { > + let mut items: Vec =3D Vec::with_capacity(self.i= tems.len() + paths.len()); > + > + items.extend(self.items.iter().map(|item| item.to_string= ())); > + items.extend(paths.into_iter()); > + items.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercas= e())); > + > + self.items =3D Rc::new(items.into_iter().map(AttrValue::= from).collect()); this could be expressed more neatly as: ``` Msg::Prefetched(paths) =3D> { let items =3D Rc::make_mut(&mut self.items); items.extend(paths.into_iter().map(AttrValue::from)); items.sort_by_key(|k| k.to_lowercase()); true } ``` this has a couple of advantages: * we don't move the original items from `AttrValue` to a `String` back to `AttrValue`, saving on allocations. * `Rc::make_mut()` will only clone if there are other pointers to the same allocation. since the is an `Rc::clone` in the view method below, this probably won't actually impact much here from what i can tell, but it still seems sensible to me to only force a new `Rc` if absolutely needed. * uses `sort_by_key` instead of `sort_by` is more concise and also recommended by clippy. > + > + true > + } > + Msg::PrefetchFailed =3D> false, > + } > } > > fn view(&self, ctx: &Context) -> Html {