Skip to main content

oauth_db_cli/commands/
admin.rs

1use crate::auth::require_admin;
2use crate::cli::{AdminCommands, AdminUsersCommands, Cli};
3use crate::error::{CliError, Result};
4use crate::output::print_error;
5
6pub async fn execute(cmd: &AdminCommands, _cli: &Cli) -> Result<()> {
7    match cmd {
8        AdminCommands::Users { command } => execute_users_command(command).await,
9        AdminCommands::Stats => execute_stats_command().await,
10    }
11}
12
13async fn execute_users_command(cmd: &AdminUsersCommands) -> Result<()> {
14    match cmd {
15        AdminUsersCommands::List { .. } => {
16            require_admin("list all platform users").await?;
17            print_error("Admin users list not yet implemented (Phase 5)");
18            Err(CliError::ApiError(
19                "Admin functionality will be implemented in Phase 5".to_string(),
20            ))
21        }
22        AdminUsersCommands::Show { user_id } => {
23            require_admin(&format!("view platform user '{}'", user_id)).await?;
24            print_error("Admin user show not yet implemented (Phase 5)");
25            Err(CliError::ApiError(
26                "Admin functionality will be implemented in Phase 5".to_string(),
27            ))
28        }
29        AdminUsersCommands::Create { username, .. } => {
30            require_admin(&format!("create platform user '{}'", username)).await?;
31            print_error("Admin user create not yet implemented (Phase 5)");
32            Err(CliError::ApiError(
33                "Admin functionality will be implemented in Phase 5".to_string(),
34            ))
35        }
36        AdminUsersCommands::Enable { user_id } => {
37            require_admin(&format!("enable platform user '{}'", user_id)).await?;
38            print_error("Admin user enable not yet implemented (Phase 5)");
39            Err(CliError::ApiError(
40                "Admin functionality will be implemented in Phase 5".to_string(),
41            ))
42        }
43        AdminUsersCommands::Disable { user_id } => {
44            require_admin(&format!("disable platform user '{}'", user_id)).await?;
45            print_error("Admin user disable not yet implemented (Phase 5)");
46            Err(CliError::ApiError(
47                "Admin functionality will be implemented in Phase 5".to_string(),
48            ))
49        }
50        AdminUsersCommands::SetRole { user_id, role } => {
51            require_admin(&format!("set role '{}' for platform user '{}'", role, user_id))
52                .await?;
53            print_error("Admin user set-role not yet implemented (Phase 5)");
54            Err(CliError::ApiError(
55                "Admin functionality will be implemented in Phase 5".to_string(),
56            ))
57        }
58    }
59}
60
61async fn execute_stats_command() -> Result<()> {
62    require_admin("view system statistics").await?;
63    print_error("Admin stats not yet implemented (Phase 5)");
64    Err(CliError::ApiError(
65        "Admin functionality will be implemented in Phase 5".to_string(),
66    ))
67}