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.<address> 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 });
|
||||
}));
|
||||
|
||||
@@ -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/<name>.');
|
||||
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.<address> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user