From 8200487787ba272bca84e6c0f674ad4bb06d1143 Mon Sep 17 00:00:00 2001 From: Clubs Date: Mon, 28 Sep 2026 03:03:31 -0500 Subject: [PATCH] feat: add optional flags for filtering !admin user list, hide deactivated users by default --- src/admin/user/commands.rs | 38 ++++++++++++++++++++++++++++++-------- src/admin/user/mod.rs | 12 +++++++++++- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index cda825563..fbde37570 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -31,14 +31,36 @@ const AUTO_GEN_PASSWORD_LENGTH: usize = 25; const BULK_JOIN_REASON: &str = "Bulk force joining this room as initiated by the server admin."; impl crate::Context<'_> { - pub(super) async fn list_users(&self) -> Result { - let users: Vec<_> = self - .services - .users - .stream_local_users() - .map(|id| id.as_str().to_owned()) - .collect() - .await; + pub(super) async fn list_users( + &self, + show_deactivated: bool, + hide_suspended: bool, + hide_locked: bool, + ) -> Result { + let mut users: Vec = Vec::new(); + let mut user_stream = self.services.users.stream_local_users(); + while let Some(id) = user_stream.next().await { + if !show_deactivated { + if matches!(self.services.users.status(&id).await, AccountStatus::Deactivated) { + continue; + } + } + let suspended = match self.services.users.is_suspended(&id).await { + | Err(_) => continue, + | Ok(suspended) => suspended, + }; + if hide_suspended && suspended { + continue; + } + let locked = match self.services.users.is_locked(&id).await { + | Err(_) => continue, + | Ok(locked) => locked, + }; + if hide_locked && locked { + continue; + } + users.push(id.as_str().to_owned()); + } let mut plain_msg = format!("Found {} local user account(s):\n```\n", users.len()); plain_msg += users.join("\n").as_str(); diff --git a/src/admin/user/mod.rs b/src/admin/user/mod.rs index 3b2e2fb09..3d431b33e 100644 --- a/src/admin/user/mod.rs +++ b/src/admin/user/mod.rs @@ -164,7 +164,17 @@ pub enum UserCommand { /// List local users in the database #[command(name = "list", alias = "list-users")] - ListUsers, + ListUsers { + // Include deactivated users in the user list + #[arg(long)] + show_deactivated: bool, + // Hide suspended accounts from the user list + #[arg(long)] + hide_suspended: bool, + // Hide locked accounts from the user list + #[arg(long)] + hide_locked: bool, + }, /// Lists all the rooms (local and remote) that the specified user is /// invited to