Archived
Serving roles per event or session, sign-ups and assigning with an overlap check, swaps that happen on accept (notify recipients emailed), QR and manual check-in (kids-room roles start rostered duty), optional free volunteer ticket, day-before reminder job, hours served, privacy hooks. The kids check-in and volunteer tickets are left out of public event pages and public registration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.8 KiB
JavaScript
59 lines
2.8 KiB
JavaScript
/**
|
|
* Read-only mode while the licence is suspended, revoked or missing (not connected to the Hub):
|
|
* no new or edited events, and no *new* activity — registrations, tickets added, payments started
|
|
* or recorded, waitlist places, coupons or bundles.
|
|
* Everything else keeps working on purpose: scanning tickets for events people already paid for,
|
|
* viewing and exporting data, refunds and cancellations, privacy requests, logging in, and the
|
|
* settings needed to renew the licence. Payment webhooks for payments already started also still
|
|
* arrive (they're mounted before this middleware).
|
|
*/
|
|
|
|
const { licenceStatus } = require('./licence');
|
|
|
|
const BLOCKED = [
|
|
['POST', /^\/api\/events\/?$/],
|
|
['PUT', /^\/api\/events\/[^/]+\/?$/],
|
|
['POST', /^\/api\/events\/[^/]+\/options\/?$/],
|
|
['PUT', /^\/api\/events\/options\/[^/]+\/?$/],
|
|
['POST', /^\/api\/events\/options\/[^/]+\/variants\/?$/],
|
|
['PUT', /^\/api\/events\/variants\/[^/]+\/?$/],
|
|
['POST', /^\/api\/registrations\/?$/],
|
|
['POST', /^\/api\/registrations\/manual\/?$/],
|
|
['PUT', /^\/api\/registrations\/[^/]+\/options\/?$/],
|
|
['POST', /^\/api\/payments\/?$/],
|
|
['POST', /^\/api\/payments\/(checkout|yoco-checkout)(\/send)?\/?$/],
|
|
['POST', /^\/api\/payments\/pay\/[^/]+\/?$/],
|
|
['POST', /^\/api\/waitlist\/?$/],
|
|
['POST', /^\/api\/coupons\/?$/],
|
|
['POST', /^\/api\/bundles\/event\/[^/]+\/?$/],
|
|
// Volunteer rosters: new roles and new people on them (they can carry a free ticket).
|
|
['POST', /^\/api\/volunteers\/roles\/[^/]+\/sign-up\/?$/],
|
|
['POST', /^\/api\/volunteers\/manage\/events\/[^/]+\/roles\/?$/],
|
|
['POST', /^\/api\/volunteers\/manage\/roles\/[^/]+\/assign\/?$/],
|
|
];
|
|
|
|
function isBlocked(method, path) {
|
|
return BLOCKED.some(([m, re]) => m === method && re.test(path));
|
|
}
|
|
|
|
async function licenceReadOnly(req, res, next) {
|
|
if (!isBlocked(req.method, req.path)) return next();
|
|
try {
|
|
const status = await licenceStatus();
|
|
if (!status.readOnly) return next();
|
|
return res.status(403).json({
|
|
code: 'LICENCE_READ_ONLY',
|
|
message: status.state === 'revoked'
|
|
? "This site's licence has been revoked, so nothing new can be added and events can't be changed. Tickets still scan and all data can still be viewed and exported."
|
|
: status.state === 'unlicensed'
|
|
? "This site has no licence, so nothing new can be added and events can't be changed. A site admin can connect a licence key in Site settings → Licence."
|
|
: "This site's licence is suspended, so nothing new can be added and events can't be changed for now. Tickets still scan and all data can still be viewed and exported. Please contact the site's administrator.",
|
|
});
|
|
} catch {
|
|
// Never let a licence check failure take the site down.
|
|
return next();
|
|
}
|
|
}
|
|
|
|
module.exports = { licenceReadOnly, isBlocked, BLOCKED };
|