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 7f5e31461a
commit 6907bc3bd3
32 changed files with 1441 additions and 35 deletions
+20 -11
View File
@@ -7,11 +7,12 @@
* notice is shown, so it follows Site settings and the operator register:
* {org} {orgEmail} {website} {ioName} {ioEmail} {medicalRetentionDays}
* {operators} — on a line of its own: one bullet per active operator.
* {retention} — on a line of its own: one bullet per retention period (utils/retention.js).
*/
const prisma = require('../config/db');
const PLACEHOLDERS = ['org', 'orgEmail', 'website', 'ioName', 'ioEmail', 'medicalRetentionDays', 'operators'];
const PLACEHOLDERS = ['org', 'orgEmail', 'website', 'ioName', 'ioEmail', 'medicalRetentionDays', 'operators', 'retention'];
const MAX_SECTIONS = 40;
const MAX_TITLE = 200;
const MAX_BODY = 20000;
@@ -120,13 +121,10 @@ const DEFAULT_SECTIONS = [
id: 'retention',
title: '7. Data Retention',
body: [
'We retain your personal data for up to 5 years after your last event registration, or until you ask us to delete your account — whichever comes first.',
'Medical and emergency-contact details from parental consent forms are deleted {medicalRetentionDays} days after the event ends. The record of who gave consent, when, and to which wording is kept.',
'Detailed visit statistics are combined into anonymous daily totals after 90 days.',
"Ticket lists downloaded to a staff member's scanner for offline check-in are deleted from that device when offline mode is ended.",
'Records of support access to accounts (see section 9), of who exported personal information, and other audit records are kept for accountability.',
'You can ask for your account to be deleted from the Privacy page in your account. Your account is closed straight away, and your personal information — your name and contact details, the people you registered, your form answers — is deleted within 30 days (after any upcoming event you registered for). Payment and registration records are kept without your name, because the law requires us to keep financial records.',
'Backups of our database still contain deleted information until they are replaced, which happens automatically within a few weeks.',
'We keep personal information only as long as we need it:',
'{retention}',
"• Ticket lists downloaded to a staff member's scanner for offline check-in are deleted from that device when offline mode is ended.",
'You can ask for your account to be deleted at any time from the Privacy page in your account. Your account is closed straight away, and your personal information — your name and contact details, the people you registered, your form answers — is deleted within 30 days (after any upcoming event you registered for). Payment and registration records are kept without your name, because the law requires us to keep financial records.',
].join('\n'),
},
{
@@ -263,7 +261,7 @@ function cleanSections(input) {
/** Settings and operators the placeholders are filled from. */
async function noticeContext(db = prisma) {
const { getSetting } = require('./settingsCache');
const [org, orgEmail, website, ioName, ioEmail, medicalDays, operators] = await Promise.all([
const [org, orgEmail, website, ioName, ioEmail, medicalDays, operators, retention] = await Promise.all([
getSetting('org_name', process.env.ORG_NAME || 'Cross Code'),
getSetting('org_email', ''),
getSetting('legal_website_url', ''),
@@ -271,6 +269,7 @@ async function noticeContext(db = prisma) {
getSetting('legal_io_email', ''),
getSetting('consent_medical_retention_days', ''),
db.operator.findMany({ where: { active: true }, orderBy: [{ order: 'asc' }, { name: 'asc' }] }),
require('./retention').noticeLines(db),
]);
// Unset legal fields show an obviously-unfinished placeholder, never someone's real details.
return {
@@ -281,9 +280,16 @@ async function noticeContext(db = prisma) {
ioEmail: ioEmail || 'io@example.com',
medicalRetentionDays: String(parseInt(medicalDays, 10) || 30),
operators,
retention,
};
}
// Placeholders that stand on a line of their own and become several bullet lines.
const LIST_PLACEHOLDERS = {
operators: ctx => (ctx.operators.length ? ctx.operators.map(operatorLine) : ['• (No service providers listed.)']),
retention: ctx => ctx.retention || [],
};
function operatorLine(o) {
return `• ${o.name}${o.location ? ` (${o.location})` : ''} — ${o.purpose}. ${o.dataShared ? `Receives: ${o.dataShared}.` : ''}`.trim();
}
@@ -293,8 +299,11 @@ function renderSections(sections, ctx) {
return sections.map(s => {
const body = String(s.body || '')
.split('\n')
.flatMap(line => (line.trim() === '{operators}' ? (ctx.operators.length ? ctx.operators.map(operatorLine) : ['• (No service providers listed.)']) : [line]))
.map(line => line.replace(/\{(\w+)\}/g, (m, key) => (key !== 'operators' && PLACEHOLDERS.includes(key) ? ctx[key] : m)))
.flatMap(line => {
const list = line.trim().match(/^\{(\w+)\}$/)?.[1];
return list && LIST_PLACEHOLDERS[list] ? LIST_PLACEHOLDERS[list](ctx) : [line];
})
.map(line => line.replace(/\{(\w+)\}/g, (m, key) => (!LIST_PLACEHOLDERS[key] && PLACEHOLDERS.includes(key) ? ctx[key] : m)))
.join('\n');
return { id: s.id, title: s.title, body };
});