- 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
52 lines
2.0 KiB
JavaScript
52 lines
2.0 KiB
JavaScript
const prisma = require('../config/db');
|
|
const { getClientIp } = require('./requestUtils');
|
|
|
|
// What each DataAccessLog action means, for the admin page.
|
|
const ACCESS_ACTIONS = {
|
|
report_pdf: 'Report downloaded (PDF)',
|
|
report_excel: 'Report downloaded (Excel)',
|
|
report_email: 'Report emailed',
|
|
report_whatsapp: 'Report sent by WhatsApp',
|
|
attendance_export: 'Attendance register exported',
|
|
certificates_download: 'Certificates downloaded',
|
|
group_lists: 'Room/group lists opened',
|
|
form_responses: 'Attendee form answers viewed',
|
|
consent_list: 'Parental consent list viewed',
|
|
medical_list: 'Medical list viewed',
|
|
backup_download: 'Database backup downloaded',
|
|
impersonation: 'Viewed the site as another user',
|
|
};
|
|
|
|
/**
|
|
* POPIA access log: someone exported or viewed personal information in bulk. Fire-and-
|
|
* forget like logAdminAction — a logging failure never blocks the export itself.
|
|
*/
|
|
async function logDataAccess(req, { action, what, eventId = null, records = null }) {
|
|
try {
|
|
await prisma.dataAccessLog.create({
|
|
data: {
|
|
actorId: req.user?.id || null,
|
|
actorRole: req.user?.role || 'unknown',
|
|
action,
|
|
what: String(what || ACCESS_ACTIONS[action] || action).slice(0, 500),
|
|
eventId: eventId || null,
|
|
records: Number.isFinite(records) ? records : null,
|
|
ip: getClientIp(req),
|
|
},
|
|
});
|
|
} catch (e) {
|
|
console.error('Failed to log data access:', e?.message);
|
|
}
|
|
}
|
|
|
|
/** Rows in a report payload (main table or layered sections, plus extra tables). */
|
|
function reportRowCount(payload) {
|
|
const p = payload || {};
|
|
let n = Array.isArray(p.table?.rows) ? p.table.rows.length : 0;
|
|
if (Array.isArray(p.layered?.sections)) n += p.layered.sections.reduce((s, sec) => s + (Array.isArray(sec.items) ? sec.items.length : 0), 0);
|
|
if (Array.isArray(p.extraTables)) n += p.extraTables.reduce((s, t) => s + (Array.isArray(t.rows) ? t.rows.length : 0), 0);
|
|
return n;
|
|
}
|
|
|
|
module.exports = { ACCESS_ACTIONS, logDataAccess, reportRowCount };
|