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 <noreply@anthropic.com>
This commit is contained in:
parent
6a797cb3fa
commit
c9387a255d
2 changed files with 11 additions and 6 deletions
|
|
@ -16,7 +16,7 @@ public abstract record ConsentState
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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 ? "" : $"""<div id="errors" role="alert" tabindex="-1"><strong>That did not go through.</strong><p>{E(error)}</p></div>""";
|
||||
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
|
||||
? """<form method="post" action="/auth/bifrost/consent/withdraw"><button type="submit">Withdraw</button></form>"""
|
||||
: "";
|
||||
var agreeButton = state is ConsentState.Current
|
||||
? ""
|
||||
: $"""<form method="post" action="/auth/bifrost/consent/accept"><input type="hidden" name="version" value="{version}" /><button type="submit">Agree to version {version}</button></form>""";
|
||||
var button = agreeButton + withdrawButton;
|
||||
|
||||
return $$"""
|
||||
<!doctype html>
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in a new issue