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 A21441FF183 for ; Wed, 22 Oct 2025 15:11:08 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 878DC18925; Wed, 22 Oct 2025 15:11:34 +0200 (CEST) From: Shannon Sterz To: pdm-devel@lists.proxmox.com Date: Wed, 22 Oct 2025 15:11:26 +0200 Message-ID: <20251022131126.358790-11-s.sterz@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251022131126.358790-1-s.sterz@proxmox.com> References: <20251022131126.358790-1-s.sterz@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1761138682333 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.056 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH datacenter-manager v2 1/1] ui: main menu: use the AclContext to hide the Notes if appropriate X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" a user that does not have `PRIV_SYS_AUDIT` on `/system` is not allowed to view the notes and one that lacks `PRIV_SYS_MODIFY` on `/system/notes` is not allowed to edit them. so hide the respective ui elements when a user does not have the necessary permissions. Signed-off-by: Shannon Sterz --- ui/src/main_menu.rs | 66 +++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/ui/src/main_menu.rs b/ui/src/main_menu.rs index 7650b63..c411367 100644 --- a/ui/src/main_menu.rs +++ b/ui/src/main_menu.rs @@ -9,9 +9,10 @@ use pwt::state::Selection; use pwt::widget::nav::{Menu, MenuItem, NavigationDrawer}; use pwt::widget::{Container, Row, SelectionView, SelectionViewRenderInfo}; -use proxmox_yew_comp::{NotesView, XTermJs}; +use proxmox_yew_comp::{AclContext, NotesView, XTermJs}; use pdm_api_types::remotes::RemoteType; +use pdm_api_types::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY}; use crate::remotes::RemotesPanel; use crate::sdn::evpn::EvpnPanel; @@ -62,11 +63,14 @@ impl MainMenu { pub enum Msg { Select(Key), + UpdateAcl(AclContext), } pub struct PdmMainMenu { active: Key, menu_selection: Selection, + acl_context: AclContext, + _acl_context_listener: ContextHandle, } fn register_view( @@ -109,10 +113,17 @@ impl Component for PdmMainMenu { type Message = Msg; type Properties = MainMenu; - fn create(_ctx: &Context) -> Self { + fn create(ctx: &Context) -> Self { + let (acl_context, acl_context_listener) = ctx + .link() + .context(ctx.link().callback(Msg::UpdateAcl)) + .expect("acl context not present"); + Self { active: Key::from("dashboard"), menu_selection: Selection::new(), + acl_context, + _acl_context_listener: acl_context_listener, } } @@ -122,6 +133,10 @@ impl Component for PdmMainMenu { self.active = key; true } + Msg::UpdateAcl(acl_context) => { + self.acl_context = acl_context; + true + } } } @@ -144,25 +159,36 @@ impl Component for PdmMainMenu { move |_| Dashboard::new().into(), ); - register_view( - &mut menu, - &mut content, - tr!("Notes"), - "notes", - Some("fa fa-sticky-note-o"), - move |_| { - let notes = NotesView::new("/config/notes").on_submit(|notes| async move { - proxmox_yew_comp::http_put("/config/notes", Some(serde_json::to_value(¬es)?)) - .await - }); + if self.acl_context.check_privs(&["system"], PRIV_SYS_AUDIT) { + let allow_editing = self + .acl_context + .check_privs(&["system", "notes"], PRIV_SYS_MODIFY); - Container::new() - .class("pwt-content-spacer") - .class(pwt::css::FlexFit) - .with_child(notes) - .into() - }, - ); + register_view( + &mut menu, + &mut content, + tr!("Notes"), + "notes", + Some("fa fa-sticky-note-o"), + move |_| { + let notes = NotesView::new("/config/notes") + .on_submit(|notes| async move { + proxmox_yew_comp::http_put( + "/config/notes", + Some(serde_json::to_value(¬es)?), + ) + .await + }) + .allow_editing(allow_editing); + + Container::new() + .class("pwt-content-spacer") + .class(pwt::css::FlexFit) + .with_child(notes) + .into() + }, + ) + } let mut config_submenu = Menu::new(); -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel