Hub 2.22.0: Get more storage for the Church Website
POST /api/installs/storage-request (contracts 1.18.0): recorded on the install, Joshua emailed once, closed when the licence gets more extra storage steps. The church is emailed once when its website's storage passes 80% and once when it's full (from the heartbeat). Vendors contracts 1.18.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@ const { compareVersions } = require('../utils/alerts');
|
||||
const { requestMessage, requestedVersionOf, isOutdated } = require('../utils/updateRequests');
|
||||
const { sendMail } = require('../utils/mail');
|
||||
const { render } = require('../utils/emailLayout');
|
||||
const storage = require('../utils/storage');
|
||||
|
||||
/** An update-request email to Joshua (2.10.0: laid out as the Hub's other emails). */
|
||||
const updateRequestEmail = ({ heading, note, rows, link }) => render({
|
||||
@@ -248,6 +249,15 @@ router.post('/installs/heartbeat', heartbeatLimiter, async (req, res) => {
|
||||
await prisma.installEvent.updateMany({ where: { installId: install.id, type: 'update_requested', resolvedAt: null }, data: { resolvedAt: now } });
|
||||
}
|
||||
}
|
||||
// Hub 2.22.0: a Website's storage at 80% or full emails the church once (decision 12).
|
||||
if (install.product === 'website' && stats) {
|
||||
try {
|
||||
const withCustomer = await prisma.install.findUnique({ where: { id: install.id }, include: { customer: true } });
|
||||
await storage.storageLevels(prisma, withCustomer || install, stats, { sendMail, now });
|
||||
} catch (e) {
|
||||
console.warn('[storage] checking the storage level failed:', e?.message || e);
|
||||
}
|
||||
}
|
||||
|
||||
const publicKeyStatus = v2 && body.publicKey ? await acceptPublicKey(install, body.publicKey, now) : null;
|
||||
|
||||
@@ -265,6 +275,25 @@ router.post('/installs/heartbeat', heartbeatLimiter, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Hub 2.22.0 (contracts 1.18.0): a Website's Owner or Admin pressed "Get more storage". Recorded on
|
||||
// the install and emailed to Joshua once per request; it closes when the licence gets more steps.
|
||||
router.post('/installs/storage-request', updateRequestLimiter, async (req, res) => {
|
||||
try {
|
||||
const install = await signedInstall(req, res);
|
||||
if (!install) return;
|
||||
if (install.product !== 'website') return fail(res, 409, 'WRONG_PRODUCT', 'Only a Church Website has storage to add.');
|
||||
const body = bodyFor(req, res, hub.storageRequestSchema);
|
||||
if (!body) return;
|
||||
const settings = await getSettings();
|
||||
const withCustomer = await prisma.install.findUnique({ where: { id: install.id }, include: { customer: true } });
|
||||
const reply = await storage.storageRequested(prisma, withCustomer || install, body, { alertEmail: settings.alert_email, sendMail });
|
||||
res.status(reply.alreadyRequested ? 200 : 201).json(reply);
|
||||
} catch (e) {
|
||||
console.error('[storage-request]', e);
|
||||
fail(res, 500, 'SERVER_ERROR', 'The Hub could not record the request. Try again later.');
|
||||
}
|
||||
});
|
||||
|
||||
// A site admin pressed "Request update": open an alert (emailed once) until the install reports a
|
||||
// newer version. Asking again while a request is open doesn't email again.
|
||||
router.post('/installs/update-request', updateRequestLimiter, async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user