Skip to content

Commit e43cdb7

Browse files
committed
fix(ui): every error notice has its icon
Most error notices were written by hand without the warning icon and the `.text` span that `alert_notice` gives, so the same refusal looked different from page to page. Every error notice now renders through `alert_notice`, which takes an optional message and renders nothing without one. The passkey error placeholders render through it too, and the passkey and dashboard scripts write the failure into the notice's `.text`, so the icon stays. Closes #550
1 parent 467e813 commit e43cdb7

17 files changed

Lines changed: 125 additions & 76 deletions

File tree

‎apps/auth-service/assets/dashboard.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ function wire(document) {
9696
const dialog = document.getElementById('passkey-confirmation');
9797
const button = dialog?.querySelector('button[data-passkey-confirm]');
9898
const alert = dialog?.querySelector('[data-passkey-error]');
99+
const alertText = alert?.querySelector('.text');
99100
const confirming = dialog?.querySelector('[data-confirming]');
100101
if (
101102
!dialog ||
102103
!(button instanceof HTMLButtonElement) ||
103104
!(alert instanceof HTMLElement) ||
105+
!(alertText instanceof HTMLElement) ||
104106
!(confirming instanceof HTMLElement)
105107
)
106108
return;
@@ -209,7 +211,7 @@ function wire(document) {
209211
return;
210212
}
211213
busy(false);
212-
alert.textContent =
214+
alertText.textContent =
213215
cause instanceof DOMException
214216
? 'The passkey request was cancelled or unavailable. Try again or use another device.'
215217
: cause instanceof Error

‎apps/auth-service/assets/passkey.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ class Passkeys {
386386
* passkeys are known to work here; its `data-unavailable` note says why, and hides
387387
* once it is enabled.
388388
* While a passkey form's ceremony runs, the form is busy: its button is disabled and
389-
* says so, and its `data-passkey-error` element, which says why the last one failed,
390-
* hides.
389+
* says so, and its `data-passkey-error` notice, which says in its `.text` why the
390+
* last one failed, hides.
391391
* @param {Document} document
392392
* @returns {void}
393393
*/
@@ -421,6 +421,7 @@ function wire(document) {
421421
const run = (form, ceremony) => {
422422
if (form.dataset.busy) return;
423423
const alert = /** @type {HTMLElement | null} */ (form.querySelector('[data-passkey-error]'));
424+
const text = alert?.querySelector('.text');
424425
const button = form.querySelector('button');
425426
const label = button?.textContent ?? '';
426427
/** @param {boolean} waiting */
@@ -441,8 +442,8 @@ function wire(document) {
441442
},
442443
(/** @type {unknown} */ cause) => {
443444
busy(false);
444-
if (!alert) return;
445-
alert.textContent = Passkeys.message(cause);
445+
if (!alert || !text) return;
446+
text.textContent = Passkeys.message(cause);
446447
alert.hidden = false;
447448
}
448449
);

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,13 @@ pub(super) async fn create(cx: &Cx, form: Option<Form<NewClientForm>>) -> Result
190190
id: &shown.id,
191191
kind: shown.kind(),
192192
};
193-
App::registration_page(cx, registration, &shown.settings, refusal.as_deref()).await
193+
Box::pin(App::registration_page(
194+
cx,
195+
registration,
196+
&shown.settings,
197+
refusal.as_deref(),
198+
))
199+
.await
194200
}
195201

196202
/// `/clients/{client}/settings`: changes a client's registration, every setting
@@ -222,7 +228,13 @@ pub(super) async fn edit(cx: &Cx, form: Option<Form<OperatorDraft>>) -> Result<R
222228
let registration = Registration::Edit {
223229
name: App::title(&stored),
224230
};
225-
App::registration_page(cx, registration, &shown, refusal.as_deref()).await
231+
Box::pin(App::registration_page(
232+
cx,
233+
registration,
234+
&shown,
235+
refusal.as_deref(),
236+
))
237+
.await
226238
}
227239

