From 86e3ffe8d588a403f8ae2d41b89d4df31506a2d0 Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 27 Apr 2026 10:49:53 -0700 Subject: [PATCH] feat(daemon): AppState::get_pending_status returns wire-friendly bool+flag has_pending stays #[cfg(test)] because production GUI reads via the new get_pending_status (one round-trip carries both presence and flag); production PAM module reads the file directly. Method gated with #[allow(dead_code)] until Task 5 wires D-Bus. Co-Authored-By: Claude Opus 4.7 (1M context) --- daemon/src/state.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/daemon/src/state.rs b/daemon/src/state.rs index 8aeaa87..ca317a8 100644 --- a/daemon/src/state.rs +++ b/daemon/src/state.rs @@ -7,7 +7,9 @@ use crate::storage::policy::PolicyStore; use crate::storage::recovery::{RecoveryEntry, RecoveryStore, RecoveryStoreError}; use crate::storage::userdb::{UserDb, UserDbError}; use authforge_common::policy::{Policy, PolicyError}; -use authforge_common::types::{Credential, Method, PendingFlag, PolicyApplyResult, Transport}; +use authforge_common::types::{ + Credential, Method, PendingFlag, PendingStatus, PolicyApplyResult, Transport, +}; use std::collections::HashSet; use std::path::PathBuf; use std::sync::Arc; @@ -249,12 +251,24 @@ impl AppState { } /// Tests assert pending flag round-trips through SetPendingFlag / - /// ClearPendingFlag via this read accessor. Production readers (PAM - /// module, GUI status) read the on-disk file directly in later phases. + /// ClearPendingFlag via this read accessor. Production readers go + /// through `get_pending_status` (GUI) or read the on-disk file + /// directly (PAM module). #[cfg(test)] pub async fn has_pending(&self, user: &str) -> Result { Ok(self.pending.get(user)?.is_some()) } + + #[allow(dead_code)] // wired through D-Bus in Task 5. + pub async fn get_pending_status(&self, user: &str) -> Result { + match self.pending.get(user)? { + Some(flag) => Ok(PendingStatus { present: true, flag }), + None => Ok(PendingStatus { + present: false, + flag: PendingFlag::default(), + }), + } + } } #[cfg(test)]