Hub 2.4.0: demo sites, and demo data loaded from the Hub
Mark a Cross Events install as a demo site, then load a demo set (small, events, ministry, multicampus) with a seed-demo job (agent 1.2.0+, crosscode demo: backup, demo data, restart). Typing the short name for both. Deployment.isDemo (migration), contracts 1.7.0 vendored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -187,6 +187,19 @@ router.post('/deployments/:id/adopt', wrap(async (req, res) => {
|
||||
res.status(201).json({ job });
|
||||
}));
|
||||
|
||||
// Demo sites (2.4.0): mark one, then replace its data with a demo set.
|
||||
router.post('/deployments/:id/demo', wrap(async (req, res) => {
|
||||
const d = await jobs.setDemo(req.params.id, { isDemo: req.body?.isDemo === true, confirm: req.body?.confirm });
|
||||
await audit(req, d.isDemo ? 'install_marked_demo' : 'install_unmarked_demo', d.id, {});
|
||||
res.json({ isDemo: d.isDemo });
|
||||
}));
|
||||
|
||||
router.post('/deployments/:id/seed-demo', wrap(async (req, res) => {
|
||||
const job = await jobs.seedDemo({ deploymentId: req.params.id, profile: req.body?.profile, confirm: req.body?.confirm }, req.admin);
|
||||
await audit(req, 'demo_seed_queued', req.params.id, { job: job.id, profile: job.args.profile });
|
||||
res.status(201).json({ job });
|
||||
}));
|
||||
|
||||
router.post('/deployments/:id/uninstall', wrap(async (req, res) => {
|
||||
const out = await jobs.scheduleUninstall({ deploymentId: req.params.id, at: req.body?.at, totp: req.body?.totp, confirm: req.body?.confirm }, req.admin);
|
||||
await audit(req, 'uninstall_scheduled', req.params.id, { at: out.uninstallJob.notBefore });
|
||||
|
||||
@@ -168,6 +168,10 @@ async function afterJob(job, { exportKey }, now) {
|
||||
await emailJoshua(`${job.type === 'adopt' ? 'Adopt' : 'Update'} ${ok ? 'done' : job.status.replace('_', ' ')}: ${deployment.shortName}`, jobReportText(job));
|
||||
break;
|
||||
}
|
||||
case 'seed-demo':
|
||||
if (!deployment) break;
|
||||
await emailJoshua(`Demo data ${ok ? `(${job.args.profile}) loaded` : job.status.replace('_', ' ')}: ${deployment.shortName}`, jobReportText(job));
|
||||
break;
|
||||
case 'export':
|
||||
if (!deployment) break;
|
||||
if (ok && exportKey) {
|
||||
@@ -677,8 +681,39 @@ async function runNow({ serverId, type, args, deploymentId = null }, admin, now
|
||||
return makeJob(prisma, { serverId, type, args, deploymentId, createdById: admin?.id || null, notBefore: now });
|
||||
}
|
||||
|
||||
/** Mark or unmark an install as a demo site. Marking it asks for its short name, since a demo site's data can be replaced. */
|
||||
async function setDemo(deploymentId, { isDemo, confirm }) {
|
||||
const d = await prisma.deployment.findUnique({ where: { id: deploymentId } });
|
||||
if (!d) throw fail(404, 'NOT_FOUND', 'Not found.');
|
||||
if (d.product !== 'events') throw fail(400, 'NOT_EVENTS', 'Only Cross Events installs have demo data.');
|
||||
if (isDemo && confirm !== d.shortName) throw fail(400, 'CONFIRM', `Type ${d.shortName} to mark it as a demo site.`);
|
||||
return prisma.deployment.update({ where: { id: d.id }, data: { isDemo: !!isDemo } });
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a demo site's data with a demo set (`crosscode demo`, a backup is taken first). Only for
|
||||
* installs marked as demo sites, typing the short name, on an agent that knows the job (1.2.0+).
|
||||
*/
|
||||
async function seedDemo({ deploymentId, profile, confirm }, admin, now = new Date()) {
|
||||
const d = await prisma.deployment.findUnique({ where: { id: deploymentId }, include: { server: true } });
|
||||
if (!d) throw fail(404, 'NOT_FOUND', 'Not found.');
|
||||
if (!d.isDemo) throw fail(409, 'NOT_DEMO', `${d.shortName} isn't marked as a demo site.`);
|
||||
if (d.product !== 'events') throw fail(400, 'NOT_EVENTS', 'Only Cross Events installs have demo data.');
|
||||
if (!['live', 'waiting_for_proxy'].includes(d.status)) throw fail(409, 'NOT_LIVE', `It's ${d.status.replace(/_/g, ' ')}; demo data goes on an installed site.`);
|
||||
if (confirm !== d.shortName) throw fail(400, 'CONFIRM', `Type ${d.shortName} to replace its data.`);
|
||||
if (!agent.DEMO_PROFILES.includes(profile)) throw fail(400, 'BAD_REQUEST', `Choose one of: ${agent.DEMO_PROFILES.join(', ')}.`);
|
||||
if (d.server.removedAt) throw fail(409, 'SERVER_REMOVED', 'That server was removed.');
|
||||
if (compareVersions(d.server.agentVersion || '0.0.0', agent.SEED_DEMO_MIN_AGENT) < 0) {
|
||||
throw fail(409, 'AGENT_TOO_OLD', `The agent on ${d.server.name} is ${d.server.agentVersion || 'an unknown version'}; demo data needs ${agent.SEED_DEMO_MIN_AGENT} or later (update the agent first).`);
|
||||
}
|
||||
const running = await prisma.job.findFirst({ where: { serverId: d.serverId, status: 'delivered' }, orderBy: { deliveredAt: 'desc' } });
|
||||
if (!agentOnline(d.server, now, running)) throw fail(409, 'AGENT_OFFLINE', `The agent on ${d.server.name} isn't online.`);
|
||||
const adminEmail = d.adminEmail && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(d.adminEmail) ? d.adminEmail.toLowerCase() : undefined;
|
||||
return makeJob(prisma, { serverId: d.serverId, type: 'seed-demo', deploymentId: d.id, createdById: admin?.id || null, notBefore: now, args: { church: d.shortName, profile, ...(adminEmail ? { adminEmail } : {}) } });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
WINDOW_MIN, SCHEDULE_MIN_HOURS, EMERGENCY_MIN_MINUTES,
|
||||
WINDOW_MIN, SCHEDULE_MIN_HOURS, EMERGENCY_MIN_MINUTES, setDemo, seedDemo,
|
||||
makeJob, signedJob, jobConfig, poll, receiveReport, finish, tick, advanceBatch,
|
||||
newInstall, proxyDone, scheduleUpdate, cancelJob, scheduleUninstall, neverInstalled, removeFailedInstall, receiveExport, linkDeployment, scheduleAdopt, queueCentralCheck, runNow,
|
||||
fastPanelText, jobReportText, scheduleWarnings, requireTotp, agentOnline, siteAdminEmail,
|
||||
|
||||
Reference in New Issue
Block a user