Skip to main content

systemprompt_cli/commands/admin/users/
mod.rs

1mod ban;
2mod bulk;
3mod count;
4mod create;
5mod delete;
6mod export;
7mod list;
8mod merge;
9mod role;
10mod search;
11mod session;
12mod show;
13mod stats;
14mod types;
15mod update;
16mod webauthn;
17
18use crate::cli_settings::CliConfig;
19use anyhow::{bail, Result};
20use clap::Subcommand;
21use systemprompt_runtime::DatabaseContext;
22
23pub use types::*;
24
25#[derive(Debug, Subcommand)]
26pub enum UsersCommands {
27    #[command(about = "List users with pagination and filtering")]
28    List(list::ListArgs),
29
30    #[command(about = "Show detailed user information")]
31    Show(show::ShowArgs),
32
33    #[command(about = "Search users by name, email, or full name")]
34    Search(search::SearchArgs),
35
36    #[command(about = "Create a new user")]
37    Create(create::CreateArgs),
38
39    #[command(about = "Update user fields")]
40    Update(update::UpdateArgs),
41
42    #[command(about = "Delete a user")]
43    Delete(delete::DeleteArgs),
44
45    #[command(about = "Get total user count")]
46    Count(count::CountArgs),
47
48    #[command(about = "Export users to JSON")]
49    Export(export::ExportArgs),
50
51    #[command(about = "Show user statistics dashboard")]
52    Stats,
53
54    #[command(about = "Merge source user into target user")]
55    Merge(merge::MergeArgs),
56
57    #[command(subcommand, about = "Bulk operations on users")]
58    Bulk(bulk::BulkCommands),
59
60    #[command(subcommand, about = "Role management commands")]
61    Role(role::RoleCommands),
62
63    #[command(subcommand, about = "Session management commands")]
64    Session(session::SessionCommands),
65
66    #[command(subcommand, about = "IP ban management commands")]
67    Ban(ban::BanCommands),
68
69    #[command(subcommand, about = "WebAuthn credential management commands")]
70    Webauthn(webauthn::WebauthnCommands),
71}
72
73pub async fn execute(cmd: UsersCommands, config: &CliConfig) -> Result<()> {
74    match cmd {
75        UsersCommands::List(args) => list::execute(args, config).await,
76        UsersCommands::Show(args) => show::execute(args, config).await,
77        UsersCommands::Search(args) => search::execute(args, config).await,
78        UsersCommands::Create(args) => create::execute(args, config).await,
79        UsersCommands::Update(args) => update::execute(args, config).await,
80        UsersCommands::Delete(args) => delete::execute(args, config).await,
81        UsersCommands::Count(args) => count::execute(args, config).await,
82        UsersCommands::Export(args) => export::execute(args, config).await,
83        UsersCommands::Stats => stats::execute(config).await,
84        UsersCommands::Merge(args) => merge::execute(args, config).await,
85        UsersCommands::Bulk(cmd) => bulk::execute(cmd, config).await,
86        UsersCommands::Role(cmd) => role::execute(cmd, config).await,
87        UsersCommands::Session(cmd) => session::execute(cmd, config).await,
88        UsersCommands::Ban(cmd) => ban::execute(cmd, config).await,
89        UsersCommands::Webauthn(cmd) => webauthn::execute(cmd, config).await,
90    }
91}
92
93pub async fn execute_with_db(
94    cmd: UsersCommands,
95    db_ctx: &DatabaseContext,
96    config: &CliConfig,
97) -> Result<()> {
98    match cmd {
99        UsersCommands::List(args) => list::execute_with_pool(args, db_ctx.db_pool(), config).await,
100        UsersCommands::Show(args) => show::execute_with_pool(args, db_ctx.db_pool(), config).await,
101        UsersCommands::Search(args) => {
102            search::execute_with_pool(args, db_ctx.db_pool(), config).await
103        },
104        UsersCommands::Count(args) => {
105            count::execute_with_pool(args, db_ctx.db_pool(), config).await
106        },
107        UsersCommands::Export(args) => {
108            export::execute_with_pool(args, db_ctx.db_pool(), config).await
109        },
110        UsersCommands::Stats => stats::execute_with_pool(db_ctx.db_pool(), config).await,
111        UsersCommands::Session(cmd) => {
112            session::execute_with_pool(cmd, db_ctx.db_pool(), config).await
113        },
114        UsersCommands::Ban(cmd) => ban::execute_with_pool(cmd, db_ctx.db_pool(), config).await,
115        UsersCommands::Role(cmd) => role::execute_with_pool(cmd, db_ctx.db_pool(), config),
116        UsersCommands::Create(_)
117        | UsersCommands::Update(_)
118        | UsersCommands::Delete(_)
119        | UsersCommands::Merge(_)
120        | UsersCommands::Bulk(_)
121        | UsersCommands::Webauthn(_) => {
122            bail!("Write operations require full profile context")
123        },
124    }
125}