|
|
|
@@ -34,6 +34,8 @@ const SCHEDULE_MIN_HOURS = 4;
|
|
|
|
|
const EMERGENCY_MIN_MINUTES = 15;
|
|
|
|
|
const AGENT_ONLINE_MS = 2 * MIN;
|
|
|
|
|
const EXPORT_DAYS = 30;
|
|
|
|
|
// The crosscode script's order (Accounts first: the others sign in through it).
|
|
|
|
|
const PRODUCT_ORDER = ['accounts', 'events', 'website', 'app'];
|
|
|
|
|
const SHORT_NAME = /^[a-z][a-z0-9-]{1,30}$/;
|
|
|
|
|
const DOMAIN = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$/;
|
|
|
|
|
|
|
|
|
@@ -213,7 +215,7 @@ async function afterJob(job, { exportKey }, now) {
|
|
|
|
|
await emailSiteAdmin(deployment, 'Your church\'s data from Cross Code', {
|
|
|
|
|
heading: 'Your data is ready to download',
|
|
|
|
|
blocks: [
|
|
|
|
|
{ p: `Here is all of ${deployment.customer?.name || 'your church'}'s data from ${PRODUCT_NAMES[deployment.product]}: events, people, registrations, payments, check-ins and rosters, with the uploaded files.` },
|
|
|
|
|
{ p: `Here is all of ${deployment.customer?.name || 'your church'}'s data from ${(job.args.products || [deployment.product]).map(p => PRODUCT_NAMES[p]).join(' and ')}: events, people, registrations, payments, check-ins and rosters, with the uploaded files.` },
|
|
|
|
|
{ button: { label: 'Download your data', url: link } },
|
|
|
|
|
{ note: { kind: 'warning', title: 'Keep this email', text: `The link works until ${exp ? sast(exp.expiresAt) : `${EXPORT_DAYS} days from now`}. The file is encrypted, and only this link (the part after #) can open it: we can't read it, and we can't send the link again.` } },
|
|
|
|
|
],
|
|
|
|
@@ -232,21 +234,31 @@ async function afterJob(job, { exportKey }, now) {
|
|
|
|
|
case 'uninstall':
|
|
|
|
|
if (!deployment) break;
|
|
|
|
|
if (ok) {
|
|
|
|
|
await prisma.deployment.update({ where: { id: deployment.id }, data: { status: 'removed', removedAt: now } });
|
|
|
|
|
await prisma.port.updateMany({ where: { port: { in: [deployment.webPort, deployment.apiPort] } }, data: { releasedAt: now, deploymentId: deployment.id } });
|
|
|
|
|
if (deployment.installId) await prisma.install.update({ where: { id: deployment.installId }, data: { releasedAt: now } });
|
|
|
|
|
await makeJob(prisma, { serverId: deployment.serverId, type: 'purge', args: { church: deployment.shortName }, deploymentId: deployment.id, notBefore: new Date(now.getTime() + EXPORT_DAYS * DAY), windowMinutes: 3 * 24 * 60 });
|
|
|
|
|
await emailJoshua(`Uninstalled: ${deployment.shortName}`, {
|
|
|
|
|
heading: `${deployment.domain} is uninstalled`,
|
|
|
|
|
// Hub 2.12.0: with `products` (agent 1.5.0) only those went. Without it the agent removed
|
|
|
|
|
// the whole church, so its other products on this server are gone too (before 2.12.0
|
|
|
|
|
// they stayed "live" here, and their own uninstall failed later).
|
|
|
|
|
// A run can name several products (one joined to another's uninstall). When the script
|
|
|
|
|
// reports nothing left of the church (`remaining` empty: the last product went, so the
|
|
|
|
|
// church's folder and app user went too), every product of it here is gone.
|
|
|
|
|
const whole = !job.args?.products;
|
|
|
|
|
const all = [deployment, ...(await churchSiblings(deployment))];
|
|
|
|
|
const remaining = job.report?.result?.remaining;
|
|
|
|
|
const churchGone = whole || (Array.isArray(remaining) && remaining.length === 0);
|
|
|
|
|
const gone = churchGone ? all : all.filter(x => job.args.products.includes(x.product));
|
|
|
|
|
for (const g of gone) await markRemoved(g, now, { except: job.id, why: `Not needed: ${g.domain} was uninstalled by ${job.id}.` });
|
|
|
|
|
await makeJob(prisma, { serverId: deployment.serverId, type: 'purge', args: { church: deployment.shortName, ...(whole ? {} : { products: job.args.products }) }, deploymentId: deployment.id, notBefore: new Date(now.getTime() + EXPORT_DAYS * DAY), windowMinutes: 3 * 24 * 60 });
|
|
|
|
|
await emailJoshua(`Uninstalled: ${deployment.shortName}${whole ? '' : ` (${job.args.products.map(p => PRODUCT_NAMES[p]).join(' and ')})`}`, {
|
|
|
|
|
heading: `${gone.map(g => g.domain).join(' and ')} ${gone.length === 1 ? 'is' : 'are'} uninstalled`,
|
|
|
|
|
sub: 'One thing left to do by hand.',
|
|
|
|
|
blocks: [
|
|
|
|
|
{ note: { kind: 'warning', title: 'Remove the FastPanel site', text: `${deployment.domain} (ports ${deployment.webPort} and ${deployment.apiPort}).` } },
|
|
|
|
|
...gone.map(g => ({ note: { kind: 'warning', title: 'Remove the FastPanel site', text: `${g.domain} (ports ${g.webPort} and ${g.apiPort}).` } })),
|
|
|
|
|
...(churchGone ? [{ p: `Nothing of ${deployment.shortName} is left on ${deployment.server?.name || 'the server'}: its folder and app user were removed too.` }] : []),
|
|
|
|
|
{ p: `The final backup is kept on the server for ${EXPORT_DAYS} days, then purged.` },
|
|
|
|
|
...jobReportBlocks(job),
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
await prisma.deployment.update({ where: { id: deployment.id }, data: { status: statusBeforeUninstall(deployment) } });
|
|
|
|
|
await uninstallNotRun(job, deployment);
|
|
|
|
|
await emailJoshua(`Uninstall failed: ${deployment.shortName}`, jobReport(job, `${deployment.domain} wasn't uninstalled`, 'The site is as it was.'));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
@@ -307,7 +319,7 @@ async function advanceBatch(job, now) {
|
|
|
|
|
// An uninstall that won't run (its export failed): the install is still there. Before 2.3.2 it
|
|
|
|
|
// stayed "uninstalling" for good.
|
|
|
|
|
if (j.deployment && j.type === 'uninstall') {
|
|
|
|
|
await prisma.deployment.update({ where: { id: j.deployment.id }, data: { status: statusBeforeUninstall(j.deployment) } });
|
|
|
|
|
await uninstallNotRun(j, j.deployment);
|
|
|
|
|
}
|
|
|
|
|
// Hub 2.5.0: the product after a failed Accounts install never ran: its record fails and its ports are freed.
|
|
|
|
|
if (j.deployment && (j.type === 'install' || j.type === 'add-product')) {
|
|
|
|
@@ -1234,7 +1246,7 @@ async function cancelJob(jobId, admin, now = new Date()) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (job.batchId) await advanceBatch(updated, now);
|
|
|
|
|
if (job.type === 'uninstall' && job.deployment) await prisma.deployment.update({ where: { id: job.deployment.id }, data: { status: statusBeforeUninstall(job.deployment) } });
|
|
|
|
|
if (job.type === 'uninstall' && job.deployment) await uninstallNotRun(job, job.deployment);
|
|
|
|
|
return updated;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1243,6 +1255,19 @@ function statusBeforeUninstall(d) {
|
|
|
|
|
return d.liveAt || d.installId ? 'live' : 'waiting_for_proxy';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An uninstall that failed or won't run: every install it named is still on the server (2.12.0:
|
|
|
|
|
* a run can name several products, when one was added to another's uninstall).
|
|
|
|
|
*/
|
|
|
|
|
async function uninstallNotRun(job, deployment) {
|
|
|
|
|
const products = job.args?.products;
|
|
|
|
|
const all = products ? [deployment, ...(await churchSiblings(deployment))] : [deployment];
|
|
|
|
|
for (const t of all) {
|
|
|
|
|
if (t.id !== deployment.id && (!products.includes(t.product) || t.status !== 'uninstalling')) continue;
|
|
|
|
|
await prisma.deployment.update({ where: { id: t.id }, data: { status: statusBeforeUninstall(t) } });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether an install never made it onto the server, so its record can simply be removed: its
|
|
|
|
|
* install failed (the server already removed what it made) and nothing is planned for it. Also
|
|
|
|
@@ -1268,36 +1293,170 @@ async function removeFailedInstall(deploymentId) {
|
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const agentAtLeast = (server, version) => compareVersions(server?.agentVersion || '0.0.0', version) >= 0;
|
|
|
|
|
|
|
|
|
|
/** The church's other products on the same server that are still there (2.12.0). */
|
|
|
|
|
function churchSiblings(d) {
|
|
|
|
|
return prisma.deployment.findMany({ where: { serverId: d.serverId, shortName: d.shortName, id: { not: d.id }, status: { notIn: ['removed', 'failed'] } }, include: { install: true, server: true, customer: true } });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An install is gone from its server: removed here, its ports freed (after 30 days, as for any
|
|
|
|
|
* uninstall), its licence's heartbeats refused, and what was still planned for it cancelled.
|
|
|
|
|
*/
|
|
|
|
|
async function markRemoved(d, now, { except = null, why = 'Not needed: the install is removed.' } = {}) {
|
|
|
|
|
await prisma.deployment.update({ where: { id: d.id }, data: { status: 'removed', removedAt: now } });
|
|
|
|
|
await prisma.port.updateMany({ where: { port: { in: [d.webPort, d.apiPort] } }, data: { releasedAt: now, deploymentId: d.id } });
|
|
|
|
|
if (d.installId) await prisma.install.update({ where: { id: d.installId }, data: { releasedAt: now } });
|
|
|
|
|
const open = await prisma.job.findMany({ where: { deploymentId: d.id, status: { in: ['scheduled', 'queued'] } } });
|
|
|
|
|
for (const j of open) {
|
|
|
|
|
if (j.id === except) continue;
|
|
|
|
|
await prisma.job.update({ where: { id: j.id }, data: { status: 'cancelled', message: why, finishedAt: now } });
|
|
|
|
|
if (j.noticeId) await endNotice(j.noticeId, now);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The church's uninstalls on this server that haven't run yet (2.12.0), soonest first: when, what
|
|
|
|
|
* they remove (`products` null: the whole church), and whether another product can still be added
|
|
|
|
|
* to the run (its export hasn't started).
|
|
|
|
|
*/
|
|
|
|
|
async function pendingUninstalls(d, siblings) {
|
|
|
|
|
const list = await prisma.job.findMany({ where: { type: 'uninstall', deploymentId: { in: [d.id, ...siblings.map(s => s.id)] }, status: { in: ['scheduled', 'queued'] } }, orderBy: { notBefore: 'asc' } });
|
|
|
|
|
const out = [];
|
|
|
|
|
for (const job of list) {
|
|
|
|
|
const exportJob = job.batchId ? await prisma.job.findFirst({ where: { batchId: job.batchId, type: 'export' } }) : null;
|
|
|
|
|
const products = job.args?.products || null;
|
|
|
|
|
const joinable = !!products && job.status === 'scheduled' && (!exportJob || ['scheduled', 'queued'].includes(exportJob.status));
|
|
|
|
|
out.push({ job, exportJob, products, joinable });
|
|
|
|
|
}
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* What an uninstall of this install would remove (for the install's page): only this product, or
|
|
|
|
|
* the whole church with an agent before 1.5.0 (then refused while there are others). `pending`:
|
|
|
|
|
* the church's uninstalls not run yet, which this one can join. `lastProduct`: every other product
|
|
|
|
|
* is being uninstalled, so (at its own, later time) this one takes the whole church with it.
|
|
|
|
|
*/
|
|
|
|
|
async function uninstallPlan(d) {
|
|
|
|
|
const others = await churchSiblings(d);
|
|
|
|
|
const pending = await pendingUninstalls(d, others);
|
|
|
|
|
return {
|
|
|
|
|
onlyThisProduct: agentAtLeast(d.server, agent.PRODUCT_UNINSTALL_MIN_AGENT),
|
|
|
|
|
minAgent: agent.PRODUCT_UNINSTALL_MIN_AGENT,
|
|
|
|
|
others: others.map(o => ({ id: o.id, product: o.product, domain: o.domain, status: o.status })),
|
|
|
|
|
pending: pending.map(p => ({ jobId: p.job.id, notBefore: p.job.notBefore, products: p.products, joinable: p.joinable })),
|
|
|
|
|
lastProduct: others.length > 0 && others.every(o => o.status === 'uninstalling'),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Hub 2.12.0: an install's record can be removed by hand once it's sent nothing for this long. */
|
|
|
|
|
const STALE_MS = DAY;
|
|
|
|
|
|
|
|
|
|
/** When the install was last heard from: its last heartbeat, else when it went live or was made. */
|
|
|
|
|
function lastHeardAt(d) {
|
|
|
|
|
return d.install?.lastHeartbeatAt || d.liveAt || d.createdAt || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Whether an install's record can be removed without an uninstall: no heartbeat for 24 hours. */
|
|
|
|
|
function staleness(d, now = new Date()) {
|
|
|
|
|
const since = lastHeardAt(d);
|
|
|
|
|
const stale = !['removed', 'failed', 'installing'].includes(d.status) && !!since && now - new Date(since) >= STALE_MS;
|
|
|
|
|
return { since, stale };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove an install from the Hub that's no longer on its server (uninstalled by hand, the server
|
|
|
|
|
* rebuilt …): nothing runs on the server. Only after 24 hours without a heartbeat, typing the short
|
|
|
|
|
* name; what was planned for it is cancelled.
|
|
|
|
|
*/
|
|
|
|
|
async function forgetStale(deploymentId, { confirm }, now = new Date()) {
|
|
|
|
|
const d = await prisma.deployment.findUnique({ where: { id: deploymentId }, include: { install: true } });
|
|
|
|
|
if (!d) throw fail(404, 'NOT_FOUND', 'Not found.');
|
|
|
|
|
if (confirm !== d.shortName) throw fail(400, 'CONFIRM', `Type ${d.shortName} to confirm.`);
|
|
|
|
|
if (!staleness(d, now).stale) throw fail(409, 'NOT_STALE', 'Only an install that hasn\'t sent a heartbeat for 24 hours can be removed from the Hub; a working one is uninstalled.');
|
|
|
|
|
const running = await prisma.job.count({ where: { deploymentId: d.id, status: 'delivered' } });
|
|
|
|
|
if (running) throw fail(409, 'BUSY', 'The agent is running a job for it: wait for its report.');
|
|
|
|
|
await markRemoved(d, now, { why: 'Not needed: the install was removed from the Hub (no heartbeat for 24 hours).' });
|
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Uninstall (§9): 2FA, typing the short name, at least 4 hours ahead. A batch of two: the export
|
|
|
|
|
* (encrypted, emailed to the site admin), then the uninstall, which only runs if the export worked.
|
|
|
|
|
*
|
|
|
|
|
* Hub 2.12.0: one product at a time (agent 1.5.0). When another product of the church is already
|
|
|
|
|
* planned for uninstall, `join` says what to do: true adds this product to that run (one export
|
|
|
|
|
* and one uninstall for both), false gives it its own batch at `at`. Not given: refused with
|
|
|
|
|
* CHOOSE, so the page asks. The script removes the whole church (folder, app user) when a run
|
|
|
|
|
* names every product it still has, so the last product to go always takes the church with it.
|
|
|
|
|
*/
|
|
|
|
|
async function scheduleUninstall({ deploymentId, at, totp, confirm }, admin, now = new Date()) {
|
|
|
|
|
async function scheduleUninstall({ deploymentId, at, totp, confirm, join, joinJobId }, admin, now = new Date()) {
|
|
|
|
|
requireTotp(admin, totp);
|
|
|
|
|
const d = await prisma.deployment.findUnique({ where: { id: deploymentId }, include: { install: true, server: true } });
|
|
|
|
|
const d = await prisma.deployment.findUnique({ where: { id: deploymentId }, include: { install: true, server: true, customer: true } });
|
|
|
|
|
if (!d) throw fail(404, 'NOT_FOUND', 'Not found.');
|
|
|
|
|
if (confirm !== d.shortName) throw fail(400, 'CONFIRM', `Type ${d.shortName} to confirm.`);
|
|
|
|
|
if (['removed', 'uninstalling'].includes(d.status)) throw fail(409, 'ALREADY', `It's already ${d.status}.`);
|
|
|
|
|
if (d.status === 'failed') throw fail(409, 'NOT_INSTALLED', 'Its install failed, so nothing of it is on the server: remove the record instead.');
|
|
|
|
|
if (d.status === 'installing') throw fail(409, 'BUSY', 'Wait until the install has finished.');
|
|
|
|
|
const when = new Date(at || now.getTime() + 7 * DAY);
|
|
|
|
|
if (when - now < SCHEDULE_MIN_HOURS * HOUR) throw fail(400, 'TOO_SOON', `An uninstall is planned at least ${SCHEDULE_MIN_HOURS} hours ahead.`);
|
|
|
|
|
const exportId = servers.newId('exp');
|
|
|
|
|
const batchId = servers.newId('batch');
|
|
|
|
|
const noticeId = await addNotice(d, { title: `${PRODUCT_NAMES[d.product]} is closing`, message: `This site closes on ${sast(when)}. Your admin gets a download of all your data by email first.`, endsAt: new Date(when.getTime() + 2 * HOUR), level: 'warning' }, now);
|
|
|
|
|
await prisma.export.create({ data: { id: exportId, deploymentId: d.id, expiresAt: new Date(when.getTime() + EXPORT_DAYS * DAY) } });
|
|
|
|
|
const exportJob = await makeJob(prisma, { serverId: d.serverId, type: 'export', deploymentId: d.id, createdById: admin.id, scheduled: true, batchId, batchOrder: 0, notBefore: when, args: { church: d.shortName, exportId } });
|
|
|
|
|
const uninstallJob = await makeJob(prisma, { serverId: d.serverId, type: 'uninstall', deploymentId: d.id, createdById: admin.id, scheduled: true, batchId, batchOrder: 1, status: 'scheduled', notBefore: when, noticeId, args: { church: d.shortName } });
|
|
|
|
|
// Only this product goes (agent 1.5.0). An older agent removes the whole church, so it's refused
|
|
|
|
|
// while the church has other products on the server.
|
|
|
|
|
const siblings = await churchSiblings(d);
|
|
|
|
|
const onlyThis = agentAtLeast(d.server, agent.PRODUCT_UNINSTALL_MIN_AGENT);
|
|
|
|
|
if (!onlyThis && siblings.length) {
|
|
|
|
|
throw fail(409, 'AGENT_TOO_OLD', `The agent on ${d.server.name} is ${d.server.agentVersion || 'an unknown version'}: it would remove all of ${d.shortName} (${[d, ...siblings].map(x => PRODUCT_NAMES[x.product]).join(' and ')}). Update the agent to ${agent.PRODUCT_UNINSTALL_MIN_AGENT} or later to uninstall only ${PRODUCT_NAMES[d.product]}.`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Another product's uninstall that hasn't run yet: join it, or a time of its own.
|
|
|
|
|
const pending = await pendingUninstalls(d, siblings);
|
|
|
|
|
const whole = pending.find(p => !p.products);
|
|
|
|
|
if (whole) throw fail(409, 'ALREADY', `${PRODUCT_NAMES[d.product]} already goes with the uninstall of all of ${d.shortName} on ${sast(whole.job.notBefore)}.`);
|
|
|
|
|
if (pending.length && join === undefined) {
|
|
|
|
|
const first = pending[0];
|
|
|
|
|
throw Object.assign(fail(409, 'CHOOSE', `${first.products.map(p => PRODUCT_NAMES[p]).join(' and ')} of ${d.shortName} is already being uninstalled on ${sast(first.job.notBefore)}: add ${PRODUCT_NAMES[d.product]} to that, or give it its own time.`), { details: { jobId: first.job.id, notBefore: first.job.notBefore } });
|
|
|
|
|
}
|
|
|
|
|
const target = join ? pending.find(p => (joinJobId ? p.job.id === joinJobId : true) && p.joinable) : null;
|
|
|
|
|
if (join && !target) throw fail(409, 'NOT_JOINABLE', 'That uninstall has already started (its export ran): give this one its own time.');
|
|
|
|
|
const when = target ? target.job.notBefore : new Date(at || now.getTime() + 7 * DAY);
|
|
|
|
|
// The church gets at least 4 hours' notice, also when this joins a run planned earlier.
|
|
|
|
|
if (when - now < SCHEDULE_MIN_HOURS * HOUR) throw fail(400, 'TOO_SOON', target ? `That uninstall is less than ${SCHEDULE_MIN_HOURS} hours away, too soon to tell the church: give this one its own time.` : `An uninstall is planned at least ${SCHEDULE_MIN_HOURS} hours ahead.`);
|
|
|
|
|
|
|
|
|
|
// The church's other products sign in through Accounts: it goes last (or in the same run).
|
|
|
|
|
if (d.product === 'accounts' && siblings.length) {
|
|
|
|
|
const staying = siblings.filter(s => s.status !== 'uninstalling');
|
|
|
|
|
if (staying.length) throw fail(409, 'ACCOUNTS_IN_USE', `${staying.map(s => PRODUCT_NAMES[s.product]).join(' and ')} of ${d.shortName} sign${staying.length === 1 ? 's' : ''} in through Accounts: uninstall ${staying.length === 1 ? 'it' : 'them'} first, then Accounts.`);
|
|
|
|
|
const later = pending.filter(p => p.job.notBefore > when).pop();
|
|
|
|
|
if (later) throw fail(400, 'ACCOUNTS_FIRST', `Accounts goes after the church's other products: plan it for ${sast(later.job.notBefore)} or later, or add it to that uninstall.`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let exportJob;
|
|
|
|
|
let uninstallJob;
|
|
|
|
|
if (target) {
|
|
|
|
|
// One run for both: the export and the uninstall name every product, in deploy order.
|
|
|
|
|
const products = [...new Set([...target.products, d.product])].sort((a, b) => PRODUCT_ORDER.indexOf(a) - PRODUCT_ORDER.indexOf(b));
|
|
|
|
|
uninstallJob = await prisma.job.update({ where: { id: target.job.id }, data: { args: agent.jobArgsSchemas.uninstall.parse({ ...target.job.args, products }) } });
|
|
|
|
|
exportJob = target.exportJob ? await prisma.job.update({ where: { id: target.exportJob.id }, data: { args: agent.jobArgsSchemas.export.parse({ ...target.exportJob.args, products }) } }) : null;
|
|
|
|
|
await addNotice(d, { title: `${PRODUCT_NAMES[d.product]} is closing`, message: `This site closes on ${sast(when)}. Your admin gets a download of all your data by email first.`, endsAt: new Date(when.getTime() + 2 * HOUR), level: 'warning' }, now);
|
|
|
|
|
} else {
|
|
|
|
|
const products = onlyThis ? { products: [d.product] } : {};
|
|
|
|
|
const exportId = servers.newId('exp');
|
|
|
|
|
const batchId = servers.newId('batch');
|
|
|
|
|
const noticeId = await addNotice(d, { title: `${PRODUCT_NAMES[d.product]} is closing`, message: `This site closes on ${sast(when)}. Your admin gets a download of all your data by email first.`, endsAt: new Date(when.getTime() + 2 * HOUR), level: 'warning' }, now);
|
|
|
|
|
await prisma.export.create({ data: { id: exportId, deploymentId: d.id, expiresAt: new Date(when.getTime() + EXPORT_DAYS * DAY) } });
|
|
|
|
|
exportJob = await makeJob(prisma, { serverId: d.serverId, type: 'export', deploymentId: d.id, createdById: admin.id, scheduled: true, batchId, batchOrder: 0, notBefore: when, args: { church: d.shortName, exportId, ...products } });
|
|
|
|
|
uninstallJob = await makeJob(prisma, { serverId: d.serverId, type: 'uninstall', deploymentId: d.id, createdById: admin.id, scheduled: true, batchId, batchOrder: 1, status: 'scheduled', notBefore: when, noticeId, args: { church: d.shortName, ...products } });
|
|
|
|
|
}
|
|
|
|
|
await prisma.deployment.update({ where: { id: d.id }, data: { status: 'uninstalling' } });
|
|
|
|
|
await emailSiteAdmin(d, `${PRODUCT_NAMES[d.product]} at ${d.domain} closes on ${sast(when)}`, {
|
|
|
|
|
heading: `${PRODUCT_NAMES[d.product]} is closing`,
|
|
|
|
|
blocks: [
|
|
|
|
|
{ p: `As agreed, ${PRODUCT_NAMES[d.product]} at ${d.domain} will be closed.` },
|
|
|
|
|
{ rows: [['Site', d.domain], ['Closes on', sast(when)]] },
|
|
|
|
|
{ note: { kind: 'info', title: 'Your data', text: `Shortly before, you'll get an email with a link to download all your data (events, people, registrations, payments and files). The link works for ${EXPORT_DAYS} days.` } },
|
|
|
|
|
{ note: { kind: 'info', title: 'Your data', text: `Shortly before, ${target ? 'the church\'s site admin gets' : 'you\'ll get'} an email with a link to download all the data (events, people, registrations, payments and files). The link works for ${EXPORT_DAYS} days.` } },
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
return { exportJob, uninstallJob };
|
|
|
|
|
return { exportJob, uninstallJob, joined: !!target, lastProduct: siblings.every(s => s.status === 'uninstalling') };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** An agent's encrypted export (PUT /api/agent/v1/exports/:id). */
|
|
|
|
@@ -1468,6 +1627,6 @@ module.exports = {
|
|
|
|
|
readEnv, setEnv, envState, readFrp, writeFrp, portsProbed, probeServers, PROBE_SPARE,
|
|
|
|
|
WINDOW_MIN, SCHEDULE_MIN_HOURS, EMERGENCY_MIN_MINUTES, setDemo, seedDemo,
|
|
|
|
|
makeJob, signedJob, jobConfig, poll, receiveReport, finish, tick, advanceBatch,
|
|
|
|
|
JOB_STATUSES, linkFromStatus, listWhere, lookForUnlinked, newInstall, proxyDone, scheduleUpdate, cancelJob, scheduleUninstall, neverInstalled, removeFailedInstall, receiveExport, linkDeployment, scheduleAdopt, queueCentralCheck, runNow,
|
|
|
|
|
JOB_STATUSES, linkFromStatus, listWhere, lookForUnlinked, newInstall, proxyDone, scheduleUpdate, cancelJob, scheduleUninstall, neverInstalled, removeFailedInstall, staleness, forgetStale, uninstallPlan, STALE_MS, receiveExport, linkDeployment, scheduleAdopt, queueCentralCheck, runNow,
|
|
|
|
|
fastPanelText, fastPanelSteps, notesBlocks, jobReportText, scheduleWarnings, requireTotp, agentOnline, siteAdminEmail,
|
|
|
|
|
};
|
|
|
|
|