POPIA toolkit part 2: privacy notice editor, operators, consent and access logs

- Admin -> Privacy (POPIA): edit the privacy notice (built-in text as the
  start, placeholders for org/IO/operators), drafts, preview, numbered
  versions; earlier versions readable on /legal/privacy?version=N
- "Significant change" versions are accepted once after login
  (NoticePrompt); sign-up records the version accepted
- Operator register (seeded with the services the app uses), listed in
  the notice via {operators}
- Consent log (news opt-ins, notice acceptances, parental consent) and
  access log (report exports, registers, certificates, group lists, form
  answers, consent/medical lists, backups, impersonation)
- Information Officer on the contact page
- Unit tests (privacyNotice.test.js), e2e (privacy-notice.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 19:11:20 +02:00
co-authored by Claude Opus 5.5
parent 04be99b930
commit 34f9e96e4e
40 changed files with 2328 additions and 324 deletions
@@ -397,6 +397,13 @@ function writeTableRows(ws, startRow, columns, rows) {
return { nextRow: r, dataStartRow };
}
// POPIA access log: who took which report out of the system, and how many rows.
function logReport(req, action) {
const { logDataAccess, reportRowCount } = require('../utils/accessLog');
const p = req.body || {};
logDataAccess(req, { action, what: [p.title || 'Report', p.subtitle].filter(Boolean).join(' — '), records: reportRowCount(p) });
}
// POST /api/reports/pdf
// body: { title, subtitle?, kind: 'table'|'layered', table?, layered?, stats?, chart?, note?, orientation? }
const generatePdf = async (req, res) => {
@@ -410,6 +417,7 @@ const generatePdf = async (req, res) => {
doc.pipe(res);
drawReportPdf(doc, { title, subtitle, kind, table, layered, stats, chart, note, extraTables });
doc.end();
logReport(req, 'report_pdf');
} catch (e) {
res.status(400).json({ message: e.message });
}
@@ -426,6 +434,7 @@ const generateExcel = async (req, res) => {
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
await wb.xlsx.write(res);
res.end();
logReport(req, 'report_excel');
} catch (e) {
res.status(400).json({ message: e.message });
}
@@ -462,6 +471,7 @@ const emailPdf = async (req, res) => {
try { fs.unlinkSync(filePath); } catch {}
logReport(req, 'report_email');
res.json({ message: `Report emailed to ${user.email}` });
} catch (e) {
res.status(400).json({ message: e.message });
@@ -489,6 +499,7 @@ const whatsappPdf = async (req, res) => {
const filename = `${(title || 'report').replace(/[^a-z0-9]/gi, '_').toLowerCase()}.pdf`;
await sendPdf(user.phoneNumber, filePath, filename, caption || title || 'Report');
logReport(req, 'report_whatsapp');
res.json({ message: `Report sent to your WhatsApp` });
} catch (e) {
res.status(400).json({ message: e.message });