Skip to content

Commit 0eed64a

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/telemetry-privacy-cli
2 parents 5a65b59 + 61746a9 commit 0eed64a

27 files changed

Lines changed: 531 additions & 167 deletions

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

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
* unless it is marked `data-unconfirmed`, as a change that needs no
1515
* confirmation, such as writing a draft announcement, is; a button of it marked
1616
* `data-confirms`, such as the draft's "Send", still asks.
17+
* The dialog names what it confirms, from the link's or form's `data-confirming`:
18+
* the change, and what it acts on, so two pages left open are told apart. One
19+
* that names nothing gets the dialog's `data-default`, what the page acts on.
20+
* A form marked `data-submit-once` posts once: a double click sends nothing more,
21+
* so a change, or a link or secret shown only once, is not lost to it. A page
22+
* the browser restores from its back/forward cache may post it again.
1723
* The dialog's `data-passkey-confirm` button runs the passkey ceremony for the
1824
* dashboard's origin, which auth lists as a related origin of its RP ID: the
1925
* dialog's `data-confirmation-start` starts it, and its `data-confirmation-finish`
@@ -90,7 +96,14 @@ function wire(document) {
9096
const dialog = document.getElementById('passkey-confirmation');
9197
const button = dialog?.querySelector('button[data-passkey-confirm]');
9298
const alert = dialog?.querySelector('[data-passkey-error]');
93-
if (!dialog || !(button instanceof HTMLButtonElement) || !(alert instanceof HTMLElement)) return;
99+
const confirming = dialog?.querySelector('[data-confirming]');
100+
if (
101+
!dialog ||
102+
!(button instanceof HTMLButtonElement) ||
103+
!(alert instanceof HTMLElement) ||
104+
!(confirming instanceof HTMLElement)
105+
)
106+
return;
94107
const { confirmationStart: start = '', confirmationFinish: finish = '' } = dialog.dataset;
95108
/** When the confirmation ends, on `performance.now()`'s clock. */
96109
const ends = performance.now() + Number(dialog.dataset.confirmedFor ?? 0) * 1000;
@@ -144,15 +157,21 @@ function wire(document) {
144157
});
145158
};
146159
/**
147-
* Opens the dialog for the change `then` makes once confirmed. Answers whether
148-
* it opened: where it cannot confirm, the change goes on as it is.
160+
* Opens the dialog for the change `then` makes once confirmed, which `what`
161+
* names, if anything does. Answers whether it opened: where it cannot confirm,
162+
* the change goes on as it is.
149163
* @param {() => void} then
164+
* @param {string | undefined} what
150165
* @returns {boolean}
151166
*/
152-
const confirm = (then) => {
167+
const confirm = (then, what) => {
153168
if (!usable) return false;
154169
change = { then, started: post(start) };
155170
unlessStarted(change);
171+
const named = confirming.firstElementChild;
172+
const text = what ?? confirming.dataset.default;
173+
if (named) named.textContent = text ?? '';
174+
confirming.hidden = !text;
156175
alert.hidden = true;
157176
busy(false);
158177
dialog.showPopover();
@@ -212,27 +231,50 @@ function wire(document) {
212231
if (!link || !plain || confirmed(formTime)) return;
213232
const opened = confirm(() => {
214233
window.location.assign(link.href);
215-
});
234+
}, link.dataset.confirming);
216235
if (opened) event.preventDefault();
217236
});
237+
/**
238+
* Lets `form` post once, if it is marked `data-submit-once`: a later submit of
239+
* it is dropped.
240+
* @param {SubmitEvent} event
241+
* @param {HTMLFormElement} form
242+
*/
243+
const once = (event, form) => {
244+
if (!form.hasAttribute('data-submit-once')) return;
245+
if (form.dataset.submitted) event.preventDefault();
246+
else form.dataset.submitted = 'true';
247+
};
248+
// A page the browser restores from its back/forward cache posts again.
249+
window.addEventListener('pageshow', (event) => {
250+
if (!event.persisted) return;
251+
for (const form of document.querySelectorAll('form[data-submitted]')) {
252+
if (form instanceof HTMLFormElement) delete form.dataset.submitted;
253+
}
254+
});
218255
document.addEventListener('submit', (event) => {
219256
const form = event.target;
220257
if (!(form instanceof HTMLFormElement) || form.method !== 'post') return;
221258
if (form === confirmedForm) {
222259
confirmedForm = undefined;
260+
once(/** @type {SubmitEvent} */ (event), form);
223261
return;
224262
}
225263
const submitter = event.submitter;
226264
const unconfirmed =
227265
form.hasAttribute('data-unconfirmed') && !submitter?.hasAttribute('data-confirms');
228-
if (!form.closest('main') || unconfirmed || confirmed(0)) return;
229-
const opened = confirm(() => {
230-
// Its submit event runs within the call, or not at all if it is invalid.
231-
confirmedForm = form;
232-
form.requestSubmit(submitter);
233-
confirmedForm = undefined;
234-
});
266+
const opened =
267+
!!form.closest('main') &&
268+
!unconfirmed &&
269+
!confirmed(0) &&
270+
confirm(() => {
271+
// Its submit event runs within the call, or not at all if it is invalid.
272+
confirmedForm = form;
273+
form.requestSubmit(submitter);
274+
confirmedForm = undefined;
275+
}, form.dataset.confirming);
235276
if (opened) event.preventDefault();
277+
else once(/** @type {SubmitEvent} */ (event), form);
236278
});
237279
}
238280

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,24 +310,21 @@ impl AdminService {
310310
Self::finish(tx, operator, Some(user_id), vec![]).await
311311
}
312312

