From c9387a255d7654be47cabb1d7fb8fac69e91e9e8 Mon Sep 17 00:00:00 2001 From: Heimdall Date: Wed, 11 Nov 2026 11:33:51 +0000 Subject: [PATCH] Consent page: Withdraw whenever any live receipt exists, Agree whenever none is live for the version in force An account on an older receipt sees both buttons. Co-Authored-By: Claude Sonnet 5.5 --- .../Features/Registration/ConsentPage.cs | 13 +++++++++---- tests/Bifrost.Web.Tests/ConsentTests.cs | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Bifrost.Web/Features/Registration/ConsentPage.cs b/src/Bifrost.Web/Features/Registration/ConsentPage.cs index 306b014..2e7595c 100644 --- a/src/Bifrost.Web/Features/Registration/ConsentPage.cs +++ b/src/Bifrost.Web/Features/Registration/ConsentPage.cs @@ -16,7 +16,7 @@ public abstract record ConsentState } /// -/// The server-rendered consent page: the notice in force, the account's state and the one button that applies. No script, +/// The server-rendered consent page: the notice in force, the account's state and the buttons that apply. No script, /// no external asset, no cookie of its own. /// public static class ConsentPage @@ -46,17 +46,22 @@ public static class ConsentPage { static string E(string? text) => WebUtility.HtmlEncode(text ?? ""); var version = TrainingNotice.Version.ToString(System.Globalization.CultureInfo.InvariantCulture); - var (message, withdraw) = state switch + var (message, anyLive) = state switch { ConsentState.Current current => ($"You agreed to version {version} on {Iso(current.AgreedAtUtc)}. Your messages may be used as the notice says.", true), - ConsentState.Older older => ($"You agreed to version {older.Version} on {Iso(older.AgreedAtUtc)}; version {version} is in force and your messages are not used until you agree to it.", false), + ConsentState.Older older => ($"You agreed to version {older.Version} on {Iso(older.AgreedAtUtc)}; version {version} is in force and your messages are not used until you agree to it.", true), ConsentState.Withdrawn withdrawn => ($"You withdrew on {Iso(withdrawn.WithdrawnAtUtc)}. Your messages are not used.", false), _ => ("You have not agreed. Your messages are not used.", false) }; var summary = error is null ? "" : $""""""; - var button = withdraw + // Withdraw whenever any live receipt exists (an older one included); Agree whenever none is live for the version in force. + var withdrawButton = anyLive ? """
""" + : ""; + var agreeButton = state is ConsentState.Current + ? "" : $"""
"""; + var button = agreeButton + withdrawButton; return $$""" diff --git a/tests/Bifrost.Web.Tests/ConsentTests.cs b/tests/Bifrost.Web.Tests/ConsentTests.cs index e6b55cc..ff3a627 100644 --- a/tests/Bifrost.Web.Tests/ConsentTests.cs +++ b/tests/Bifrost.Web.Tests/ConsentTests.cs @@ -148,7 +148,7 @@ public sealed class ConsentTests(RegistrationGateFactory factory) : IClassFixtur } [Fact] - public async Task Agreement_to_an_older_version_says_it_no_longer_counts_and_offers_agree() + public async Task Agreement_to_an_older_version_says_it_no_longer_counts_and_offers_both_agree_and_withdraw() { var identity = NewIdentity(); Seed(identity, (1, Agreed, null)); @@ -156,7 +156,7 @@ public sealed class ConsentTests(RegistrationGateFactory factory) : IClassFixtur Assert.Contains($"You agreed to version 1 on 2026-11-01T12:30:05Z; version {TrainingNotice.Version} is in force and your messages are not used until you agree to it", html); Assert.Contains("action=\"/auth/bifrost/consent/accept\"", html); - Assert.DoesNotContain("/consent/withdraw", html); + Assert.Contains("action=\"/auth/bifrost/consent/withdraw\"", html); } [Fact]