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>
This commit is contained in:
@@ -15,7 +15,7 @@ import crypto from 'node:crypto';
|
||||
import express, { type Request, type Response } from 'express';
|
||||
import type Provider from 'oidc-provider';
|
||||
import {
|
||||
ACCOUNTS_REQUEST_PATH, IDENTITY_REQUEST_SCHEMA, identityRequestSchema,
|
||||
ACCOUNTS_REQUEST_PATH, DEMO_EMAIL_DOMAIN, IDENTITY_REQUEST_SCHEMA, identityRequestSchema,
|
||||
type ChurchLook, type IdentityRequest, type ImportPerson, type ImportResult,
|
||||
} from '@crosscode/contracts';
|
||||
import { LINK_HEADERS, openLinkValue, verify } from '@crosscode/contracts/signing';
|
||||
@@ -29,6 +29,10 @@ import { BUILT_IN_VERSION } from '../privacy/notice.js';
|
||||
import { emailProblem, normaliseEmail, profileChanged, setNewsConsent } from '../accounts/service.js';
|
||||
import { turnOff } from '../accounts/twoFactor.js';
|
||||
import { signOutEverywhere } from '../oidc/sessions.js';
|
||||
import { anonymise } from '../privacy/deletion.js';
|
||||
|
||||
/** A demo person's address (contracts DEMO_EMAIL_DOMAIN, reserved: no real person has one). */
|
||||
export const isDemoEmail = (email: string) => email.toLowerCase().endsWith(`@${DEMO_EMAIL_DOMAIN}`);
|
||||
|
||||
export class RequestError extends Error {
|
||||
constructor(message: string, public code: string, public status = 400) {
|
||||
@@ -284,6 +288,25 @@ async function handle(ctx: Ctx, provider: Provider, link: ProductLink, secret: s
|
||||
await logRequest(ctx, link, r, r.active ? 'account_reactivated_by_product' : 'account_deactivated_by_product', a.id, req);
|
||||
return reply({ ok: true as const });
|
||||
}
|
||||
case 'people.removeDemo': {
|
||||
// 1.3.0: a product's new demo data replaces the old; the old demo people's accounts go.
|
||||
const kept: { sub: string; reason: 'not_demo' | 'admin' | 'unknown' }[] = [];
|
||||
let removed = 0;
|
||||
const known = new Set((await ctx.db.productPerson.findMany({ where: { linkId: link.installId, accountId: { in: r.subs } }, select: { accountId: true } })).map((p) => p.accountId));
|
||||
const accounts = new Map((await ctx.db.account.findMany({ where: { id: { in: [...known] } } })).map((a) => [a.id, a]));
|
||||
for (const sub of new Set(r.subs)) {
|
||||
const a = accounts.get(sub);
|
||||
if (!a || a.status === 'deleted') { kept.push({ sub, reason: 'unknown' }); continue; }
|
||||
if (!isDemoEmail(a.email)) { kept.push({ sub, reason: 'not_demo' }); continue; }
|
||||
if (a.role === 'admin') { kept.push({ sub, reason: 'admin' }); continue; }
|
||||
await signOutEverywhere(ctx, provider, a.id);
|
||||
await anonymise(ctx, a.id);
|
||||
await ctx.db.productPerson.deleteMany({ where: { accountId: a.id } });
|
||||
removed++;
|
||||
}
|
||||
await logRequest(ctx, link, r, 'demo_people_removed_by_product', null, req, { removed, kept: kept.length });
|
||||
return reply({ removed, kept });
|
||||
}
|
||||
case 'church.branding': {
|
||||
const changed = await applyLook(ctx, r.church, r.overwrite);
|
||||
await logRequest(ctx, link, r, 'church_look_from_product', null, req, { changed, overwrite: r.overwrite });
|
||||
|
||||
Reference in New Issue
Block a user