all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Shannon Sterz <s.sterz@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH yew-comp 3/3] role_selector/acl_edit: make api endpoint and default role configurable
Date: Thu,  3 Apr 2025 16:18:04 +0200	[thread overview]
Message-ID: <20250403141806.402974-8-s.sterz@proxmox.com> (raw)
In-Reply-To: <20250403141806.402974-1-s.sterz@proxmox.com>

and expose it via the AclEdit component too so that users can more
easily adapt the components to their needs.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
 src/acl/acl_edit.rs  | 22 +++++++++++++++++++++-
 src/role_selector.rs | 20 ++++++++++++++++----
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/src/acl/acl_edit.rs b/src/acl/acl_edit.rs
index b8bbd89..03421b0 100644
--- a/src/acl/acl_edit.rs
+++ b/src/acl/acl_edit.rs
@@ -24,6 +24,16 @@ pub struct AclEdit {
     #[builder(IntoPropValue, into_prop_value)]
     acl_api_endpoint: String,
 
+    /// The endpoint which will be used to create new ACL entries via a PUT request.
+    #[prop_or_default]
+    #[builder(IntoPropValue, into_prop_value)]
+    role_api_endpoint: Option<String>,
+
+    /// The role that will be pre-selected in the role selector, `NoAccess` by default.
+    #[prop_or_default]
+    #[builder(IntoPropValue, into_prop_value)]
+    default_role: Option<AttrValue>,
+
     #[prop_or_default]
     input_panel: InputPanel,
 }
@@ -59,12 +69,22 @@ impl From<AclEdit> for EditWindow {
             )
         };
 
+        let mut role_selector = RoleSelector::new().name("role").required(true);
+
+        if let Some(role_api_endpoint) = value.role_api_endpoint {
+            role_selector.set_role_api_endpoint(role_api_endpoint);
+        }
+
+        if let Some(default_role) = value.default_role {
+            role_selector.set_default_role(default_role.clone());
+        }
+
         let input_panel = value
             .input_panel
             .clone()
             .padding(4)
             .with_field(authid_label, authid_field)
-            .with_field(tr!("Role"), RoleSelector::new().name("role").required(true))
+            .with_field(tr!("Role"), role_selector)
             .with_field(
                 tr!("Propagate"),
                 Checkbox::new().name("propagate").required(true),
diff --git a/src/role_selector.rs b/src/role_selector.rs
index 20a8483..429f58c 100644
--- a/src/role_selector.rs
+++ b/src/role_selector.rs
@@ -1,5 +1,6 @@
 use anyhow::format_err;
 use std::rc::Rc;
+use yew::html::IntoPropValue;
 
 use yew::virtual_dom::Key;
 
@@ -37,11 +38,22 @@ thread_local! {
 }
 
 use pwt::props::{FieldBuilder, WidgetBuilder};
-use pwt_macros::widget;
+use pwt_macros::{builder, widget};
 
 #[widget(comp=ProxmoxRoleSelector, @input)]
 #[derive(Clone, Properties, PartialEq)]
-pub struct RoleSelector {}
+#[builder]
+pub struct RoleSelector {
+    /// The default role.
+    #[builder(IntoPropValue, into_prop_value)]
+    #[prop_or(Some(AttrValue::from("NoAccess")))]
+    default_role: Option<AttrValue>,
+
+    /// The API endpoint from which to fetch the existing roles from.
+    #[builder(IntoPropValue, into_prop_value)]
+    #[prop_or(String::from("/access/roles"))]
+    role_api_endpoint: String,
+}
 
 impl Default for RoleSelector {
     fn default() -> Self {
@@ -104,8 +116,8 @@ impl Component for ProxmoxRoleSelector {
             .with_std_props(&props.std_props)
             .with_input_props(&props.input_props)
             .required(true)
-            .default("NoAccess")
-            .loader("/access/roles")
+            .default(ctx.props().default_role.clone())
+            .loader(ctx.props().role_api_endpoint.clone())
             .validate(self.validate.clone())
             .into()
     }
-- 
2.39.5



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


  parent reply	other threads:[~2025-04-03 14:18 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03 14:17 [pdm-devel] [PATCH datacenter-manager/proxmox/yew-comp 0/9] ACL edit api and ui components Shannon Sterz
2025-04-03 14:17 ` [pdm-devel] [PATCH proxmox 1/4] access-control: add more types to prepare for api feature Shannon Sterz
2025-04-03 14:17 ` [pdm-devel] [PATCH proxmox 2/4] access-control: add acl " Shannon Sterz
2025-04-09 11:01   ` Dietmar Maurer
2025-04-09 11:39     ` Dominik Csapak
2025-04-09 12:58       ` Shannon Sterz
2025-04-10  6:28         ` Dominik Csapak
2025-04-10  8:17           ` Shannon Sterz
2025-04-10 10:09             ` Dominik Csapak
2025-04-11 10:29         ` Shannon Sterz
2025-04-11 10:53           ` Dominik Csapak
2025-04-11 11:40             ` Shannon Sterz
2025-04-03 14:18 ` [pdm-devel] [PATCH proxmox 3/4] access-control: add comments to roles function of AccessControlConfig Shannon Sterz
2025-04-03 14:18 ` [pdm-devel] [PATCH proxmox 4/4] access-control: add generic roles endpoint to `api` feature Shannon Sterz
2025-04-03 14:18 ` [pdm-devel] [PATCH yew-comp 1/3] api-types/role_selector: depend on common `RoleInfo` type Shannon Sterz
2025-04-03 14:18 ` [pdm-devel] [PATCH yew-comp 2/3] acl: add a view and semi-generic `EditWindow` for acl entries Shannon Sterz
2025-04-03 14:18 ` Shannon Sterz [this message]
2025-04-03 14:18 ` [pdm-devel] [PATCH datacenter-manager 1/2] server: use proxmox-access-control api implementations Shannon Sterz
2025-04-03 14:18 ` [pdm-devel] [PATCH datacenter-manager 2/2] ui: configuration: add panel for viewing and editing acl entries Shannon Sterz
2025-04-11 13:45 ` [pdm-devel] [PATCH datacenter-manager/proxmox/yew-comp 0/9] ACL edit api and ui components Shannon Sterz

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=20250403141806.402974-8-s.sterz@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=pdm-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