From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 42C151FF17A for ; Tue, 28 Oct 2025 14:33:14 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B49DE1B911; Tue, 28 Oct 2025 14:33:46 +0100 (CET) From: Shan Shaji To: yew-devel@lists.proxmox.com Date: Tue, 28 Oct 2025 14:33:26 +0100 Message-ID: <20251028133326.342164-1-s.shaji@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1761658409305 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.109 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: [yew-devel] [PATCH proxmox-yew-comp v2] fix #6787: ui: allow creating PAM users from dashboard X-BeenThere: yew-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Yew framework devel list at Proxmox List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Yew framework devel list at Proxmox Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: yew-devel-bounces@lists.proxmox.com Sender: "yew-devel" When tried to create a user in the PAM realm an error occurs if the user doesn't exist on the host. To fix the issue hid the password and confirm password fields. Now the user will only be added to the `.cfg` file and won't be trying to update the password. The error was originating from the invocation of `pam_chauthtok`. Since the user is not created on the system, if tried to change the password the same error will be shown again. Inorder to avoid that the "change password" button will only be enabled if the user is not a "pam" user. Signed-off-by: Shan Shaji --- changes since v1: Thanks @Shannon - Use `and_then` combinator instead of chaining `map` and `flatten` functions. src/user_panel.rs | 62 ++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/src/user_panel.rs b/src/user_panel.rs index d983928..1488a66 100644 --- a/src/user_panel.rs +++ b/src/user_panel.rs @@ -165,8 +165,12 @@ impl LoadableComponent for ProxmoxUserPanel { fn toolbar(&self, ctx: &LoadableComponentContext) -> Option { let link = ctx.link(); - let disabled = self.selection.is_empty(); + let mut disable_change_password = disabled; + + if let Some(user) = self.get_selected_user() { + disable_change_password = user.user.userid.realm().as_str() == "pam"; + } let toolbar = Toolbar::new() .class("pwt-w-100") @@ -190,7 +194,7 @@ impl LoadableComponent for ProxmoxUserPanel { .with_spacer() .with_child( Button::new(tr!("Change Password")) - .disabled(disabled) + .disabled(disable_change_password) .onclick(link.change_view_callback(|_| Some(ViewState::ChangePassword))), ) .with_child( @@ -257,6 +261,12 @@ fn check_confirm_password(form_ctx: FormContext) { } impl ProxmoxUserPanel { + fn get_selected_user(&self) -> Option { + self.selection + .selected_key() + .and_then(|key| self.store.read().lookup_record(&key).cloned()) + } + fn create_add_dialog(&self, ctx: &LoadableComponentContext) -> Html { EditWindow::new(tr!("Add") + ": " + &tr!("User")) .renderer(add_user_input_panel) @@ -463,8 +473,10 @@ fn password_change_input_panel(_form_ctx: &FormContext) -> Html { .into() } -fn add_user_input_panel(_form_ctx: &FormContext) -> Html { - InputPanel::new() +fn add_user_input_panel(form_ctx: &FormContext) -> Html { + let is_pam = form_ctx.read().get_field_text("realm") == "pam"; + + let mut panel = InputPanel::new() .padding(4) .with_field( tr!("User name"), @@ -481,24 +493,30 @@ fn add_user_input_panel(_form_ctx: &FormContext) -> Html { .name("realm") .required(true) .submit(false), - ) - .with_field( - tr!("Password"), - Field::new() - .name("password") - .required(true) - .schema(&PASSWORD_SCHEMA) - .input_type(InputType::Password), - ) - // fixme: validate confirmation - .with_field( - tr!("Confirm password"), - Field::new() - .name("confirm_password") - .required(true) - .submit(false) - .input_type(InputType::Password), - ) + ); + + if !is_pam { + panel = panel + .with_field( + tr!("Password"), + Field::new() + .name("password") + .required(true) + .schema(&PASSWORD_SCHEMA) + .input_type(InputType::Password), + ) + // fixme: validate confirmation + .with_field( + tr!("Confirm password"), + Field::new() + .name("confirm_password") + .required(true) + .submit(false) + .input_type(InputType::Password), + ); + } + + panel .with_field( tr!("Expire"), Field::new() -- 2.47.3 _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel