feat(website): the admin, with drafts, preview, publish and restore

Admin API and screens: dashboard and setup checklist, template and
style, pages and blocks, ministries, leadership, media library with
the storage limit, publish and history. Pending changes with who and
when, discard one, one Publish, restore any version (each version
keeps the working copy's rows, never sent to visitors). Preview on
the site's own addresses with a bar (widths, back, publish); shared
preview links for 7 days or until revoked. Roles checked, same-origin
changes only. Publish refreshes the public pages at once
(WEBSITE_CONTENT_CACHE_SECONDS). E2E on a production build: the
admin's flows and axe on every screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 12:30:29 +02:00
co-authored by Claude Opus 5.5
parent 3caa1d1e1a
commit 84c5b0c08e
44 changed files with 2404 additions and 65 deletions
+13 -7
View File
@@ -16,13 +16,15 @@ import path from 'node:path';
import express from 'express';
import type { Ctx } from './context.js';
import { authRouter } from './auth/routes.js';
import { requireRole } from './auth/sessions.js';
import { adminRouter } from './admin/routes.js';
import { previewTokenValid } from './admin/previewLinks.js';
import { atLeast, currentSession } from './auth/sessions.js';
import { dbUp } from './hub/client.js';
import { ApiError, handle, sendError } from './http.js';
import { appVersion } from './lib/version.js';
import { linksRouter } from './links/routes.js';
import { defaultUploadDir } from './demo/demoChurch.js';
import { siteContent } from './site/content.js';
import { previewContent, siteContent } from './site/content.js';
import { siteStatus } from './site/status.js';
export function createApp(ctx: Ctx) {
@@ -45,6 +47,14 @@ export function createApp(ctx: Ctx) {
const site = express.Router();
site.get('/status', handle(() => siteStatus(ctx)));
// The preview (§4): the working copy, for a signed-in admin or a shared preview link. Never cached.
site.get('/preview', handle(async (req, res) => {
const signed = await currentSession(ctx, req);
if (!signed && !(await previewTokenValid(ctx, req.get('x-preview-token')))) throw new ApiError(401, 'NO_PREVIEW', 'This preview has ended, or you need to sign in.');
res.set('Cache-Control', 'no-store');
res.set('X-Robots-Tag', 'noindex, nofollow');
return { ...(await previewContent(ctx)), preview: { by: signed ? 'admin' : 'link', canPublish: !!signed && atLeast(signed.user.role, 'editor') } };
}));
site.get('/content', handle(async (_req, res) => {
// Short: Publish shows within a minute even where a proxy caches.
res.set('Cache-Control', 'public, max-age=30');
@@ -64,11 +74,7 @@ export function createApp(ctx: Ctx) {
app.use('/api', authRouter(ctx));
app.use('/api', linksRouter(ctx));
const admin = express.Router();
admin.use(express.json({ limit: '256kb' }));
admin.use(requireRole(ctx, 'viewer'));
admin.get('/me', handle(async (req) => ({ user: req.signed!.user, mfa: req.signed!.mfa })));
app.use('/api/v1/admin', admin);
app.use('/api/v1/admin', adminRouter(ctx));
app.use('/api', (_req, res) => {
res.status(404).json({ error: { code: 'NOT_FOUND', message: 'There is no such API endpoint.' } });