Privacy notice: built-in text up to date, review flow, acceptance (1.48.1)

The built-in notice now covers volunteer rosters, event series, season
passes, webhooks, how people agree to it, and the provider-notices
storage item. Sites with their own published version see what changed
in the editor (sections marked, use new text per section or all, add
missing sections, "Done - hide this"). Account activation asks for
agreement to the terms and notice; anyone who never accepted is asked
once after login. The cookie button shows above any cookie section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 13:15:57 +02:00
co-authored by Claude Opus 5.5
parent aa79168660
commit adb6e11000
27 changed files with 368 additions and 44 deletions
@@ -28,7 +28,7 @@ type ParentalRow = { id: string; at: string | null; child: string; event: string
type LogResponse<T> = { rows: T[]; total: number; pageSize: number };
const SOURCE: Record<string, string> = {
signup: "Sign-up", privacy_centre: "Privacy page", prompt: "Asked after login", unsubscribe_link: "Unsubscribe link",
signup: "Sign-up", activation: "Account activation", privacy_centre: "Privacy page", prompt: "Asked after login", unsubscribe_link: "Unsubscribe link",
whatsapp_stop: "Replied STOP", existing_account: "Existing account (1.38.0)", admin: "Administrator",
};
@@ -2,13 +2,15 @@
import React, { useCallback, useEffect, useState } from "react";
import Link from "next/link";
import { ArrowUp, ArrowDown, Trash2, Plus, RotateCcw, Eye, PencilLine } from "lucide-react";
import { ArrowUp, ArrowDown, Trash2, Plus, RotateCcw, Eye, PencilLine, Sparkles } from "lucide-react";
import { apiFetch } from "@/lib/api";
import { errorMessage } from "@/lib/utils";
import { PrivacyNoticeSection, type NoticeSection } from "@/components/shared/PrivacyNoticeSection";
type Version = { version: number; publishedAt: string; changeSummary: string | null; requiresAcceptance: boolean; publishedBy: string | null; acceptances: number };
type Draft = { sections: NoticeSection[]; rendered: NoticeSection[]; isDraft: boolean; savedAt: string | null; versions: Version[]; builtIn: NoticeSection[] };
// Changes to the built-in text since this site last reviewed them (only once it has published its own).
type BuiltInUpdate = { revision: string; summary: string[]; sections: string[] };
type Draft = { sections: NoticeSection[]; rendered: NoticeSection[]; isDraft: boolean; savedAt: string | null; versions: Version[]; builtIn: NoticeSection[]; builtInUpdates?: BuiltInUpdate[] };
type Msg = { type: "ok" | "err"; text: string } | null;
const PLACEHOLDER_HELP: [string, string][] = [
@@ -106,10 +108,45 @@ export function NoticeEditor({ token }: { token: string }) {
}
};
// The built-in text changed since this site last looked: hide the list once the admin has been through it.
const markReviewed = async () => {
setBusy(true);
try {
await apiFetch("/api/privacy/notice/builtin-reviewed", { method: "POST", authToken: token });
setDraft(d => (d ? { ...d, builtInUpdates: [] } : d));
setMsg({ type: "ok", text: "Done. Remember to save the draft and publish if you took any new text." });
} catch (e) {
setMsg({ type: "err", text: errorMessage(e) || "Could not save." });
} finally {
setBusy(false);
}
};
if (!draft) return msg ? <p className="text-sm text-red-700">{msg.text}</p> : <p className="text-sm text-gray-400">Loading…</p>;
const builtInById = new Map(draft.builtIn.map(s => [s.id, s]));
const current = draft.versions[0];
const updates = draft.builtInUpdates || [];
const updatedIds = new Set(updates.flatMap(u => u.sections));
const differs = (s: NoticeSection) => { const b = builtInById.get(s.id); return !!b && (b.body !== s.body || b.title !== s.title); };
// Built-in sections this notice doesn't have (removed, or new in the built-in text).
const missing = draft.builtIn.filter(b => !sections.some(s => s.id === b.id));
const pendingIds = sections.filter(s => updatedIds.has(s.id) && differs(s)).map(s => s.id);
/** Puts a built-in section back where it sits in the built-in text. */
const addBuiltIn = (b: NoticeSection) => {
const order = draft.builtIn.map(x => x.id);
const after = order.slice(0, order.indexOf(b.id)).reverse().find(id => sections.some(s => s.id === id));
const at = after ? sections.findIndex(s => s.id === after) + 1 : 0;
change([...sections.slice(0, at), { ...b }, ...sections.slice(at)]);
};
const useAllNew = () => {
if (!confirm("Replace every changed section with the new built-in text? Your own wording in those sections is replaced (other sections stay as they are). Nothing is public until you publish.")) return;
const next = sections.map(s => {
const b = updatedIds.has(s.id) ? builtInById.get(s.id) : undefined;
return b ? { ...b } : s;
});
change(next);
};
return (
<div className="space-y-5">
@@ -148,6 +185,24 @@ export function NoticeEditor({ token }: { token: string }) {
{dirty && <span className="self-center text-xs text-amber-700">Unsaved changes</span>}
</div>
{updates.length > 0 && (
<div className="border border-amber-200 bg-amber-50 rounded-xl p-4 text-sm text-amber-900 space-y-2" data-testid="builtin-updates">
<div className="flex items-center gap-2 font-medium"><Sparkles className="w-4 h-4" /> The built-in privacy notice has been updated</div>
<p>Your published notice keeps your own text, so the new wording from Cross Events {updates.map(u => u.revision).join(", ")} isn&apos;t in it yet:</p>
<ul className="list-disc pl-5">{updates.flatMap(u => u.summary).map((line, i) => <li key={i}>{line}</li>)}</ul>
<p>
{pendingIds.length > 0
? <>Sections with new text are marked below. Use the new text where you want it (it replaces your wording in that section), then save the draft and publish.</>
: <>Your draft already has the new text in every changed section. Save the draft and publish to make it live.</>}
{" "}Tick &quot;Significant change&quot; when publishing if people should accept it again.
</p>
<div className="flex flex-wrap gap-2">
{pendingIds.length > 0 && <button onClick={useAllNew} disabled={busy} className="px-3 py-1.5 rounded-lg bg-amber-600 text-white text-sm font-medium hover:bg-amber-700 disabled:opacity-50">Use all the new text</button>}
<button onClick={markReviewed} disabled={busy} className="px-3 py-1.5 rounded-lg border border-amber-300 bg-white text-sm hover:bg-amber-100 disabled:opacity-50">Done — hide this</button>
</div>
</div>
)}
{msg && <div className={`p-3 rounded-lg text-sm ${msg.type === "ok" ? "bg-green-50 text-green-800 border border-green-200" : "bg-red-50 text-red-800 border border-red-200"}`}>{msg.text}</div>}
{publishing && (
@@ -182,8 +237,9 @@ export function NoticeEditor({ token }: { token: string }) {
<div className="space-y-3">
{sections.map((s, i) => {
const original = builtInById.get(s.id);
const hasNew = updatedIds.has(s.id) && differs(s);
return (
<div key={`${s.id}-${i}`} className="border rounded-xl p-3 bg-white">
<div key={`${s.id}-${i}`} className={`border rounded-xl p-3 bg-white ${hasNew ? "border-amber-300" : ""}`} data-testid={hasNew ? "section-has-new-text" : undefined}>
<div className="flex items-center gap-2 mb-2">
<input className={`${inputCls} font-medium`} value={s.title} onChange={e => update(i, { title: e.target.value })} aria-label="Section title" />
<button onClick={() => move(i, -1)} disabled={i === 0} className="p-1.5 rounded hover:bg-gray-100 disabled:opacity-30" aria-label="Move up"><ArrowUp className="w-4 h-4" /></button>
@@ -194,9 +250,27 @@ export function NoticeEditor({ token }: { token: string }) {
<button onClick={() => confirm(`Remove "${s.title}"?`) && change(sections.filter((_, j) => j !== i))} className="p-1.5 rounded hover:bg-red-50 text-red-600" aria-label="Remove section"><Trash2 className="w-4 h-4" /></button>
</div>
<textarea className={`${inputCls} font-mono text-xs`} rows={Math.min(18, Math.max(3, s.body.split("\n").length + 1))} value={s.body} onChange={e => update(i, { body: e.target.value })} aria-label={`${s.title} text`} />
{hasNew && original && (
<details className="mt-2 text-xs">
<summary className="cursor-pointer text-amber-800 font-medium">New built-in text for this section — show it</summary>
<pre className="mt-2 whitespace-pre-wrap rounded-lg bg-amber-50 border border-amber-200 p-2 font-mono text-[11px] text-gray-700">{original.body}</pre>
<button onClick={() => update(i, { title: original.title, body: original.body })} className="mt-2 px-3 py-1.5 rounded-lg bg-amber-600 text-white hover:bg-amber-700">Use the new text</button>
</details>
)}
</div>
);
})}
{missing.length > 0 && (
<div className="border border-dashed rounded-xl p-3 text-sm text-gray-600 space-y-1">
<div className="font-medium text-gray-800">Built-in sections not in your notice</div>
{missing.map(b => (
<div key={b.id} className="flex items-center justify-between gap-2">
<span>{b.title}{updatedIds.has(b.id) && <span className="ml-1 text-xs text-amber-700">(new text)</span>}</span>
<button onClick={() => addBuiltIn(b)} className="inline-flex items-center gap-1 px-2 py-1 rounded border bg-white text-xs hover:bg-gray-50"><Plus className="w-3.5 h-3.5" /> Add</button>
</div>
))}
</div>
)}
<button onClick={() => change([...sections, { id: `section-${sections.length + 1}`, title: "New section", body: "" }])} className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border bg-white text-sm hover:bg-gray-50">
<Plus className="w-4 h-4" /> Add section
</button>
@@ -9,11 +9,12 @@ import { errorMessage } from "@/lib/utils";
import type { PublicNotice } from "@/components/shared/PrivacyNoticeSection";
/**
* POPIA: a privacy notice version marked as a significant change has been published, and
* this person accepted an older one. Asked once after login; it can't be waved away, but the
* notice and the Privacy page (to delete the account instead) stay reachable.
* POPIA: asked once after login when this person never accepted the privacy notice (an account
* made for them, or from before acceptances were recorded) — reason "first" — or a version marked
* as a significant change came out after the one they accepted ("updated"). It can't be waved
* away, but the notice and the Privacy page (to delete the account instead) stay reachable.
*/
export function NoticePrompt({ onDone }: { onDone: () => void }) {
export function NoticePrompt({ reason = "updated", onDone }: { reason?: "first" | "updated"; onDone: () => void }) {
const { token } = useAuth();
const [notice, setNotice] = useState<PublicNotice | null>(null);
const [saving, setSaving] = useState(false);
@@ -40,7 +41,7 @@ export function NoticePrompt({ onDone }: { onDone: () => void }) {
};
// The newest version that needed accepting, for "what changed".
const changes = notice.versions.find(v => v.requiresAcceptance)?.changeSummary || notice.changeSummary;
const changes = reason === "updated" ? notice.versions.find(v => v.requiresAcceptance)?.changeSummary || notice.changeSummary : null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4" role="dialog" aria-modal="true" aria-labelledby="notice-prompt-title">
@@ -49,7 +50,7 @@ export function NoticePrompt({ onDone }: { onDone: () => void }) {
<div className="w-9 h-9 rounded-lg flex items-center justify-center bg-brand-50 text-brand-600 shrink-0">
<ScrollText className="w-5 h-5" />
</div>
<h2 id="notice-prompt-title" className="text-lg font-semibold text-gray-900">We&apos;ve updated our privacy notice</h2>
<h2 id="notice-prompt-title" className="text-lg font-semibold text-gray-900">{reason === "first" ? "Our privacy notice" : <>We&apos;ve updated our privacy notice</>}</h2>
</div>
{changes && (
<div className="mb-3 p-3 rounded-lg bg-gray-50 border text-sm text-gray-700 whitespace-pre-line">
@@ -57,6 +58,7 @@ export function NoticePrompt({ onDone }: { onDone: () => void }) {
</div>
)}
<p className="text-sm text-gray-600 mb-5">
{reason === "first" && <>It explains what we keep about you and why, and your rights. </>}
Please read the <Link href="/legal/privacy" target="_blank" className="text-brand-600 hover:underline">privacy notice</Link> and
accept it to carry on using your account. If you don&apos;t agree, you can{" "}
<Link href="/dashboard/user/privacy" className="text-brand-600 hover:underline">delete your account</Link> instead.
@@ -42,7 +42,8 @@ export function PrivacyNoticeSection({ section, first = false }: { section: Noti
) : (
<h3 className="text-xl font-semibold text-brand-600 mb-3">{section.title}</h3>
)}
{section.id === "cookies" && (
{/* Above the cookie section: the built-in "cookies" one, or one an admin wrote about cookies. */}
{/cookie/i.test(section.id) && (
<CookieSettingsButton className="mb-3 px-3 py-1.5 text-sm rounded-lg border border-brand-300 text-brand-700 hover:bg-brand-50">
Change my cookie choice
</CookieSettingsButton>
@@ -18,6 +18,6 @@ export function PrivacyPrompts() {
const finishNotice = useCallback(() => setNoticeDone(true), []);
if (pathname === "/dashboard/user/privacy") return null;
if (user?.noticePromptPending && !noticeDone) return <NoticePrompt onDone={finishNotice} />;
if (user?.noticePromptPending && !noticeDone) return <NoticePrompt reason={user.noticePromptPending} onDone={finishNotice} />;
return <NewsPrompt />;
}