From a2e97a5ea9b2813ec25cbd32df156d2bb1e37024 Mon Sep 17 00:00:00 2001 From: Joshua Oosthuizen Date: Wed, 18 Nov 2026 09:58:16 +0200 Subject: [PATCH] Adopt: pass the church's address; Link: the short name is a name crosscode adopt can only work out the church's address from an events.
domain, and the Hub never sent --address, so adopting a site like events-demo.crosscode.co.za failed on the server. The adopt form now asks for the address (required for such domains), the Hub refuses to plan the move without it, and it goes into the job's arguments. Link existing: the short name field and its error say it's a name like `hope`, not a folder. Co-Authored-By: Claude Opus 5.5 --- backend/src/routes/servers.js | 2 +- backend/src/utils/jobs.js | 12 +++++-- backend/tests/servers.test.js | 32 +++++++++++++++++++ .../app/(hub)/servers/installs/[id]/page.tsx | 6 ++-- .../src/app/(hub)/servers/installs/page.tsx | 2 +- 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/backend/src/routes/servers.js b/backend/src/routes/servers.js index cb9f6cb..0ae1017 100644 --- a/backend/src/routes/servers.js +++ b/backend/src/routes/servers.js @@ -166,7 +166,7 @@ router.post('/deployments/:id/proxy-done', wrap(async (req, res) => { })); router.post('/deployments/:id/adopt', wrap(async (req, res) => { - const job = await jobs.scheduleAdopt({ deploymentId: req.params.id, eventsDir: req.body?.eventsDir, version: req.body?.version, at: req.body?.at }, req.admin); + const job = await jobs.scheduleAdopt({ deploymentId: req.params.id, eventsDir: req.body?.eventsDir, version: req.body?.version, address: req.body?.address, at: req.body?.at }, req.admin); await audit(req, 'adopt_scheduled', req.params.id, { job: job.id, at: job.notBefore }); res.status(201).json({ job }); })); diff --git a/backend/src/utils/jobs.js b/backend/src/utils/jobs.js index ae0a0b8..2b2d0b5 100644 --- a/backend/src/utils/jobs.js +++ b/backend/src/utils/jobs.js @@ -567,7 +567,7 @@ async function linkDeployment(input, admin) { if (!server || !install) throw fail(404, 'NOT_FOUND', 'Server or install not found.'); if (install.deployment) throw fail(409, 'ALREADY_LINKED', 'That install is already linked.'); const shortName = String(input.shortName || '').trim(); - if (!SHORT_NAME.test(shortName)) throw fail(400, 'BAD_REQUEST', 'The short name (its folder in /var/www/sites) is a-z, 0-9 and -.'); + if (!SHORT_NAME.test(shortName)) throw fail(400, 'BAD_REQUEST', 'The short name is just a name (a-z, 0-9 and -, like hope), not a folder: the site lives, or will after adopt, in /var/www/sites/.'); const web = parseInt(input.webPort, 10); const api = parseInt(input.apiPort, 10); if (!(web > 0 && api > 0 && web !== api)) throw fail(400, 'BAD_REQUEST', 'Give the site\'s two ports (web and api).'); @@ -584,14 +584,20 @@ async function linkDeployment(input, admin) { } /** Move a linked 2.1.x install onto the monorepo with `crosscode adopt`, at a time with notice. */ -async function scheduleAdopt({ deploymentId, eventsDir, version, at }, admin, now = new Date()) { +async function scheduleAdopt({ deploymentId, eventsDir, version, address, at }, admin, now = new Date()) { const d = await prisma.deployment.findUnique({ where: { id: deploymentId }, include: { install: true, server: true } }); if (!d) throw fail(404, 'NOT_FOUND', 'Not found.'); + // The church's address (crosscode adopt --address): crosscode can only work it out from an + // events.
domain, so any other domain (events-demo.crosscode.co.za) needs it given. + let church = String(address || '').trim().toLowerCase(); + if (!church && d.domain.startsWith('events.')) church = d.domain.slice('events.'.length); + if (!church) throw fail(400, 'ADDRESS_NEEDED', `${d.domain} doesn't start with "events.", so give the church's address (like hope.co.za).`); + if (!DOMAIN.test(church)) throw fail(400, 'BAD_REQUEST', 'The church\'s address is a domain, like hope.co.za.'); const when = new Date(at); if (Number.isNaN(when.getTime()) || when - now < SCHEDULE_MIN_HOURS * HOUR) throw fail(400, 'TOO_SOON', `Plan it at least ${SCHEDULE_MIN_HOURS} hours ahead.`); const release = await releaseFor(d.product, version || null); const noticeId = await addNotice(d, { title: 'Planned maintenance', message: `${PRODUCT_NAMES[d.product]} will be moved to its new home on ${sast(when)}. The site will be unavailable for a minute or two.`, endsAt: new Date(when.getTime() + 2 * HOUR) }, now); - const job = await makeJob(prisma, { serverId: d.serverId, type: 'adopt', deploymentId: d.id, createdById: admin?.id || null, scheduled: true, notBefore: when, noticeId, args: { church: d.shortName, eventsDir: String(eventsDir || ''), version: `${d.product}@${release.version}` } }); + const job = await makeJob(prisma, { serverId: d.serverId, type: 'adopt', deploymentId: d.id, createdById: admin?.id || null, scheduled: true, notBefore: when, noticeId, args: { church: d.shortName, eventsDir: String(eventsDir || ''), version: `${d.product}@${release.version}`, address: church } }); await emailSiteAdmin(d, `Planned maintenance on ${sast(when)}`, `${PRODUCT_NAMES[d.product]} at ${d.domain} will be moved to its new home on ${sast(when)}. The site will be unavailable for a minute or two; nothing changes for your team.`); return job; } diff --git a/backend/tests/servers.test.js b/backend/tests/servers.test.js index 7b5fc36..09ed6a8 100644 --- a/backend/tests/servers.test.js +++ b/backend/tests/servers.test.js @@ -312,3 +312,35 @@ describe('banners reach a site the Hub installed (found in the VM test)', () => expect((await db.deployment.findUnique({ where: { id: d.id } })).installId).toBe('inst-9'); }); }); + +describe('adopting an existing install', () => { + async function linked(domain) { + const { server } = await joinServer(); + await db.release.create({ data: { product: 'events', version: '2.3.0', releasedAt: NOW } }); + await db.install.create({ data: { id: `inst-${domain}`, customerId: 'cust-1', product: 'events', name: 'Demo', url: `https://${domain}`, secret: 'x', version: '2.1.1' } }); + return jobs.linkDeployment({ serverId: server.id, installId: `inst-${domain}`, shortName: 'cross-events-demo', webPort: 3100, apiPort: 5100 }, admin); + } + const at = new Date(NOW.getTime() + 5 * H); + + test('a link takes a name, not a folder', async () => { + const { server } = await joinServer(); + await db.install.create({ data: { id: 'inst-p', customerId: 'cust-1', product: 'events', name: 'P', url: 'https://events.p.test', secret: 'x', version: '2.1.1' } }); + await expect(jobs.linkDeployment({ serverId: server.id, installId: 'inst-p', shortName: '/var/www/cross-events-demo', webPort: 3100, apiPort: 5100 }, admin)) + .rejects.toMatchObject({ status: 400, message: expect.stringContaining('not a folder') }); + }); + + test('the old folder and the church address go to crosscode adopt', async () => { + const d = await linked('events-demo.crosscode.co.za'); + const job = await jobs.scheduleAdopt({ deploymentId: d.id, eventsDir: '/var/www/cross-events-demo', address: 'crosscode.co.za', at }, admin, NOW); + expect(job.args).toMatchObject({ church: 'cross-events-demo', eventsDir: '/var/www/cross-events-demo', address: 'crosscode.co.za' }); + expect(agent.jobArgsSchemas.adopt.safeParse(job.args).success).toBe(true); + }); + + test('a domain without "events." needs the address; events.
works it out', async () => { + const d = await linked('events-demo.crosscode.co.za'); + await expect(jobs.scheduleAdopt({ deploymentId: d.id, eventsDir: '/var/www/cross-events-demo', at }, admin, NOW)).rejects.toMatchObject({ status: 400, code: 'ADDRESS_NEEDED' }); + await db.deployment.update({ where: { id: d.id }, data: { domain: 'events.hope.co.za' } }); + const job = await jobs.scheduleAdopt({ deploymentId: d.id, eventsDir: '/var/www/hope-events', at }, admin, NOW); + expect(job.args.address).toBe('hope.co.za'); + }); +}); diff --git a/frontend/src/app/(hub)/servers/installs/[id]/page.tsx b/frontend/src/app/(hub)/servers/installs/[id]/page.tsx index a3e0833..279d338 100644 --- a/frontend/src/app/(hub)/servers/installs/[id]/page.tsx +++ b/frontend/src/app/(hub)/servers/installs/[id]/page.tsx @@ -24,7 +24,7 @@ export default function DeploymentPage() { const [msg, setMsg] = useState(warn ? { type: "err", text: warn } : null); const [problems, setProblems] = useState([]); const [upd, setUpd] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, reason: "", totp: "" }); - const [adopt, setAdopt] = useState({ eventsDir: "", version: "", at: toInput(new Date(Date.now() + 5 * H)) }); + const [adopt, setAdopt] = useState({ eventsDir: "", version: "", address: "", at: toInput(new Date(Date.now() + 5 * H)) }); const [un, setUn] = useState({ at: toInput(new Date(Date.now() + 7 * 24 * H)), totp: "", confirm: "" }); const load = useCallback(() => api(`/api/admin/deployments/${id}`).then(setD).catch(e => setMsg({ type: "err", text: errorText(e) })), [id]); @@ -85,9 +85,11 @@ export default function DeploymentPage() { )} {x.status === "live" && x.install?.version?.startsWith("2.1.") && ( -
{ e.preventDefault(); act(`/api/admin/deployments/${x.id}/adopt`, { eventsDir: adopt.eventsDir, version: adopt.version || undefined, at: fromInput(adopt.at) }, "Adopt planned. The site admin was emailed."); }}> + { e.preventDefault(); act(`/api/admin/deployments/${x.id}/adopt`, { eventsDir: adopt.eventsDir, version: adopt.version || undefined, address: adopt.address || undefined, at: fromInput(adopt.at) }, "Adopt planned. The site admin was emailed."); }}>

Move onto the monorepo (crosscode adopt)

+

Moves the site from its old folder to /var/www/sites/{x.shortName}/events. Same database, uploads, .env and ports; the old folder is kept 14 days for crosscode adopt {x.shortName} --undo.

setAdopt({ ...adopt, eventsDir: e.target.value })} />
+
setAdopt({ ...adopt, address: e.target.value })} />
setAdopt({ ...adopt, version: e.target.value })} />
setAdopt({ ...adopt, at: e.target.value })} />
diff --git a/frontend/src/app/(hub)/servers/installs/page.tsx b/frontend/src/app/(hub)/servers/installs/page.tsx index a785e5c..1f03148 100644 --- a/frontend/src/app/(hub)/servers/installs/page.tsx +++ b/frontend/src/app/(hub)/servers/installs/page.tsx @@ -111,7 +111,7 @@ export default function InstallsPage() {

For sites installed by hand or moved with crosscode adopt. Nothing on the server changes; the Hub records the server, folder name and ports (see the server's church.env and frpc.ini).

-
+

Just the name, not a path: its folder is /var/www/sites/<name>. A site still in an old folder (/var/www/hope-events) gets that name when you move it onto the monorepo.