Archived
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:
@@ -0,0 +1,73 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { ScrollText } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
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.
|
||||
*/
|
||||
export function NoticePrompt({ onDone }: { onDone: () => void }) {
|
||||
const { token } = useAuth();
|
||||
const [notice, setNotice] = useState<PublicNotice | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
apiFetch<PublicNotice>("/api/privacy/notice").then(setNotice).catch(() => onDone());
|
||||
}, [onDone]);
|
||||
|
||||
if (!notice) return null;
|
||||
|
||||
const accept = async () => {
|
||||
if (!token) return;
|
||||
setSaving(true);
|
||||
setError(null);
|
||||
try {
|
||||
await apiFetch("/api/privacy/me/notice/accept", { method: "POST", authToken: token });
|
||||
onDone();
|
||||
} catch (e) {
|
||||
setError(errorMessage(e) || "Could not save. Please try again.");
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
// The newest version that needed accepting, for "what changed".
|
||||
const changes = notice.versions.find(v => v.requiresAcceptance)?.changeSummary || notice.changeSummary;
|
||||
|
||||
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">
|
||||
<div className="w-full max-w-md rounded-xl bg-white p-6 shadow-xl">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<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'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">
|
||||
<span className="font-medium">What changed: </span>{changes}
|
||||
</div>
|
||||
)}
|
||||
<p className="text-sm text-gray-600 mb-5">
|
||||
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't agree, you can{" "}
|
||||
<Link href="/dashboard/user/privacy" className="text-brand-600 hover:underline">delete your account</Link> instead.
|
||||
</p>
|
||||
{error && <p className="text-sm text-red-600 mb-3">{error}</p>}
|
||||
<div className="flex justify-end">
|
||||
<button onClick={accept} disabled={saving} className="px-4 py-2 rounded-lg bg-brand-600 text-white text-sm font-medium hover:bg-brand-700 disabled:opacity-50">
|
||||
{saving ? "Saving…" : "I accept"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { CookieSettingsButton } from "@/components/shared/CookieSettingsButton";
|
||||
|
||||
export type NoticeSection = { id: string; title: string; body: string };
|
||||
|
||||
export type PublicNotice = {
|
||||
version: number;
|
||||
builtIn: boolean;
|
||||
current: boolean;
|
||||
publishedAt: string | null;
|
||||
effectiveDate: string;
|
||||
changeSummary: string | null;
|
||||
sections: NoticeSection[];
|
||||
versions: { version: number; publishedAt: string; changeSummary: string | null; requiresAcceptance: boolean }[];
|
||||
};
|
||||
|
||||
// Email addresses, web addresses and bare "www." names in notice text become links.
|
||||
const LINK_RE = /([\w.+-]+@[\w-]+\.[\w.]+|https?:\/\/[^\s)]+|www\.[\w-]+\.[\w.]+)/g;
|
||||
|
||||
function linkify(line: string) {
|
||||
const parts = line.split(LINK_RE);
|
||||
return parts.map((part, i) => {
|
||||
if (i % 2 === 0) return part;
|
||||
const href = part.includes("@") && !part.startsWith("http") ? `mailto:${part}` : part.startsWith("http") ? part : `https://${part}`;
|
||||
return (
|
||||
<a key={i} href={href} className="text-brand-600 hover:underline break-all" {...(href.startsWith("http") ? { target: "_blank", rel: "noopener noreferrer" } : {})}>
|
||||
{part}
|
||||
</a>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/** One section of the privacy notice: one paragraph per line, "• " lines as bullets. */
|
||||
export function PrivacyNoticeSection({ section, first = false }: { section: NoticeSection; first?: boolean }) {
|
||||
const lines = section.body.split("\n").filter(l => l.trim() !== "");
|
||||
return (
|
||||
<section id={section.id} className="mb-10 scroll-mt-24">
|
||||
{first ? (
|
||||
<h2 className="text-2xl font-semibold text-brand-600 mb-4">{section.title}</h2>
|
||||
) : (
|
||||
<h3 className="text-xl font-semibold text-brand-600 mb-3">{section.title}</h3>
|
||||
)}
|
||||
{section.id === "cookies" && (
|
||||
<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>
|
||||
)}
|
||||
{lines.map((line, i) =>
|
||||
line.startsWith("• ") ? (
|
||||
<p key={i} className="mb-1.5 pl-5 -indent-3">{"• "}{linkify(line.slice(2))}</p>
|
||||
) : (
|
||||
<p key={i} className="mb-2">{linkify(line)}</p>
|
||||
),
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
"use client";
|
||||
|
||||
import React, { useCallback, useState } from "react";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { NoticePrompt } from "@/components/shared/NoticePrompt";
|
||||
import { NewsPrompt } from "@/components/shared/NewsPrompt";
|
||||
|
||||
/**
|
||||
* The one-time POPIA questions after login, one at a time: accept a new privacy notice
|
||||
* version first, then the news opt-in. Neither shows on the Privacy page itself, so someone
|
||||
* can always get to "Delete my account".
|
||||
*/
|
||||
export function PrivacyPrompts() {
|
||||
const { user } = useAuth();
|
||||
const pathname = usePathname();
|
||||
const [noticeDone, setNoticeDone] = useState(false);
|
||||
const finishNotice = useCallback(() => setNoticeDone(true), []);
|
||||
|
||||
if (pathname === "/dashboard/user/privacy") return null;
|
||||
if (user?.noticePromptPending && !noticeDone) return <NoticePrompt onDone={finishNotice} />;
|
||||
return <NewsPrompt />;
|
||||
}
|
||||
Reference in New Issue
Block a user