From a1e453524459b97ddb87f954058dcea42b26c813 Mon Sep 17 00:00:00 2001 From: piquel Date: Fri, 20 Nov 2026 09:46:08 +0100 Subject: [PATCH 1/2] fix(admin): the dashboard offers Resend on an invitation only while email is on The invitations page offered Resend on every open, mailed invitation, though the service refuses to mail one while email is off, after the operator has written a reason. The page now asks AdminService whether it mails, and the service keeps its own refusal. Closes #556 --- apps/auth-service/src/admin/service/mod.rs | 7 ++++ .../auth-service/src/web/admin/invitations.rs | 9 +++-- apps/auth-service/src/web/admin/tests/mod.rs | 5 +-- .../src/web/admin/tests/operations.rs | 35 +++++++++++++++++++ docs/dev/operations/administration.md | 5 +-- 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/apps/auth-service/src/admin/service/mod.rs b/apps/auth-service/src/admin/service/mod.rs index bbb53a9e3..376d41ff9 100644 --- a/apps/auth-service/src/admin/service/mod.rs +++ b/apps/auth-service/src/admin/service/mod.rs @@ -58,6 +58,13 @@ impl AdminService { Self { database, mails } } + /// Whether email is enabled, so an invitation can be mailed again: pages + /// offer a resend only while it is. + #[must_use] + pub(crate) const fn mails(&self) -> bool { + self.mails + } + /// Ends every mutation: rechecks `operator`, records `events` about `subject` /// with their `reason`, then commits. Every mutation ends here, so none /// commits without a reason. The check runs after the mutation's last write, diff --git a/apps/auth-service/src/web/admin/invitations.rs b/apps/auth-service/src/web/admin/invitations.rs index 89cedf030..e42a40794 100644 --- a/apps/auth-service/src/web/admin/invitations.rs +++ b/apps/auth-service/src/web/admin/invitations.rs @@ -20,7 +20,7 @@ use topcoat::{ path_param!(pub invitation: TokenId, error = not_found); /// `/invitations`: signup invitations, newest first, with the changes each -/// open one takes. +/// open one takes: a mailed one is resent only while email is on. #[route(GET "/invitations")] pub(super) async fn list(cx: &Cx) -> Result { let admin = App::admin(cx).await?; @@ -34,8 +34,11 @@ pub(super) async fn list(cx: &Cx) -> Result { let action = |href: String| Action { href, inline }; InvitationRow { invitation, - resend: (open && invitation.expires_at > now && invitation.email.is_some()) - .then(|| action(href!(resend, Invitation(invitation.id)).resolve(cx))), + resend: (open + && invitation.expires_at > now + && invitation.email.is_some() + && app.service.mails()) + .then(|| action(href!(resend, Invitation(invitation.id)).resolve(cx))), revoke: open.then(|| action(href!(revoke, Invitation(invitation.id)).resolve(cx))), } }) diff --git a/apps/auth-service/src/web/admin/tests/mod.rs b/apps/auth-service/src/web/admin/tests/mod.rs index 12f621edb..46c043790 100644 --- a/apps/auth-service/src/web/admin/tests/mod.rs +++ b/apps/auth-service/src/web/admin/tests/mod.rs @@ -3,7 +3,7 @@ use super::{AdminApplication, Attention, AttentionCache}; use crate::{ - AdminError, AdminService, AuthConfig, DashboardConfig, Reason, + AdminError, AdminService, AuthConfig, DashboardConfig, InviteExpiry, Reason, account::AccountService, admin::DashboardSignIn, assets::EmbeddedAssets, @@ -22,8 +22,9 @@ use axum::{ }; use chrono::{DateTime, Utc}; use sourceorigin_common::{ - AccountStatus, AuthenticationMethod, Handle, PictureId, UserId, + AccountStatus, AuthenticationMethod, Handle, PictureId, TokenId, UserId, admin::EventSearch, + email::NormalizedEmail, events::{Actor, DomainEvent}, notifications::Notification, }; diff --git a/apps/auth-service/src/web/admin/tests/operations.rs b/apps/auth-service/src/web/admin/tests/operations.rs index 6a8208f3e..b7c0cc039 100644 --- a/apps/auth-service/src/web/admin/tests/operations.rs +++ b/apps/auth-service/src/web/admin/tests/operations.rs @@ -56,6 +56,41 @@ async fn an_invitations_link_shows_once() { ); } +/// Without email, the dashboard offers no mailing the service would refuse: a +/// mailed invitation can be revoked but not resent, and a new one asks for no +/// address, only how long its link lasts. +#[tokio::test] +#[ignore = "requires TEST_DATABASE_URL"] +async fn invitations_offer_mailing_only_while_email_is_on() { + let mut config = AuthConfig::test(&AUTH_ORIGIN.parse().expect("auth origin")); + config.email.smtp = None; + let harness = Harness::of(config).await; + // Unique, since other scenarios share the database. + let jane = format!("jane-{}@example.com", TokenId::new()); + // Mailed while email was on. + let invitation = AdminService::new(harness.database.clone(), true) + .create_invitation( + &operator(), + &crate::tests::invitation_links(), + InviteExpiry::default(), + Some(NormalizedEmail::parse(&jane).expect("address")), + reason(), + ) + .await + .expect("invitation"); + let admin = harness.admin().await; + let dashboard = harness + .confirmed(&admin, "/invitations/new", Utc::now()) + .await; + let page = html(harness.visit(&dashboard, "/invitations").await).await; + let actions = format!("/invitations/{}", invitation.id); + assert!(page.contains(&format!("{actions}/revoke")), "{page}"); + assert!(!page.contains(&format!("{actions}/resend")), "{page}"); + let form = html(harness.visit(&dashboard, "/invitations/new").await).await; + assert!(form.contains(r#"name="expires_in""#), "{form}"); + assert!(!form.contains(r#"name="email""#), "{form}"); +} + sourceorigin_repository::test_channels! { /// A delivery no worker sends, which the dashboard's tests list, cancel and retry. Unsent = "test_dashboard_unsent": () => (); diff --git a/docs/dev/operations/administration.md b/docs/dev/operations/administration.md index 1e41a5fc5..4078e3acf 100644 --- a/docs/dev/operations/administration.md +++ b/docs/dev/operations/administration.md @@ -122,8 +122,9 @@ Its link stops working at once. signs in instead. - If another account confirms the address before the person signs up, the new account starts without it. -- Only a mailed invitation can be sent again, and not to an address an account - has confirmed since. +- Only a mailed invitation can be sent again, and only while email is enabled: + the dashboard offers **Resend** only then. It can't go to an address an + account has confirmed since. - Where signup is open, a signup that starts at GitHub or Google doesn't carry the invitation: the account is created without it, and without its address. From 27a848459e42cfe2c43ca2fd77f23e888c5a6ce6 Mon Sep 17 00:00:00 2001 From: piquel Date: Fri, 20 Nov 2026 09:58:48 +0100 Subject: [PATCH 2/2] fix(admin): the new-invitation form asks for an address only while email is on The form offered the Email address field while email was off, though the service refuses a mailed invitation then, after the operator has written a reason. The service keeps its own refusal. Refs #556 --- apps/auth-service/src/admin/service/mod.rs | 4 ++-- apps/auth-service/src/web/admin/invitations.rs | 15 +++++++++------ docs/dev/operations/administration.md | 6 +++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/apps/auth-service/src/admin/service/mod.rs b/apps/auth-service/src/admin/service/mod.rs index 376d41ff9..d5fb44bf1 100644 --- a/apps/auth-service/src/admin/service/mod.rs +++ b/apps/auth-service/src/admin/service/mod.rs @@ -58,8 +58,8 @@ impl AdminService { Self { database, mails } } - /// Whether email is enabled, so an invitation can be mailed again: pages - /// offer a resend only while it is. + /// Whether email is enabled, so an invitation can be mailed: pages offer to + /// mail or resend one only while it is. #[must_use] pub(crate) const fn mails(&self) -> bool { self.mails diff --git a/apps/auth-service/src/web/admin/invitations.rs b/apps/auth-service/src/web/admin/invitations.rs index e42a40794..a62c6ca93 100644 --- a/apps/auth-service/src/web/admin/invitations.rs +++ b/apps/auth-service/src/web/admin/invitations.rs @@ -57,7 +57,7 @@ pub(super) async fn list(cx: &Cx) -> Result { /// `/invitations/new`: creates an invitation, mailed to the address given or /// shown to pass on, then comes back here, which shows its link once, or where -/// it was mailed. +/// it was mailed. The form asks for an address only while email is on. #[route([GET, POST] "/invitations/new")] pub(super) async fn create(cx: &Cx, form: Option>) -> Result { let admin = App::admin(cx).await?; @@ -108,6 +108,7 @@ pub(super) async fn create(cx: &Cx, form: Option>) -> Res ) }); let (created, refused) = (&created, refused.as_deref()); + let mails = app.service.mails(); let page = view! { cx => match created { Some(created) => { @@ -123,11 +124,13 @@ pub(super) async fn create(cx: &Cx, form: Option>) -> Res back: back.as_str(), refusal: refused, reason: reason, - + if mails { + + }