Files
crosscode-platform/apps/accounts/backend/src/privacy/notice.ts
T
joshuaandClaude Opus 5.5 8856d6b35d Events 3.3.0, Accounts 1.3.0, contracts 1.11.0: Accounts looks like Events, backups; sign-out and upload fixes
- Accounts: account and admin pages in Cross Events' layout (top bar, sidebar,
  a page per section, dark footer); quick links to the church's sites
  (GET /me/apps); nightly pg_dump backups with Admin -> Backups (run, keep,
  download, audited; heartbeat lastBackupAt); a fuller built-in privacy notice
  with headings and bullets; a fixed favicon. /backups/ ignored (anchored, so
  src/backups is kept).
- Contracts 1.11.0: people.removeDemo (only @example.com, never an admin).
- Events: uploads served from the folder they're saved in (a backend started
  outside backend/ answered 404 for a logo it had just saved); Branding checks
  the file loads before saving; logout waits for the sign-out call so Accounts
  signs out too; set-demo removes the last demo's people from Accounts.
Tests: Accounts 62 + e2e 8, Events 782, contracts 225; npm run check passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 11:19:57 +02:00

107 lines
8.3 KiB
TypeScript

/**
* The privacy notice (ROADMAP-v3 §3, as Cross Events): versions an admin publishes, and who
* accepted which. Version 1 is the built-in notice; published versions are 2, 3, … Someone who
* accepted an older version is asked again before signing in to a product (§5 of the plan).
*/
import type { Ctx } from '../context.js';
import { church } from '../church/profile.js';
export const BUILT_IN_VERSION = 1;
/**
* The built-in notice (1.3.0: in sections, as Cross Events' privacy policy, and saying what
* Accounts actually does). Plain text: a line starting "## " is a heading, "• " a bullet. Filled
* in from the church profile, so it follows the church's name and contact details.
*/
export async function builtInNotice(ctx: Ctx) {
const c = await church(ctx);
const org = c.name;
const contact = [c.contact.email && `• Email: ${c.contact.email}`, c.contact.phone && `• Phone: ${c.contact.phone}`].filter(Boolean) as string[];
const keepBackups = (await ctx.settings.get('backup_retain_count')) || '14';
return {
version: BUILT_IN_VERSION,
title: `How ${org} looks after your information`,
body: [
'## In short',
`• Your church account is how you sign in to ${org}'s websites and apps. It holds your name, email address and, if you give it, your mobile number.`,
'• Your password is never stored, only a scrambled form of it that can\'t be turned back. Two-step sign-in codes and recovery codes are protected the same way.',
'• It\'s kept on the church\'s own server, not shared with other churches, and never sold.',
'• The church\'s sites only get your name and contact details, when you sign in to them, and when you change them here.',
'• News comes only if you say yes, and you can change that at any time.',
'• On your account page you can download everything held about you, see your sign-ins, and delete your account.',
'',
'## 1. Who we are',
`${org} ("we", "us") is responsible for your personal information under the Protection of Personal Information Act (POPIA). This notice is about your church account: the sign-in shared by ${org}'s websites and apps. Each site may hold more about you for what you do there (for example the events site's bookings and tickets), and explains that in its own privacy notice.`,
'',
'## 2. What we keep',
'• Your details: name, email address (and whether you\'ve confirmed it), and your mobile number if you add it.',
'• Signing in: your password as a one-way hash, which two-step sign-in method you use, your authenticator app\'s key (encrypted), and your recovery codes (hashed). Codes sent by email or WhatsApp last a few minutes and are never kept in readable form.',
'• Security records: when you sign in, fail to, change your password, or turn two-step sign-in on or off, with the time, the IP address, the device type and which site it was for. These let you spot sign-ins you don\'t recognise and let us look into misuse.',
'• Your choices: whether you want news by email or WhatsApp, which version of this notice you accepted, and when you made each choice.',
'• Which of the church\'s sites you use: so a change to your name or email reaches them, and a deletion is passed on.',
'• If you\'re an admin: what you change in the admin pages, in an audit log. When an admin opens someone\'s details, that\'s recorded too.',
'',
'## 3. How we use it',
`• To sign you in, once, to all of ${org}'s sites and apps, and to sign you out of all of them when you sign out or ask to.`,
'• To send what signing in needs: email confirmation links, password reset links, sign-in codes, and security notices.',
'• To send church news, only if you said yes.',
'• To keep your account safe: locking it after too many wrong passwords, and asking admins for a second step.',
'',
'## 4. Who can see it',
`• The church's sites and apps you sign in to get your name, email address and mobile number (and whether they're confirmed), and nothing else from here. Each is listed by the church under Linked products, and only ${org}'s own sites can be linked.`,
`• ${org}'s Accounts admins can see your details and recent sign-ins to help you (for example to unlock your account). They can't see your password or codes.`,
'• Email is sent through the church\'s email provider, and WhatsApp messages through WAWP (wawp.net); they get only the message and where it goes.',
'• The software (Cross Code Accounts) is licensed from Cross Code. Every 15 minutes it sends Cross Code\'s licence server totals, such as how many accounts there are and how many use two-step sign-in, and technical health information. Never names, contact details or anything else about a person.',
'• Nobody else, unless South African law requires it. We don\'t sell or rent your information.',
'',
'## 5. Where it\'s kept, and for how long',
`• On ${org}'s server, in its own database, separate from every other church.`,
`• Your account and its sign-in history are kept while you have the account. A copy of your data that you ask to download is kept for 7 days. Sign-in codes stop working after a few minutes, and links to set or reset a password after at most 7 days.`,
`• The database is backed up every night onto the same server; the last ${keepBackups} backups are kept, then deleted. Backups are only used to put things back after a fault.`,
'• When your account is deleted, your name, contact details, password, codes and sign-in history are removed straight away, and are gone from the backups once those backups are deleted in turn.',
'',
'## 6. Cookies',
`Signing in uses a few cookies that are strictly necessary: they keep you signed in (for as long as "Keep me signed in" lasts, if you tick it) and protect each sign-in step. There are no tracking, advertising or analytics cookies, and these pages load nothing from other websites apart from the church's own logo.`,
'',
'## 7. Your rights',
'Under POPIA you may see the information we hold about you, have it corrected or deleted, withdraw consent (for example to news), object to direct marketing, and complain to the Information Regulator. On your account page you can:',
'• change your details and your news choices;',
'• download a copy of everything the church\'s sites hold about you;',
'• see your recent sign-ins, and sign out everywhere;',
`• delete your account. You're signed out at once; an admin confirms it, then each of the church's sites deletes what it holds (a site may wait until an event you're booked for is over).`,
'We answer requests within 30 days. The Information Regulator: www.inforeg.org.za, enquiries@inforeg.org.za.',
'',
'## 8. Children',
'Anyone under 18 should have a parent\'s or guardian\'s permission to make a church account.',
'',
'## 9. Changes to this notice',
'If this notice changes, you\'re asked to read the new version the next time you sign in.',
'',
'## 10. Contact us',
contact.length ? `To ask about your information or use your rights, contact ${org}:` : `To ask about your information or use your rights, contact ${org}'s office.`,
...contact,
].join('\n'),
publishedAt: null as Date | null,
};
}
export async function currentNotice(ctx: Ctx) {
const latest = await ctx.db.privacyNotice.findFirst({ orderBy: { version: 'desc' } });
return latest ?? (await builtInNotice(ctx));
}
export async function currentNoticeVersion(ctx: Ctx): Promise<number> {
return (await currentNotice(ctx)).version;
}
export async function accept(ctx: Ctx, accountId: string, version: number) {
await ctx.db.noticeAcceptance.create({ data: { accountId, version, acceptedAt: ctx.now() } });
await ctx.db.account.update({ where: { id: accountId }, data: { noticeVersionAccepted: version } });
}
export async function publish(ctx: Ctx, input: { title: string; body: string }, actorId: string) {
const latest = await ctx.db.privacyNotice.findFirst({ orderBy: { version: 'desc' } });
const version = Math.max(BUILT_IN_VERSION, latest?.version ?? BUILT_IN_VERSION) + 1;
return ctx.db.privacyNotice.create({ data: { version, title: input.title, body: input.body, publishedAt: ctx.now(), publishedById: actorId } });
}