313-
/// Ends one active session and the refresh grants issued from it.
313+
/// Ends `user_id`'s active session `session_id` and the refresh grants issued
314+
/// from it. Another account's session is not found: the caller names the
315+
/// account it means to sign out, as its page or command shows it.
314316
pub(crate) async fn revoke_session(
315317
&self,
316318
operator: &Operator,
319+
user_id: UserId,
317320
session_id: SessionId,
318321
) -> Result<(), AdminError> {
319322
let mut tx = self.database.begin().await?;
320-
// The owner never changes, so it can be read before taking the account lock.
321-
let session = tx
322-
.sessions()
323-
.find_by_id(session_id)
324-
.await?
325-
.ok_or(AdminError::SessionNotFound)?;
326-
operator.lock(&mut tx, session.user_id).await?;
323+
operator.lock(&mut tx, user_id).await?;
327324
if tx
328325
.revoke_sessions(
329326
&operator.context(),
330-
session.user_id,
327+
user_id,
331328
SessionScope::One(session_id),
332329
&RevocationReason::Admin,
333330
)
@@ -336,7 +333,7 @@ impl AdminService {
336333
{
337334
return Err(AdminError::SessionNotFound);
338335
}
339-
Self::finish(tx, operator, Some(session.user_id), vec![]).await
336+
Self::finish(tx, operator, Some(user_id), vec![]).await
340337
}
341338

342339
/// Lists the accounts whose current handle is reserved, by the handle rules or

‎apps/auth-service/src/cli/session.rs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ use sourceorigin_common::SessionId;
88
/// Ending sessions, with the refresh tokens their applications hold.
99
#[derive(Subcommand)]
1010
pub(super) enum SessionCommand {
11-
/// End one session and its applications' refresh tokens.
11+
/// End one session of an account and its applications' refresh tokens.
1212
Revoke {
13-
/// The session's ID, as `user show` lists it.
13+
/// The account: its handle, ID or verified email.
14+
user: UserRef,
15+
/// The session's ID, as `user show` lists it. Another account's session is
16+
/// not found.
1417
session: SessionId,
1518
},
1619
/// End every session of an account and its applications' refresh tokens.
@@ -30,7 +33,10 @@ impl SessionCommand {
3033
service, operator, ..
3134
} = console;
3235
match self {
33-
Self::Revoke { session } => service.revoke_session(operator, session).await?,
36+
Self::Revoke { user, session } => {
37+
let id = console.user(&user).await?;
38+
service.revoke_session(operator, id, session).await?;
39+
}
3440
Self::RevokeAll { user, confirm } => {
3541
let id = console.user(&user).await?;
3642
confirm.ask(&format!("Sign {user} ({id}) out everywhere"))?;

‎apps/auth-service/src/cli/tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl AdminOperation {
3838
"Spam account",
3939
],
4040
Self::RevokeUserSessions => &["session", "revoke-all", "alice"],
41-
Self::RevokeSession => &["session", "revoke", AN_ID],
41+
Self::RevokeSession => &["session", "revoke", "alice", AN_ID],
4242
Self::ListInvitations => &["invite", "list"],
4343
Self::CreateInvitation => &["invite", "create"],
4444
Self::RevokeInvitation => &["invite", "revoke", AN_ID],

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ pub(super) async fn revoke(cx: &Cx, form: Option<Form<IgnoredAny>>) -> Result<Re
121121
service.revoke_administrator(&admin.operator, id)
122122
})
123123
.await?;
124+
let target = App::target(cx).await;
124125
let page = view! { cx =>
125126
sourceorigin_ui::dashboard_change(
126127
change: Change::RevokeAdministrator,
128+
target: target,
127129
back: back.as_str(),
128130
refusal: refusal.as_deref(),
129131
)

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use sourceorigin_common::{
88
AlertId,
99
alerts::{AlertStatus, AlertsShown},
1010
};
11-
use sourceorigin_ui::{Action, AlertCard, Change};
11+
use sourceorigin_ui::{Action, AlertCard, Change, Target};
1212
use topcoat::{
1313
Result,
1414
context::Cx,
@@ -115,12 +115,17 @@ pub(super) async fn update(cx: &Cx, form: Option<Form<UpdateForm>>) -> Result<Re
115115
(Some(refused.form.status), refused.form.note.as_str())
116116
});
117117
let refusal = refused.as_deref();
118+
let shown = id.to_string();
119+
let target = Target {
120+
name: subject,
121+
id: Some(&shown),
122+
};
118123
let page = view! { cx =>
119124
sourceorigin_ui::dashboard_change(
120125
change: Change::UpdateAlert,
126+
target: target,
121127
back: back.as_str(),
122128
refusal: refusal,
123-
<p><strong>(subject)</strong></p>
124129
sourceorigin_ui::alert_update_fields(status: status, note: note)
125130
)
126131
};

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use sourceorigin_common::{
1717
};
1818
use sourceorigin_ui::{
1919
Action, AdminAnnouncementRow, Change, Checkbox, Crumb, DraftActions, FoundAccount, Query,
20+
Target,
2021
};
2122
use topcoat::{
2223
Error, Result,
@@ -167,9 +168,15 @@ pub(super) async fn send(cx: &Cx, form: Option<Form<SendAnnouncement>>) -> Resul
167168
};
168169
let mailed = &format!("{} {}", detail.mailed, announcement.emailed());
169170
let revision = &checked.revision.to_string();
171+
let shown = id.to_string();
172+
let target = Target {
173+
name: &announcement.subject,
174+
id: Some(&shown),
175+
};
170176
let page = view! { cx =>
171177
sourceorigin_ui::dashboard_change(
172178
change: Change::SendAnnouncement,
179+
target: target,
173180
back: back.as_str(),
174181
refusal: refusal.as_deref(),
175182
<dl class="facts">
@@ -195,9 +202,15 @@ pub(super) async fn discard(cx: &Cx, form: Option<Form<IgnoredAny>>) -> Result<R
195202
})
196203
.await?;
197204
let back = &href!(show, Announcement(id)).resolve(cx);
205+
let shown = id.to_string();
206+
let target = Target {
207+
name: "Draft",
208+
id: Some(&shown),
209+
};
198210
let page = view! { cx =>
199211
sourceorigin_ui::dashboard_change(
200212
change: Change::DiscardAnnouncement,
213+
target: target,
201214
back: back.as_str(),
202215
refusal: refusal.as_deref(),
203216
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,13 @@ impl Toggle {
356356
let refusal =
357357
App::submit(cx, form, done, |_| self.make(service, &admin.operator, &id)).await?;
358358
let change = self.change();
359-
let which = format!("Client {id}.");
359+
let target = App::target(cx).await;
360360
let page = view! { cx =>
361361
sourceorigin_ui::dashboard_change(
362362
change: change,
363+
target: target,
363364
back: back.as_str(),
364365
refusal: refusal.as_deref(),
365-
<p class="help">(which.as_str())</p>
366366
)
367367
};
368368
App::render(cx, StatusCode::OK, change.title(), page).await

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::AdminApplication as App;
44
use serde::de::IgnoredAny;
55
use sourceorigin_common::{DeliveryId, admin::DeliveryStatus};
6-
use sourceorigin_ui::{Action, Change, DeliveryRow};
6+
use sourceorigin_ui::{Action, Change, DeliveryRow, Target};
77
use topcoat::{
88
Result,
99
context::Cx,
@@ -115,9 +115,15 @@ impl App {
115115
}
116116
})
117117
.await?;
118+
let id = id.to_string();
119+
let target = Target {
120+
name: "Delivery",
121+
id: Some(&id),
122+
};
118123
let page = view! { cx =>
119124
sourceorigin_ui::dashboard_change(
120125
change: change,
126+
target: target,
121127
back: back.as_str(),
122128
refusal: refusal.as_deref(),
123129
)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{Reason, handles::HandlesError};
66
use serde::{Deserialize, Serialize, de::IgnoredAny};
77
use sourceorigin_common::{Handle, handle::RESERVED};
88
use sourceorigin_ui::{
9-
Action, Change, HandlesPage, Query, ReleasedRow, ReservationRow, ReservedHolder,
9+
Action, Change, HandlesPage, Query, ReleasedRow, ReservationRow, ReservedHolder, Target,
1010
};
1111
use topcoat::{
1212
Result,
@@ -156,6 +156,10 @@ impl App {
156156
let handle = query_params::<HandleQuery>(cx)?.handle.clone();
157157
let back = href!(check).resolve(cx);
158158
let shown = format!("@{handle}");
159+
let target = Target {
160+
name: &shown,
161+
id: None,
162+
};
159163
let refusal = Self::submit(cx, form, back.clone(), |_| async move {
160164
if change == Change::ReleaseHandle {
161165
service.release_handle(&admin.operator, handle).await
@@ -167,9 +171,9 @@ impl App {
167171
let page = view! { cx =>
168172
sourceorigin_ui::dashboard_change(
169173
change: change,
174+
target: target,
170175
back: back.as_str(),
171176
refusal: refusal.as_deref(),
172-
<p><strong>(shown.as_str())</strong></p>
173177
)
174178
};
175179
Self::render(cx, StatusCode::OK, change.title(), page).await

0 commit comments

Comments
 (0)