Skip to content

Commit 09c6ede

Browse files
PiquelChipsclaude
andauthored
fix(ui): the crumb leads through the tab and the account, client or app, in lowercase menus, replacing the back links (#372)
In the admin dashboard, opening an account from Users showed "admin / handle" in the top bar, and a client from Clients showed "admin / name". The tab in between was missing, so there was no way back up except the sidebar, and the pages below carried "← Back" links to make up for it. The crumb also mixed cases: "admin / Users" on the list, "admin / users / handle" below it. The crumb now leads the whole way and reads in one case. The dashboard puts the current tab between the area and the page, then the account or client a deeper page belongs to, each linked: "admin / users / azerty / security history", "admin / clients / name / client secrets", "admin / administrators / handle / revoke rights". Every menu name in the crumb is lowercase, in every signed-in shell; a name someone chose, a handle, a display name, a client's or an app's, keeps its case. A `Crumb` type on the shell tells the two apart, and a plain string is a menu name, so the pages that name themselves from a menu are unchanged. The developer console's app pages follow the same rule: "developers / My App / settings", the app linking its overview. Every "← Back" link in the dashboard is gone, since the crumb leads there now. A trail too long for a phone shortens its long links to an ellipsis and keeps the page's name whole. Proof: two database tests render the pages through the real server, one for an account under Users and its history, one for an app and its settings in the console, and assert each link, its text and its case; both pass on a scratch cluster, and clippy and rustfmt are clean. Every crumb above was also read live on the branch's piqueld preview with a fresh administrator, at desktop width and at 360px. Reviewed with review-loop: 4 rounds in all with 2× GPT 6.1 Sol and Claude Opus 5.5, the last two on the lowercase crumb and the app trail. Verdict: approved > [!NOTE] > written by Claude Fable 5.1 in Claude Code and reviewed by GPT 6.1 Sol and Claude Opus 5.5 (via T3 Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent dd46679 commit 09c6ede

21 files changed

Lines changed: 305 additions & 97 deletions

File tree

‎apps/auth-service/src/admin/service/accounts.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ impl AdminService {
6161
found.ok_or(AdminError::UserNotFound)
6262
}
6363

64+
/// The handle of the account `user_id`, in any status, which names it.
65+
pub(crate) async fn user_handle(
66+
&self,
67+
operator: &Operator,
68+
user_id: UserId,
69+
) -> Result<Handle, AdminError> {
70+
operator.authorize_read(&self.database).await?;
71+
let user = self
72+
.database
73+
.users()
74+
.find_by_id(user_id)
75+
.await?
76+
.ok_or(AdminError::UserNotFound)?;
77+
Ok(user.handle)
78+
}
79+
6480
/// Lists `page` of the accounts matching `query`, by handle: the first page
6581
/// when `None`.
6682
pub(crate) async fn search_users(

‎apps/auth-service/src/web/account.rs‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use crate::{
2222
use piquel_common::ErrorChain;
2323
use piquel_telemetry::HttpTelemetry;
2424
use piquel_ui::{
25-
AccountNav, Alert, FieldError, LoginQuery, Messages, Notice, Query, Recovery, Section, Tab, Who,
25+
AccountNav, Alert, Crumb, FieldError, LoginQuery, Messages, Notice, Query, Recovery, Section,
26+
Tab, Who,
2627
};
2728
use serde::{Deserialize, de::DeserializeOwned};
2829
use topcoat::{
@@ -223,8 +224,11 @@ pub(super) struct Framed<'a> {
223224
pub(super) section: Section,
224225
/// The settings tab it is, if it is one, which the sidebar marks.
225226
pub(super) tab: Option<Tab>,
226-
/// Its title in the browser.
227-
pub(super) title: &'a str,
227+
/// The pages it is under, named and linked in the crumb: an app's page is
228+
/// under the app.
229+
pub(super) trail: &'a [(Crumb<'a>, &'a str)],
230+
/// Its title in the browser and its name in the crumb.
231+
pub(super) title: Crumb<'a>,
228232
/// What opens it, above its messages, such as an app's header.
229233
pub(super) head: Child<'a>,
230234
/// The page.
@@ -351,7 +355,8 @@ impl WebApplication {
351355
let framed = Framed {
352356
section: P::SECTION,
353357
tab: None,
354-
title: P::TITLE,
358+
trail: &[],
359+
title: P::TITLE.into(),
355360
head: Child::new(head),
356361
page: Child::default(),
357362
};
@@ -404,6 +409,7 @@ impl WebApplication {
404409
let Framed {
405410
section,
406411
tab,
412+
trail,
407413
title,
408414
head,
409415
page,
@@ -413,7 +419,7 @@ impl WebApplication {
413419
Ok(profile) => profile,
414420
Err(AccountError::Owner(SessionError::Missing)) => {
415421
return self
416-
.signed_out(cx, section, title, StatusCode::UNAUTHORIZED)
422+
.signed_out(cx, section, title.as_str(), StatusCode::UNAUTHORIZED)
417423
.await;
418424
}
419425
Err(error) => return Err(error.into()),
@@ -459,6 +465,7 @@ impl WebApplication {
459465
piquel_ui::account(
460466
nav: nav,
461467
who: who,
468+
trail: trail,
462469
title: title,
463470
home: page::settings::HOME,
464471
sign_out: page::LOGOUT,
@@ -483,7 +490,7 @@ impl WebApplication {
483490
)
484491
};
485492
Ok(self
486-
.render_document(cx, status, title, targets, false, page)
493+
.render_document(cx, status, title.as_str(), targets, false, page)
487494
.await?)
488495
}
489496

‎apps/auth-service/src/web/admin/administrators.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub(super) async fn grant(cx: &Cx, form: Option<Form<GrantForm>>) -> Result<Resp
7373
.as_ref()
7474
.map(|Form(form)| (form.q.clone(), form.page))
7575
.unwrap_or_default();
76-
let refusal = App::submit(cx, form, back.clone(), |input: GrantForm| async move {
76+
let refusal = App::submit(cx, form, back, |input: GrantForm| async move {
7777
let user_id = input.user_id.ok_or(AdminError::UserNotFound)?;
7878
service.grant_administrator(&admin.operator, user_id).await
7979
})
@@ -109,7 +109,6 @@ pub(super) async fn grant(cx: &Cx, form: Option<Form<GrantForm>>) -> Result<Resp
109109
q: q.as_str(),
110110
rows: rows,
111111
pages: pager,
112-
back: back.as_str(),
113112
refusal: refusal,
114113
)
115114
};

‎apps/auth-service/src/web/admin/clients.rs‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use piquel_common::{
3131
};
3232
use piquel_repository::StoredOidcClient;
3333
use piquel_ui::{
34-
Action, AdminClientRow, Change, ClientChanges, ClientPage, ClientRow, ClientStatus,
34+
Action, AdminClientRow, Change, ClientChanges, ClientPage, ClientRow, ClientStatus, Crumb,
3535
NewClientForm, OperatorDraft, Query, Registration, Revealed, SecretRow, SecretsChange,
3636
SecretsState,
3737
};
@@ -145,12 +145,18 @@ pub(super) async fn detail(cx: &Cx) -> Result<Response> {
145145
approve,
146146
changes,
147147
};
148-
let (shown, back) = (&shown, &href!(list).resolve(cx));
148+
let shown = &shown;
149149
let page = view! { cx =>
150-
piquel_ui::client_page(page: shown, back: back.as_str(), now: Utc::now())
150+
piquel_ui::client_page(page: shown, now: Utc::now())
151151
};
152152
// A large page: its future is boxed, off the handler's stack.
153-
Box::pin(App::render(cx, StatusCode::OK, App::title(stored), page)).await
153+
Box::pin(App::render(
154+
cx,
155+
StatusCode::OK,
156+
Crumb::Name(App::title(stored)),
157+
page,
158+
))
159+
.await
154160
}
155161

156162
/// `/clients/new`: registers a client operators manage, then goes on to its page,
@@ -270,9 +276,8 @@ pub(super) async fn rotate(cx: &Cx, form: Option<Form<SecretsChange>>) -> Result
270276
expires_at: secret.expires_at,
271277
})
272278
.collect();
273-
let (here, back, name, secrets, state, refusal) = (
279+
let (here, name, secrets, state, refusal) = (
274280
&here,
275-
&href!(detail, Client(id.clone())).resolve(cx),
276281
App::title(&details.client),
277282
&secrets,
278283
&state,
@@ -281,7 +286,6 @@ pub(super) async fn rotate(cx: &Cx, form: Option<Form<SecretsChange>>) -> Result
281286
let page = view! { cx =>
282287
piquel_ui::client_secrets(
283288
page: here.as_str(),
284-
back: back.as_str(),
285289
name: name,
286290
secrets: secrets,
287291
now: Utc::now(),
@@ -459,7 +463,7 @@ impl App {
459463

460464
/// The name of client `stored`'s pages: its own, or its ID once deleted, which
461465
/// erases its name.
462-
fn title(stored: &StoredOidcClient) -> &str {
466+
pub(super) fn title(stored: &StoredOidcClient) -> &str {
463467
if stored.display_name.is_empty() {
464468
stored.id.as_str()
465469
} else {
@@ -492,20 +496,13 @@ impl App {
492496
settings: &OperatorDraft,
493497
refusal: Option<&str>,
494498
) -> Result<Response> {
495-
let back = match registration {
496-
Registration::New { .. } => href!(list).resolve(cx),
497-
Registration::Edit { .. } => {
498-
href!(detail, Client(path_param::<Client>(cx)?.clone())).resolve(cx)
499-
}
500-
};
501499
let here = uri(cx).path().to_owned();
502-
let (title, back, here) = (registration.title(), &back, &here);
500+
let (title, here) = (registration.title(), &here);
503501
let page = view! { cx =>
504502
piquel_ui::client_registration(
505503
registration: registration,
506504
settings: settings,
507505
action: here.as_str(),
508-
back: back.as_str(),
509506
refusal: refusal,
510507
)
511508
};

‎apps/auth-service/src/web/admin/mod.rs‎

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ use crate::{
5959
};
6060
use axum::http::header::InvalidHeaderValue;
6161
use chrono::Duration;
62-
use piquel_common::{ErrorChain, config::Origin};
62+
use piquel_common::{ClientId, ErrorChain, UserId, config::Origin};
6363
use piquel_crypto::{KeyEncryptionKey, NoteVerifier};
6464
use piquel_repository::Database;
6565
use piquel_telemetry::HttpTelemetry;
66-
use piquel_ui::{Dashboard, DashboardTab, Health, PreferenceChange, Search, Who};
66+
use piquel_ui::{Crumb, Dashboard, DashboardTab, Health, PreferenceChange, Search, Who};
6767
use serde::Deserialize;
6868
use std::{
6969
future::Future,
@@ -600,16 +600,64 @@ impl AdminApplication {
600600
.or_else(|| (path == tabs[0].1).then_some(DashboardTab::Overview))
601601
}
602602

603+
/// The page the request's page is under, inside `current`, among `tabs`, if
604+
/// any, named and linked in the crumb: the account under Users or
605+
/// Administrators, or the client under Clients, which a page such as
606+
/// `/users/{account}/disable` changes. The account's or client's own page,
607+
/// and a tab's other pages, have none. A parent that cannot be read, such as
608+
/// on the error page of an account that does not exist, is left out: the
609+
/// page itself says what went wrong.
610+
async fn parent(
611+
cx: &Cx,
612+
admin: Option<&SignedInAdmin>,
613+
tabs: &[(DashboardTab, String)],
614+
current: Option<DashboardTab>,
615+
) -> Option<(String, String)> {
616+
let (admin, current) = (admin?, current?);
617+
let path = uri(cx).path();
618+
let (_, tab) = tabs.iter().find(|(tab, _)| *tab == current)?;
619+
// Only a page below the account's or client's has one: `/clients/new`
620+
// names no client, whatever its registry holds.
621+
let below = path.strip_prefix(tab.as_str())?.strip_prefix('/')?;
622+
let (id, _) = below.split_once('/')?;
623+
let service = &Self::of(cx).service;
624+
match current {
625+
// An administrator's page is their account's, under Users.
626+
DashboardTab::Users | DashboardTab::Administrators => {
627+
let id: UserId = id.parse().ok()?;
628+
let handle = service.user_handle(&admin.operator, id).await.ok()?;
629+
Some((handle.to_string(), Self::account(cx, id)))
630+
}
631+
DashboardTab::Clients => {
632+
let id: ClientId = id.parse().ok()?;
633+
let href = href!(clients::detail, clients::Client(id.clone())).resolve(cx);
634+
if path == href {
635+
return None;
636+
}
637+
let details = service.client_details(&admin.operator, &id).await.ok()?;
638+
Some((Self::title(&details.client).to_owned(), href))
639+
}
640+
_ => None,
641+
}
642+
}
643+
603644
/// Answers with the page named `title` and `page`, at `status`, in the shell
604645
/// every page shares: the sidebar of tabs, the signed-in administrator and
605646
/// signing out, the account search, the service's health, and the trace ID
606647
/// of a server error.
607-
async fn render(cx: &Cx, status: StatusCode, title: &str, page: impl View) -> Result<Response> {
648+
async fn render<'a>(
649+
cx: &Cx,
650+
status: StatusCode,
651+
title: impl Into<Crumb<'a>>,
652+
page: impl View,
653+
) -> Result<Response> {
654+
let title = title.into();
608655
// A browser that is not signed in is sent on by the page itself.
609656
let admin = Self::admin(cx).await.ok();
610657
let app = Self::of(cx);
611658
let tabs = Self::tabs(cx);
612659
let current = Self::current_tab(cx, &tabs);
660+
let parent = Self::parent(cx, admin, &tabs, current).await;
613661
let links: &Vec<_> = &tabs
614662
.iter()
615663
.map(|(tab, link)| (*tab, link.as_str()))
@@ -649,6 +697,9 @@ impl AdminApplication {
649697
me: &me,
650698
tabs: links,
651699
current,
700+
parent: parent
701+
.as_ref()
702+
.map(|(name, href)| (name.as_str(), href.as_str())),
652703
sign_out: leave,
653704
preferences: BrowserCookie::read_preferences(headers(cx)),
654705
preferences_action: prefer,
@@ -667,7 +718,7 @@ impl AdminApplication {
667718
let page = Child::new(page);
668719
let html = view! { cx =>
669720
piquel_ui::document(
670-
title: title,
721+
title: title.as_str(),
671722
stylesheet: stylesheet,
672723
preferences: dashboard.preferences,
673724
admin: true,

‎apps/auth-service/src/web/admin/settings.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,9 @@ impl App {
423423
.iter()
424424
.map(|(tab, link)| (*tab, link.as_str()))
425425
.collect();
426-
let back = &Self::account(cx, user);
427426
let section = Child::new(section);
428427
let page = view! { cx =>
429428
piquel_ui::account_settings(
430-
back: back.as_str(),
431429
tabs: tabs,
432430
current: tab,
433431
refusal: refused,

‎apps/auth-service/src/web/admin/tests.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,40 @@ async fn an_accounts_page_names_no_passkey() {
547547
assert!(!page.contains(&passkey.friendly_name), "{page}");
548548
}
549549

550+
/// A page inside a tab has the tab in its crumb, linking its page: an account's
551+
/// reads "admin / users / handle", and the account's history "admin / users /
552+
/// handle / security history", the handle linking the account. The tab's own
553+
/// page names it once. The menus' names are lowercase; the account's are not.
554+
#[tokio::test]
555+
#[ignore = "requires TEST_DATABASE_URL"]
556+
async fn the_crumb_leads_through_the_tab() {
557+
let harness = Harness::new().await;
558+
let admin = harness.admin().await;
559+
let owner = Browser::new_account(&harness.database).await;
560+
let account = format!("/users/{}", owner.user_id);
561+
let dashboard = harness.sign_in(&admin, &account).await;
562+
let page = html(harness.visit(&dashboard, &account).await).await;
563+
let users = r#"<a href="/users">users</a>"#;
564+
assert!(page.contains(users), "{page}");
565+
// The menus' names are lowercase in the crumb; the account's own are not.
566+
assert!(page.contains(r#"<a href="/">admin</a>"#), "{page}");
567+
assert!(page.contains("<b>browser-"), "{page}");
568+
let page = html(harness.visit(&dashboard, "/users").await).await;
569+
assert!(!page.contains(users), "{page}");
570+
assert!(page.contains("<b>users</b>"), "{page}");
571+
let page = html(
572+
harness
573+
.visit(&dashboard, &format!("{account}/history"))
574+
.await,
575+
)
576+
.await;
577+
assert!(
578+
page.contains(&format!(r#"<a href="{account}">browser-"#)),
579+
"{page}"
580+
);
581+
assert!(page.contains("<b>security history</b>"), "{page}");
582+
}
583+
550584
/// The audit page shows the chain as `audit verify` reports it, and says that
551585
/// pruning is the database owner's, from the command line.
552586
#[tokio::test]

‎apps/auth-service/src/web/admin/users.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use piquel_common::{
88
};
99
use piquel_repository::{RecentRecovery, RecoveryState};
1010
use piquel_ui::{
11-
AccountPages, Action, Change, Pager, Query, RecoveryKey, RecoveryRow, RecoveryStanding,
11+
AccountPages, Action, Change, Crumb, Pager, Query, RecoveryKey, RecoveryRow, RecoveryStanding,
1212
SessionRow, UserRow,
1313
};
1414
use serde::de::IgnoredAny;
@@ -174,7 +174,7 @@ pub(super) async fn detail(cx: &Cx) -> Result<Response> {
174174
Box::pin(App::render(
175175
cx,
176176
StatusCode::OK,
177-
detail.user.display_name.as_str(),
177+
Crumb::Name(detail.user.handle.as_str()),
178178
page,
179179
))
180180
.await

0 commit comments

Comments
 (0)