From 614b50c6c5f2ca0054ba06f8ad72832f6b108362 Mon Sep 17 00:00:00 2001 From: piquel Date: Fri, 20 Nov 2026 08:39:30 +0100 Subject: [PATCH] refactor(cli): user show reuses the passkey and identity tables user show printed its passkeys and linked identities with copies of the tables account passkeys list and account identities list print. It now calls those reports, and the client reports share one owner cell. --- apps/auth-service/src/cli/account.rs | 4 ++-- apps/auth-service/src/cli/client.rs | 19 +++++++++---------- apps/auth-service/src/cli/user.rs | 19 ++----------------- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/apps/auth-service/src/cli/account.rs b/apps/auth-service/src/cli/account.rs index d740ee0ba..45e857364 100644 --- a/apps/auth-service/src/cli/account.rs +++ b/apps/auth-service/src/cli/account.rs @@ -470,7 +470,7 @@ report!(Option, self, out, { } }); -// One passkey per line. +// One passkey per line, as `user show` lists them too. report!([Passkey], self, out, { out.table( ["ID", "NAME"], @@ -480,7 +480,7 @@ report!([Passkey], self, out, { ) }); -// One linked provider per line. +// One linked provider per line, as `user show` lists them too. report!([Identity], self, out, { out.table( ["PROVIDER", "EMAIL"], diff --git a/apps/auth-service/src/cli/client.rs b/apps/auth-service/src/cli/client.rs index f4c4f06ad..6afb46843 100644 --- a/apps/auth-service/src/cli/client.rs +++ b/apps/auth-service/src/cli/client.rs @@ -7,7 +7,7 @@ use super::{ use crate::{Applied, ClientDetails, GracePeriod, PUBLIC_BASE_URL, Reason}; use clap::{Args, Subcommand}; use sourceorigin_common::{ - ClientId, + ClientId, UserId, admin::{ApprovedOrigin, Client}, clients::{ AllowedScopes, BackchannelLogoutUri, ClientKind, ClientRegistration, DisplayName, @@ -292,6 +292,12 @@ impl ClientCommand { .warning("Store this client secret now: it cannot be shown again.") } + /// Who owns a client: its owner's account ID, or a muted `operator` for one + /// no account owns. + fn owner(owner: Option) -> Cell { + owner.map_or_else(|| Cell::new("operator").style(Style::Muted), Cell::new) + } + /// A client's status, coloured: `deleted`, `suspended`, `disabled` or /// `enabled`. Deletion comes first, then a suspension. fn status(deleted: bool, suspended: bool, enabled: bool) -> Cell { @@ -323,9 +329,7 @@ report!([Client], self, out, { client.allow_refresh.into(), client.trusted.into(), client.require_pushed_authorization_requests.into(), - client - .owner_id - .map_or_else(|| Cell::new("operator").style(Style::Muted), Cell::new), + ClientCommand::owner(client.owner_id), Cell::new(&client.display_name), ] }), @@ -353,12 +357,7 @@ report!(ClientDetails, self, out, { client.enabled, ), ), - ( - "Owner", - client - .owner_id - .map_or_else(|| Cell::new("operator").style(Style::Muted), Cell::new), - ), + ("Owner", ClientCommand::owner(client.owner_id)), ("Redirect URIs", list(&client.redirect_uris)), ("Post-logout URIs", list(&client.post_logout_uris)), ("Scopes", list(&client.allowed_scopes)), diff --git a/apps/auth-service/src/cli/user.rs b/apps/auth-service/src/cli/user.rs index c6d84f5b5..9aeef276e 100644 --- a/apps/auth-service/src/cli/user.rs +++ b/apps/auth-service/src/cli/user.rs @@ -400,24 +400,9 @@ report!(UserDetail, self, out, { }), )?; out.section("Passkeys")?; - out.table( - ["ID", "NAME"], - "No passkeys.", - self.passkeys - .iter() - .map(|passkey| [Cell::new(passkey.id), Cell::new(&passkey.friendly_name)]), - )?; + self.passkeys[..].human(out)?; out.section("Linked identities")?; - out.table( - ["PROVIDER", "EMAIL"], - "No linked identities.", - self.identities.iter().map(|identity| { - [ - Cell::new(identity.provider), - identity.linked_email.as_deref().into(), - ] - }), - )?; + self.identities[..].human(out)?; out.section("Sessions")?; out.table( ["ID", "METHODS", "SIGNED IN", "LAST SEEN", "EXPIRES"],