POPIA toolkit part 3: retention, breach register, readiness

- Retention policies (Admin -> Privacy -> Retention) applied by a nightly
  `retention` job: inactive accounts anonymised after 5 years with a
  30-day warning (on by default; never staff roles or people with an
  upcoming registration), form answers, login history, payer details in
  payment notifications, audit/access logs
- User.lastLoginAt (set on login, backfilled) and inactivityWarnedAt
- Breach register (SecurityBreach) with drafts for the people affected
  and the Information Regulator
- Readiness checklist with a score
- Children's/medical flag in the access log; {retention} placeholder in
  the privacy notice
- Unit tests (retention.test.js), e2e (privacy-retention.spec.ts); docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012mt6TCv85T9VKRq3cV7rXq
This commit is contained in:
2026-10-23 20:25:58 +02:00
co-authored by Claude Opus 5.5
parent 6eee10b610
commit a1ecbb9617
32 changed files with 1441 additions and 35 deletions
@@ -119,13 +119,14 @@ export function ConsentLogPanel({ token }: { token: string }) {
// ─── Access log ───────────────────────────────────────────────────────────────
type AccessRow = { id: string; at: string; actor: string; actorRole: string; action: string; what: string; records: number | null; ip: string | null };
type AccessRow = { id: string; at: string; actor: string; actorRole: string; action: string; what: string; records: number | null; ip: string | null; sensitive: boolean };
type AccessResponse = LogResponse<AccessRow> & { actions: Record<string, string>; actors: { id: string; name: string }[] };
/** Admin → Privacy → Access log: who took personal information out of the system in bulk. */
export function AccessLogPanel({ token }: { token: string }) {
const [action, setAction] = useState("");
const [actorId, setActorId] = useState("");
const [sensitiveOnly, setSensitiveOnly] = useState(false);
const [page, setPage] = useState(1);
const [data, setData] = useState<AccessResponse | null>(null);
const [error, setError] = useState<string | null>(null);
@@ -135,12 +136,13 @@ export function AccessLogPanel({ token }: { token: string }) {
const params = new URLSearchParams({ page: String(page) });
if (action) params.set("action", action);
if (actorId) params.set("actorId", actorId);
if (sensitiveOnly) params.set("sensitive", "true");
setData(await apiFetch<AccessResponse>(`/api/privacy/access-log?${params}`, { authToken: token }));
setError(null);
} catch (e) {
setError(errorMessage(e) || "Could not load the access log.");
}
}, [token, action, actorId, page]);
}, [token, action, actorId, sensitiveOnly, page]);
useEffect(() => { load(); }, [load]);
return (
@@ -158,6 +160,10 @@ export function AccessLogPanel({ token }: { token: string }) {
<option value="">Everyone</option>
{(data?.actors || []).map(a => <option key={a.id} value={a.id}>{a.name}</option>)}
</select>
<label className="flex items-center gap-2 text-sm text-gray-700">
<input type="checkbox" className="h-4 w-4 accent-brand-600" checked={sensitiveOnly} onChange={e => { setSensitiveOnly(e.target.checked); setPage(1); }} />
Children&apos;s or medical information only
</label>
</div>
{error && <p className="text-sm text-red-700">{error}</p>}
{!data ? <p className="text-sm text-gray-400">Loading…</p> : data.rows.length === 0 ? <p className="text-sm text-gray-500">Nothing recorded yet.</p> : (
@@ -168,7 +174,11 @@ export function AccessLogPanel({ token }: { token: string }) {
<tr key={r.id} className="border-t align-top">
<td className="p-2 whitespace-nowrap">{fmt(r.at)}</td>
<td className="p-2">{r.actor}<div className="text-xs text-gray-500">{r.actorRole}{r.ip ? ` · ${r.ip}` : ""}</div></td>
<td className="p-2">{data.actions[r.action] || r.action}<div className="text-xs text-gray-500">{r.what}</div></td>
<td className="p-2">
{data.actions[r.action] || r.action}
{r.sensitive && <span className="ml-2 text-[11px] px-1.5 py-0.5 rounded bg-rose-50 text-rose-700" title="Children's or special personal information">children/medical</span>}
<div className="text-xs text-gray-500">{r.what}</div>
</td>
<td className="p-2 text-right">{r.records ?? "—"}</td>
</tr>
))}</tbody>