228240
/// `/clients/{client}/secret`: a confidential client's secrets, and rotating
@@ -548,6 +560,6 @@ impl App {
548560
refusal: refusal,
549561
)
550562
};
551-
App::render(cx, StatusCode::OK, title, page).await
563+
Box::pin(App::render(cx, StatusCode::OK, title, page)).await
552564
}
553565
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub(super) async fn history(cx: &Cx) -> Result<Response> {
319319
};
320320
let rows = &rows;
321321
let section = view! { cx => sourceorigin_ui::history(rows: rows, holds: holds, page: page) };
322-
App::settings_page(cx, user, Tab::History, None, section).await
322+
Box::pin(App::settings_page(cx, user, Tab::History, None, section)).await
323323
}
324324

325325
/// `/users/{account}/notifications`: the account's inbox, as its owner sees

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ async fn failures_are_said_above_the_page() {
809809
] {
810810
let failed = format!("{LOGIN}?error={error}&return_to=%2Fsettings%2Fsessions");
811811
let page = html(browser.visit(&replicas.a, &failed).await).await;
812-
let alert = format!(r#"<p class="notice error" role="alert">{message}</p>"#);
812+
let alert = format!(r#"<span class="text">{message}</span></p>"#);
813813
assert!(page.contains(&alert), "{page}");
814814
assert!(!page.contains(&format!("error={error}")), "{page}");
815815
assert_eq!(

‎crates/ui/src/admin/announcements.rs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::icons::{Icon, icon};
66
use crate::{
77
clients::choice,
88
email::{Mail, email_preview},
9-
layout::page_head,
9+
layout::{alert_notice, page_head},
1010
};
1111
use sourceorigin_common::admin::{
1212
Announcement, AnnouncementAudience, AnnouncementDetail, DraftAnnouncement, User,
@@ -248,9 +248,7 @@ pub async fn announcement_form<'a>(
248248
let sending = Change::SendAnnouncement.confirming(subject);
249249
Ok(view! {
250250
page_head(title: change.title(), lead: change.description().to_owned())
251-
if let Some(refusal) = refusal {
252-
<p class="notice error" role="alert">(refusal)</p>
253-
}
251+
alert_notice(message: refusal)
254252
<section class="card">
255253
<form class="stack" method="post" data-submit-once="" data-unconfirmed="" data-confirming=(sending.as_str())>
256254
<label>

‎crates/ui/src/admin/audit.rs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! The audit chain's state and its checkpoints.
22
33
use super::moment;
4-
use crate::layout::page_head;
4+
use crate::layout::{alert_notice, page_head};
55
use sourceorigin_common::admin::{AuditPage, ChainPoint, Pruning, VerificationKeys};
66
use topcoat::{
77
Result,
@@ -38,9 +38,7 @@ pub async fn audit_page<'a>(
3838
Run auth-service audit verify from a trusted build for the authoritative check."
3939
.to_owned(),
4040
)
41-
if let Some(refusal) = refusal {
42-
<p class="notice error" role="alert">(refusal)</p>
43-
}
41+
alert_notice(message: refusal)
4442
chain_card(page: page, uncommitted: uncommitted)
4543
<section class="card">
4644
<header><h2>"Checkpoints"</h2></header>
@@ -115,19 +113,21 @@ async fn chain_card<'a>(page: &'a AuditPage, uncommitted: bool) -> Result<impl V
115113
(Some(_), Some(_)) => ("danger", "Broken at last check"),
116114
(Some(_), None) => ("ok", "Intact at last check"),
117115
};
116+
let broken = broken.map(|broken| {
117+
format!(
118+
"The last check found the chain broken at position {}: {}. \
119+
The change may also be a removal or insertion just before it.",
120+
broken.position, broken.problem
121+
)
122+
});
118123
Ok(view! {
119124
<section class="card">
120125
<header>
121126
<h2>"Chain"</h2>
122127
<span class=(class!("badge", badge))>(status)</span>
123128
</header>
124129
<div class="body">
125-
if let Some(broken) = broken {
126-
<p class="notice error" role="alert">
127-
(format!("The last check found the chain broken at position {}: {}.", broken.position, broken.problem))
128-
" The change may also be a removal or insertion just before it."
129-
</p>
130-
}
130+
alert_notice(message: broken.as_deref())
131131
if uncommitted {
132132
<p class="notice warning">
133133
"No audit key is committed for this environment, so checkpoints are checked \

‎crates/ui/src/admin/clients.rs‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
developers::{SecretsState, app_secrets},
1313
form::{Checkbox, Lines},
1414
icons::Icon,
15-
layout::{Destination, Group, page_head},
15+
layout::{Destination, Group, alert_notice, page_head},
1616
};
1717
use chrono::{DateTime, Utc};
1818
use serde::Deserialize;
@@ -183,9 +183,7 @@ pub async fn client_registration<'a>(
183183
};
184184
Ok(view! {
185185
page_head(title: title, lead: lead)
186-
if let Some(refusal) = refusal {
187-
<p class="notice error" role="alert">(refusal)</p>
188-
}
186+
alert_notice(message: refusal)
189187
client_form(
190188
action: action,
191189
change: (),
@@ -426,9 +424,7 @@ pub async fn client_secrets<'a>(
426424
) -> Result<impl View> {
427425
Ok(view! {
428426
page_head(title: "Client secrets", lead: name.to_owned())
429-
if let Some(refusal) = refusal {
430-
<p class="notice error" role="alert">(refusal)</p>
431-
}
427+
alert_notice(message: refusal)
432428
app_secrets(page: page, secrets: secrets, now: now, state: state, confirmed: true, reason: reason)
433429
})
434430
}

‎crates/ui/src/admin/lists.rs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::{Action, Change, UserRow, account_status, confirm, moment, refused_ac
44
use crate::{
55
clients::copyable,
66
icons::{Icon, icon},
7-
layout::{Pager, Who, avatar, page_head, pager},
7+
layout::{Pager, Who, alert_notice, avatar, page_head, pager},
88
};
99
use chrono::{DateTime, Utc};
1010
use sourceorigin_common::{
@@ -121,9 +121,7 @@ pub async fn grant_search<'a>(
121121
};
122122
Ok(view! {
123123
page_head(title: change.title(), lead: change.description().to_owned())
124-
if let Some(refusal) = refusal {
125-
<p class="notice error" role="alert">(refusal)</p>
126-
}
124+
alert_notice(message: refusal)
127125
<form class="row search" method="get" action=(action) role="search">
128126
<label class="search-box grow">
129127
icon(kind: Icon::Search)

‎crates/ui/src/admin/mod.rs‎

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use crate::{
6666
icons::{Icon, icon},
6767
layout::{
6868
Crumb, Destination, Health, Label, NavGroup, NavItem, Policies, Preferences, Search,
69-
SearchPage, Searchable, Shell, Shortcut, Spot, Who, page_head, shell,
69+
SearchPage, Searchable, Shell, Shortcut, Spot, Who, alert_notice, page_head, shell,
7070
},
7171
settings::{Tab as SettingsTab, settings_tabs},
7272
};
@@ -443,7 +443,7 @@ pub async fn dashboard_frame<'a>(
443443
// What the change is, and what it acts on, which the dashboard's
444444
// script writes from the link or form that opened the dialog.
445445
<p data-confirming="" data-default=(confirmation.target.map(Target::text)) hidden=""><strong></strong></p>
446-
<p class="notice error" role="alert" data-passkey-error="" hidden=""></p>
446+
alert_notice(passkey: true)
447447
<div class="row actions">
448448
<button type="button" data-passkey-confirm="" autofocus="">"Confirm with a passkey"</button>
449449
<button type="button" class="secondary" popovertarget="passkey-confirmation" popovertargetaction="hide">"Cancel"</button>
@@ -931,9 +931,7 @@ pub async fn dashboard_change<'a>(
931931
let confirming = change.confirming(named.as_deref());
932932
Ok(view! {
933933
page_head(title: change.title(), lead: change.description().to_owned())
934-
if let Some(refusal) = refusal {
935-
<p class="notice error" role="alert">(refusal)</p>
936-
}
934+
alert_notice(message: refusal)
937935
<section class="card">
938936
<form class="stack" method="post" data-submit-once="" data-unconfirmed=(!change.confirms()) data-confirming=(confirming.as_str())>
939937
(child)
@@ -1067,9 +1065,7 @@ pub async fn account_settings<'a>(
10671065
lead: account.and_then(|account| account.id).map(str::to_owned),
10681066
)
10691067
settings_tabs(tabs: tabs, current: current)
1070-
if let Some(refusal) = refusal {
1071-
<p class="notice error" role="alert">(refusal)</p>
1072-
}
1068+
alert_notice(message: refusal)
10731069
(child)
10741070
})
10751071
}
@@ -1170,9 +1166,7 @@ pub async fn handoff_proof<'a>(
11701166
<h1>"Confirm it's you"</h1>
11711167
<p class="lead">"The admin dashboard needs your passkey to sign you in or make a change. It counts for the dashboard only."</p>
11721168
</div>
1173-
if let Some(alert) = alert {
1174-
<p class="notice error" role="alert">(alert)</p>
1175-
}
1169+
alert_notice(message: alert)
11761170
<form
11771171
class="stack"
11781172
method="post"
@@ -1182,9 +1176,52 @@ pub async fn handoff_proof<'a>(
11821176
<input type="hidden" name="state" value=(query.state.as_str())>
11831177
<input type="hidden" name="return_to" value=(query.return_to.as_str())>
11841178
<input type="hidden" name="assertion" value="">
1185-
<p class="notice error" role="alert" data-passkey-error="" hidden=""></p>
1179+
alert_notice(passkey: true)
11861180
<p class="help" data-unavailable="">"Confirming needs a browser that supports passkeys, with scripts allowed."</p>
11871181
<button disabled="">"Confirm with a passkey"</button>
11881182
</form>
11891183
})
11901184
}
1185+
1186+
#[cfg(test)]
1187+
mod tests {
1188+
use super::{HandoffQuery, handoff_proof};
1189+
use topcoat::{
1190+
context::Cx,
1191+
view::{ViewExt, view},
1192+
};
1193+
1194+
/// A refused proof, and the placeholder the passkey script says a failed
1195+
/// ceremony in, are error notices with their warning icon and text.
1196+
#[tokio::test]
1197+
async fn the_handoff_says_errors_with_their_icon() {
1198+
let query = HandoffQuery {
1199+
state: "state".to_owned(),
1200+
return_to: "/".to_owned(),
1201+
};
1202+
let cx = Cx::default();
1203+
let page = view! { cx =>
1204+
handoff_proof(action: "/proof", proof: "/ceremony", query: &query, alert: "The passkey was refused.")
1205+
}
1206+
.single()
1207+
.await
1208+
.expect("the handoff")
1209+
.render(&cx);
1210+
let notices = page
1211+
.split(r#"<p class="notice error""#)
1212+
.skip(1)
1213+
.collect::<Vec<_>>();
1214+
assert_eq!(notices.len(), 2, "{page}");
1215+
for notice in notices
1216+
.into_iter()
1217+
.filter_map(|notice| notice.split("</p>").next())
1218+
{
1219+
assert!(notice.contains(r#"<svg class="icon""#), "{page}");
1220+
assert!(notice.contains(r#"<span class="text">"#), "{page}");
1221+
}
1222+
assert!(
1223+
page.contains(r#"<span class="text">The passkey was refused.</span>"#),
1224+
"{page}"
1225+
);
1226+
}
1227+
}

0 commit comments

Comments
 (0)