diff --git a/apps/auth-service/src/cli/admin.rs b/apps/auth-service/src/cli/admin.rs index 2e2c16362..3c8c4360c 100644 --- a/apps/auth-service/src/cli/admin.rs +++ b/apps/auth-service/src/cli/admin.rs @@ -1,10 +1,10 @@ //! Granting, revoking and listing administrators. use super::{ - CliError, Confirm, Console, + CliError, Confirm, Console, WhyOwnerSees, output::{Cell, report}, }; -use crate::{Reason, UserRef}; +use crate::UserRef; use clap::Subcommand; use sourceorigin_common::admin::Administrator; @@ -20,20 +20,18 @@ pub(super) enum AdminCommand { Grant { /// The account: its handle, ID or verified email. user: UserRef, - /// Why, recorded with the change and shown to the owner in their history: - /// 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: WhyOwnerSees, }, /// Remove an account's administrator rights. The last active administrator /// keeps theirs. Revoke { /// The account: its handle, ID or verified email. user: UserRef, - /// Why, recorded with the change and shown to the owner in their history: - /// 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: WhyOwnerSees, /// Confirmation. #[command(flatten)] confirm: Confirm, @@ -52,22 +50,22 @@ impl AdminCommand { .. } = console; match self { - Self::Grant { user, reason } => { + Self::Grant { user, why } => { let id = console.user(&user).await?; - service.grant_administrator(operator, id, reason).await?; + service + .grant_administrator(operator, id, why.reason) + .await?; out.info(format_args!("Made {user} an administrator."))?; } - Self::Revoke { - user, - reason, - confirm, - } => { + Self::Revoke { user, why, confirm } => { let id = console.user(&user).await?; confirm.ask( out, &format!("Remove the administrator rights of {user} ({id})"), )?; - service.revoke_administrator(operator, id, reason).await?; + service + .revoke_administrator(operator, id, why.reason) + .await?; out.info(format_args!("Removed the administrator rights of {user}."))?; } Self::List => out.emit(&service.list_administrators(operator).await?[..])?, diff --git a/apps/auth-service/src/cli/audit.rs b/apps/auth-service/src/cli/audit.rs index 0ea57889c..add66d57d 100644 --- a/apps/auth-service/src/cli/audit.rs +++ b/apps/auth-service/src/cli/audit.rs @@ -2,11 +2,11 @@ //! over them (see `docs/dev/security/audit-history.md`). use super::{ - CliError, Confirm, Console, + CliError, Confirm, Console, Why, output::{Cell, Style, report}, }; use crate::{ - AuditError, AuditKeys, PUBLIC_BASE_URL, Reason, UserRef, + AuditError, AuditKeys, PUBLIC_BASE_URL, UserRef, audit::{AuditVerification, ChainPoint}, }; use clap::{Args, Subcommand}; @@ -40,9 +40,9 @@ pub(super) enum AuditCommand { /// The keys to check checkpoints against. #[command(flatten)] keys: AuditKeyArgs, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, /// Confirmation. #[command(flatten)] confirm: Confirm, @@ -93,7 +93,7 @@ impl AuditCommand { Self::Prune { through, keys, - reason, + why, confirm, } => { confirm.ask( @@ -101,7 +101,7 @@ impl AuditCommand { &format!("This deletes every audit event through position {through}"), )?; let deleted = service - .prune_audit_chain(operator, &keys.keys()?, through, reason) + .prune_audit_chain(operator, &keys.keys()?, through, why.reason) .await?; out.info(format_args!( "Pruned {deleted} events through position {through}." diff --git a/apps/auth-service/src/cli/client.rs b/apps/auth-service/src/cli/client.rs index 733ddb233..f4c4f06ad 100644 --- a/apps/auth-service/src/cli/client.rs +++ b/apps/auth-service/src/cli/client.rs @@ -1,7 +1,7 @@ //! Registering, inspecting and changing OIDC clients. use super::{ - CliError, Confirm, Console, + CliError, Confirm, Console, Why, output::{Cell, Joined, Single, Style, report}, }; use crate::{Applied, ClientDetails, GracePeriod, PUBLIC_BASE_URL, Reason}; @@ -40,9 +40,9 @@ pub(super) enum ClientCommand { Disable { /// The client's ID. id: ClientId, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, /// Confirmation. #[command(flatten)] confirm: Confirm, @@ -52,9 +52,9 @@ pub(super) enum ClientCommand { Delete { /// The client's ID. id: ClientId, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, /// Confirmation. #[command(flatten)] confirm: Confirm, @@ -63,18 +63,18 @@ pub(super) enum ClientCommand { Enable { /// The client's ID. id: ClientId, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, }, /// Block a client: it is disabled, and its owner cannot enable it again /// until `unsuspend`. Suspend { /// The client's ID. id: ClientId, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, /// Confirmation. #[command(flatten)] confirm: Confirm, @@ -83,9 +83,9 @@ pub(super) enum ClientCommand { Unsuspend { /// The client's ID. id: ClientId, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, }, /// Print a new secret for a confidential client. Earlier secrets keep working /// during the grace period, while the client switches to the new one. @@ -96,9 +96,9 @@ pub(super) enum ClientCommand { /// now, which asks first. #[arg(long, default_value = "24h")] grace: GracePeriod, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, /// Confirmation, which `--grace 0` needs. #[command(flatten)] confirm: Confirm, @@ -120,9 +120,9 @@ pub(super) enum OriginCommand { id: ClientId, /// The origin, as browsers send it, e.g. `https://notes.example`. origin: RelatedOrigin, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, }, /// Remove an origin: its pages stop signing users in. Remove { @@ -130,9 +130,9 @@ pub(super) enum OriginCommand { id: ClientId, /// The origin, as approved. origin: RelatedOrigin, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, }, /// List every approved origin. List, @@ -148,18 +148,18 @@ impl OriginCommand { .. } = console; match self { - Self::Add { id, origin, reason } => { + Self::Add { id, origin, why } => { // Tells hosts within auth's own domain, which browsers accept without the // list, from public suffixes. let auth: Origin = PUBLIC_BASE_URL.parse()?; service - .approve_related_origin(operator, &id, &origin, auth.host(), reason) + .approve_related_origin(operator, &id, &origin, auth.host(), why.reason) .await?; out.info(format_args!("Approved {origin} for client {id}.")) } - Self::Remove { id, origin, reason } => { + Self::Remove { id, origin, why } => { service - .remove_related_origin(operator, &id, &origin, reason) + .remove_related_origin(operator, &id, &origin, why.reason) .await?; out.info(format_args!("Removed {origin} from client {id}.")) } @@ -181,7 +181,7 @@ impl ClientCommand { } = console; match self { Self::Create(create) => { - let (id, reason) = (create.id.clone(), create.reason.clone()); + let (id, reason) = (create.id.clone(), create.why.reason.clone()); let secret = service .create_client(operator, &create.registration()?, reason) .await?; @@ -194,37 +194,29 @@ impl ClientCommand { Self::List => out.emit(&service.list_clients(operator).await?[..]), Self::Show { id } => out.emit(&service.client_details(operator, &id).await?), Self::Update(update) => { - let (id, reason) = (update.id.clone(), update.reason.clone()); + let (id, reason) = (update.id.clone(), update.why.reason.clone()); service .update_client(operator, &id, reason, |client| update.apply(client)) .await?; out.info(format_args!("Updated client {id}.")) } - Self::Disable { - id, - reason, - confirm, - } => { + Self::Disable { id, why, confirm } => { confirm.ask( out, &format!("Disable client {id}: it stops working at once"), )?; service - .set_client_enabled(operator, &id, false, reason) + .set_client_enabled(operator, &id, false, why.reason) .await?; out.info(format_args!("Disabled client {id}.")) } - Self::Enable { id, reason } => { + Self::Enable { id, why } => { service - .set_client_enabled(operator, &id, true, reason) + .set_client_enabled(operator, &id, true, why.reason) .await?; out.info(format_args!("Enabled client {id}.")) } - Self::Suspend { - id, - reason, - confirm, - } => { + Self::Suspend { id, why, confirm } => { confirm.ask( out, &format!( @@ -232,38 +224,34 @@ impl ClientCommand { ), )?; service - .set_client_suspended(operator, &id, true, reason) + .set_client_suspended(operator, &id, true, why.reason) .await?; out.info(format_args!("Suspended client {id}.")) } - Self::Unsuspend { id, reason } => { + Self::Unsuspend { id, why } => { service - .set_client_suspended(operator, &id, false, reason) + .set_client_suspended(operator, &id, false, why.reason) .await?; out.info(format_args!( "Lifted the suspension of client {id}: it stays disabled until enabled." )) } - Self::Delete { - id, - reason, - confirm, - } => { + Self::Delete { id, why, confirm } => { confirm.ask( out, &format!( "Delete client {id}: it stops working at once, and its ID can never be reused" ), )?; - service.delete_client(operator, &id, reason).await?; + service.delete_client(operator, &id, why.reason).await?; out.info(format_args!("Deleted client {id}.")) } Self::RotateSecret { id, grace, - reason, + why, confirm, - } => Self::rotate_secret(console, &id, grace, reason, &confirm).await, + } => Self::rotate_secret(console, &id, grace, why.reason, &confirm).await, Self::Origin(command) => command.run(console).await, } } @@ -462,9 +450,9 @@ pub(super) struct CreateClient { /// ends (OIDC Back-Channel Logout); HTTPS with a public address. #[arg(long)] backchannel_logout_uri: Option, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, } /// A client a deployment manages, as `client apply` makes it. @@ -489,7 +477,7 @@ impl ApplyClient { async fn run(self, console: &Console) -> Result<(), CliError> { let secret = self.secret()?; let id = self.client.id.clone(); - let reason = self.client.reason.clone(); + let reason = self.client.why.reason.clone(); let registration = self.client.registration()?; let applied = console .service @@ -599,9 +587,9 @@ pub(super) struct UpdateClient { /// Stop posting logout tokens to the client. #[arg(long)] no_backchannel_logout_uri: bool, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, } impl UpdateClient { diff --git a/apps/auth-service/src/cli/console.rs b/apps/auth-service/src/cli/console.rs index 23fb9fab4..67c3d1482 100644 --- a/apps/auth-service/src/cli/console.rs +++ b/apps/auth-service/src/cli/console.rs @@ -1,10 +1,11 @@ //! What administrative commands share: the service and its operator, where they -//! print, and confirmation before changes that cut off a whole account, -//! administrator or client. +//! print, the reason a change records, and confirmation before changes that cut +//! off a whole account, administrator or client. use super::{CliError, output::Output}; use crate::{ - AdminService, AuthConfig, Operator, UserRef, account::AccountService, admin::OperatorName, + AdminService, AuthConfig, Operator, Reason, UserRef, account::AccountService, + admin::OperatorName, }; use clap::Args; use sourceorigin_common::{UserId, config::ConfigurationError}; @@ -66,6 +67,23 @@ impl Console { } } +/// The `--reason` of a change, recorded with it. +#[derive(Args)] +pub(super) struct Why { + /// Why, recorded with the change: 1 to 500 characters. + #[arg(long)] + pub(super) reason: Reason, +} + +/// The `--reason` of a change to an account, which its owner sees. +#[derive(Args)] +pub(super) struct WhyOwnerSees { + /// Why, recorded with the change and shown to the owner in their history: + /// 1 to 500 characters. + #[arg(long)] + pub(super) reason: Reason, +} + /// The `--yes` option of commands that cut off a whole account, administrator or /// client. Ending one session does not ask: the command names it exactly, and its /// owner can sign in again. diff --git a/apps/auth-service/src/cli/deliveries.rs b/apps/auth-service/src/cli/deliveries.rs index 9fdb2d498..6d66bc46a 100644 --- a/apps/auth-service/src/cli/deliveries.rs +++ b/apps/auth-service/src/cli/deliveries.rs @@ -1,10 +1,9 @@ //! The break-glass view of the outbound delivery queue. use super::{ - CliError, Console, + CliError, Console, Why, output::{Cell, Style, report}, }; -use crate::Reason; use clap::Subcommand; use sourceorigin_common::{DeliveryId, admin::DeliverySummary}; use sourceorigin_repository::DeliveryStatus; @@ -28,17 +27,17 @@ pub(super) enum DeliveriesCommand { Retry { /// The delivery's ID. id: DeliveryId, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, }, /// Cancel a pending or failed delivery. Cancel { /// The delivery's ID. id: DeliveryId, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, }, } @@ -61,12 +60,12 @@ impl DeliveriesCommand { .list_deliveries(operator, status, channel.as_deref(), limit) .await?[..], )?, - Self::Retry { id, reason } => { - admin.retry_delivery(operator, id, reason).await?; + Self::Retry { id, why } => { + admin.retry_delivery(operator, id, why.reason).await?; out.info(format_args!("Delivery {id} will be attempted again now."))?; } - Self::Cancel { id, reason } => { - admin.cancel_delivery(operator, id, reason).await?; + Self::Cancel { id, why } => { + admin.cancel_delivery(operator, id, why.reason).await?; out.info(format_args!("Cancelled delivery {id}."))?; } } diff --git a/apps/auth-service/src/cli/handle.rs b/apps/auth-service/src/cli/handle.rs index beb47763b..31759aafc 100644 --- a/apps/auth-service/src/cli/handle.rs +++ b/apps/auth-service/src/cli/handle.rs @@ -2,7 +2,7 @@ //! handles kept from others: released ones and reserved ones. use super::{ - CliError, Confirm, Console, + CliError, Confirm, Console, Why, WhyOwnerSees, output::{Cell, Style, report}, }; use crate::{HandleProblem, Reason, UserRef}; @@ -27,10 +27,9 @@ pub(super) enum HandleCommand { /// Its new handle. #[arg(value_parser = Handle::parse)] new: Handle, - /// Why, recorded with the change and shown to the owner in their history: - /// 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: WhyOwnerSees, /// Allow a reserved name, or one that looks like it. #[arg(long)] allow_reserved: bool, @@ -42,9 +41,9 @@ pub(super) enum HandleCommand { /// The released handle. #[arg(value_parser = Handle::parse)] handle: Handle, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, /// Confirmation. #[command(flatten)] confirm: Confirm, @@ -68,9 +67,9 @@ pub(super) enum HandleCommand { /// The handle. #[arg(value_parser = Handle::parse)] handle: Handle, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, }, } @@ -88,18 +87,18 @@ impl HandleCommand { Self::Rename { user, new, - reason, + why, allow_reserved, } => { let id = console.user(&user).await?; service - .rename_handle(operator, id, new.clone(), reason, allow_reserved) + .rename_handle(operator, id, new.clone(), why.reason, allow_reserved) .await?; out.info(format_args!("Renamed {user} to @{new}."))?; } Self::Release { handle, - reason, + why, confirm, } => { confirm.ask( @@ -109,7 +108,7 @@ impl HandleCommand { ), )?; service - .release_handle(operator, handle.clone(), reason) + .release_handle(operator, handle.clone(), why.reason) .await?; out.info(format_args!("Released @{handle}: anyone may claim it."))?; } @@ -124,9 +123,9 @@ impl HandleCommand { .await?; out.info(format_args!("Reserved @{handle}."))?; } - Self::Unreserve { handle, reason } => { + Self::Unreserve { handle, why } => { service - .unreserve_handle(operator, handle.clone(), reason) + .unreserve_handle(operator, handle.clone(), why.reason) .await?; out.info(format_args!("Unreserved @{handle}: anyone may claim it."))?; } diff --git a/apps/auth-service/src/cli/invite.rs b/apps/auth-service/src/cli/invite.rs index 724d7559c..27260b907 100644 --- a/apps/auth-service/src/cli/invite.rs +++ b/apps/auth-service/src/cli/invite.rs @@ -1,10 +1,10 @@ //! Signup invitations. use super::{ - CliError, Console, + CliError, Console, Why, output::{Cell, Single, report}, }; -use crate::{AuthConfig, InviteExpiry, Reason}; +use crate::{AuthConfig, InviteExpiry}; use clap::Subcommand; use sourceorigin_common::{ TokenId, @@ -28,9 +28,9 @@ pub(super) enum InviteCommand { /// How long the link stays valid, e.g. 24h or 7d. #[arg(long, default_value = "7d")] expires_in: InviteExpiry, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, }, /// List invitations, newest first, without their links. List, @@ -39,17 +39,17 @@ pub(super) enum InviteCommand { Resend { /// The invitation's ID, as `invite list` shows it. id: TokenId, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, }, /// Revoke an unredeemed invitation. Revoke { /// The invitation's ID, as `invite list` shows it. id: TokenId, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, }, } @@ -66,11 +66,11 @@ impl InviteCommand { Self::Create { email, expires_in, - reason, + why, } => { let links = AuthConfig::invitation_links_from_environment()?; let invitation = service - .create_invitation(operator, &links, expires_in, email, reason) + .create_invitation(operator, &links, expires_in, email, why.reason) .await?; match invitation.sent { InvitationSent::Link(link) => out.emit(&Single { @@ -87,12 +87,12 @@ impl InviteCommand { } } Self::List => out.emit(&service.list_invitations(operator).await?[..])?, - Self::Resend { id, reason } => { - service.resend_invitation(operator, id, reason).await?; + Self::Resend { id, why } => { + service.resend_invitation(operator, id, why.reason).await?; out.info(format_args!("Mailed invitation {id} again."))?; } - Self::Revoke { id, reason } => { - service.revoke_invitation(operator, id, reason).await?; + Self::Revoke { id, why } => { + service.revoke_invitation(operator, id, why.reason).await?; out.info(format_args!("Revoked invitation {id}."))?; } } diff --git a/apps/auth-service/src/cli/keys.rs b/apps/auth-service/src/cli/keys.rs index 05da7ccd2..900e8d5e6 100644 --- a/apps/auth-service/src/cli/keys.rs +++ b/apps/auth-service/src/cli/keys.rs @@ -5,11 +5,11 @@ //! keys page does. use super::{ - CliError, Confirm, Console, + CliError, Confirm, Console, Why, output::{Cell, Output, Single, report}, }; use crate::{ - AuditConfig, KeyEncryptionKeys, KeyStore, PUBLIC_BASE_URL, Reason, TokenDigestKeys, + AuditConfig, KeyEncryptionKeys, KeyStore, PUBLIC_BASE_URL, TokenDigestKeys, admin::{AdminOperation, OperatorName}, }; use clap::Subcommand; @@ -31,9 +31,9 @@ pub(super) enum KeysCommand { /// Asks first. #[arg(long)] now: bool, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, /// Confirmation, which `--now` needs. #[command(flatten)] confirm: Confirm, @@ -45,9 +45,9 @@ pub(super) enum KeysCommand { Revoke { /// The key's ID. id: KeyId, - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, /// Confirmation. #[command(flatten)] confirm: Confirm, @@ -56,9 +56,9 @@ pub(super) enum KeysCommand { /// a change of key-encryption key, so `AUTH_KEY_ENCRYPTION_KEY_ACCEPTED` can /// be removed. Refuses, changing nothing, if a key opens under neither. Rewrap { - /// Why, recorded with the change: 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: Why, /// Confirmation. #[command(flatten)] confirm: Confirm, @@ -122,11 +122,7 @@ impl KeysCommand { } = &console()?; out.emit(&service.list_signing_keys(operator).await?[..])?; } - Self::Rotate { - now, - reason, - confirm, - } => { + Self::Rotate { now, why, confirm } => { let Console { service, operator, .. } = &console()?; @@ -137,25 +133,21 @@ impl KeysCommand { )?; } let id = service - .rotate_signing_key(operator, &store()?, now, reason) + .rotate_signing_key(operator, &store()?, now, why.reason) .await?; out.emit(&Single { name: "id", value: id, })?; } - Self::Revoke { - id, - reason, - confirm, - } => { + Self::Revoke { id, why, confirm } => { let Console { service, operator, .. } = &console()?; let keys = service.list_signing_keys(operator).await?; confirm.ask(&out, &Self::revoking(&id, &keys))?; match service - .revoke_signing_key(operator, &store()?, &id, reason) + .revoke_signing_key(operator, &store()?, &id, why.reason) .await? { Some(replacement) => out.info(format_args!( @@ -164,7 +156,7 @@ impl KeysCommand { None => out.info(format_args!("Revoked key {id}."))?, } } - Self::Rewrap { reason, confirm } => { + Self::Rewrap { why, confirm } => { let Console { service, operator, .. } = &console()?; @@ -173,7 +165,7 @@ impl KeysCommand { "Seal every signing key again under AUTH_KEY_ENCRYPTION_KEY: a replica that has it neither as its key-encryption key nor as its accepted one can no longer open them", )?; let ids = service - .rewrap_signing_keys(operator, &store()?, reason) + .rewrap_signing_keys(operator, &store()?, why.reason) .await?; if ids.is_empty() { out.info("No signing key has a private key to rewrap.")?; diff --git a/apps/auth-service/src/cli/mod.rs b/apps/auth-service/src/cli/mod.rs index 8fceba5f8..8b6e23ec3 100644 --- a/apps/auth-service/src/cli/mod.rs +++ b/apps/auth-service/src/cli/mod.rs @@ -17,7 +17,7 @@ mod announcement; mod audit; /// Registering, inspecting and changing OIDC clients. mod client; -/// The service and operator, and confirmation. +/// The service and operator, and the reasons and confirmation changes take. mod console; /// The outbound delivery queue. mod deliveries; @@ -53,7 +53,7 @@ use announcement::AnnouncementCommand; use audit::AuditCommand; use clap::{Parser, Subcommand}; use client::{ClientCommand, OriginCommand}; -use console::{Confirm, Console}; +use console::{Confirm, Console, Why, WhyOwnerSees}; use deliveries::DeliveriesCommand; use error::CliError; use handle::HandleCommand; diff --git a/apps/auth-service/src/cli/user.rs b/apps/auth-service/src/cli/user.rs index 8c6377ec0..c6d84f5b5 100644 --- a/apps/auth-service/src/cli/user.rs +++ b/apps/auth-service/src/cli/user.rs @@ -2,7 +2,7 @@ //! accounts. use super::{ - CliError, Confirm, Console, + CliError, Confirm, Console, WhyOwnerSees, output::{Cell, Joined, Single, Style, Time, report}, }; use crate::{ @@ -40,10 +40,9 @@ pub(super) enum UserCommand { Disable { /// The account: its handle, ID or verified email. user: UserRef, - /// Why, recorded with the change and shown to the owner in their history: - /// 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: WhyOwnerSees, /// Confirmation. #[command(flatten)] confirm: Confirm, @@ -52,10 +51,9 @@ pub(super) enum UserCommand { Enable { /// The account: its handle, ID or verified email. user: UserRef, - /// Why, recorded with the change and shown to the owner in their history: - /// 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: WhyOwnerSees, }, /// Recover an account whose owner lost every passkey. /// @@ -98,10 +96,9 @@ pub(super) enum UserCommand { Delete { /// The account: its handle, ID or verified email. user: UserRef, - /// Why, recorded with the change and shown to the owner in their history: - /// 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: WhyOwnerSees, /// Purge the account now, in any status, without a grace period. This /// cannot be undone. #[arg(long)] @@ -131,10 +128,9 @@ pub(super) enum UserCommand { Restore { /// The account: its handle, ID or verified email. user: UserRef, - /// Why, recorded with the change and shown to the owner in their history: - /// 1 to 500 characters. - #[arg(long)] - reason: Reason, + /// Why. + #[command(flatten)] + why: WhyOwnerSees, }, } @@ -155,19 +151,15 @@ impl UserCommand { let id = console.user(&user).await?; out.emit(&service.view_user(operator, id).await?)?; } - Self::Disable { - user, - reason, - confirm, - } => { + Self::Disable { user, why, confirm } => { let id = console.user(&user).await?; confirm.ask(out, &format!("Disable {user} ({id}) and end its sessions"))?; - service.disable_user(operator, id, reason).await?; + service.disable_user(operator, id, why.reason).await?; out.info(format_args!("Disabled {user} and ended its sessions."))?; } - Self::Enable { user, reason } => { + Self::Enable { user, why } => { let id = console.user(&user).await?; - service.enable_user(operator, id, reason).await?; + service.enable_user(operator, id, why.reason).await?; out.info(format_args!("Enabled {user}: it can sign in again."))?; } Self::Recover { @@ -203,13 +195,13 @@ impl UserCommand { } Self::Delete { user, - reason, + why, immediately, confirm, - } => Self::delete(console, &user, reason, immediately, &confirm).await?, - Self::Restore { user, reason } => { + } => Self::delete(console, &user, why.reason, immediately, &confirm).await?, + Self::Restore { user, why } => { let id = console.user(&user).await?; - service.restore_user(operator, id, reason).await?; + service.restore_user(operator, id, why.reason).await?; out.info(format_args!("Restored {user}: it can sign in again."))?; } }