Archived
- /api (v1) answers 410 API_V1_REMOVED, except provider webhooks (/api/webhooks/*, /api/whatsapp/webhook) and links in sent messages (308s, one-click POST). 43 v1 route files and deprecation.ts removed; /docs redirects to /docs/v2; API_DOCUMENTATION.md points there. - Read-only and impersonation lists name v2 paths only. The campus scope route test now runs over v2 routes (v2CampusScope.test.ts). - Passwords hashed with Argon2id (@node-rs/argon2); bcrypt hashes still sign in and are re-hashed at the next sign-in. - e2e on /api/v2 only (v2() helper); Playwright waits on /api/v2. - MIGRATING-TO-2.md with the full v1 -> v2 table. - Two documented response shapes corrected. Backend 690 tests and e2e 102/102 (PayFast sandbox skipped) pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
3.1 KiB
JavaScript
65 lines
3.1 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');
|
|
|
|
// /api/v2 only: 2.0 removed v1 (1.52.3 added these — the screens had used v2 since 1.51.15).
|
|
const BLOCKED = [
|
|
['POST', /^\/api\/v2\/events\/?$/],
|
|
['PATCH', /^\/api\/v2\/events\/[^/]+\/?$/],
|
|
['POST', /^\/api\/v2\/events\/[^/]+\/copy-from\/?$/],
|
|
['POST', /^\/api\/v2\/series\/?$/],
|
|
['PATCH', /^\/api\/v2\/series\/[^/]+\/?$/],
|
|
['POST', /^\/api\/v2\/season-passes\/?$/],
|
|
['PATCH', /^\/api\/v2\/season-passes\/[^/]+\/?$/],
|
|
['POST', /^\/api\/v2\/season-passes\/[^/]+\/buy\/?$/],
|
|
['POST', /^\/api\/v2\/season-pass-purchases\/[^/]+\/checkout\/?$/],
|
|
['POST', /^\/api\/v2\/events\/[^/]+\/ticket-options\/?$/],
|
|
['PATCH', /^\/api\/v2\/ticket-options\/[^/]+\/?$/],
|
|
['POST', /^\/api\/v2\/ticket-options\/[^/]+\/variants\/?$/],
|
|
['PATCH', /^\/api\/v2\/variants\/[^/]+\/?$/],
|
|
['POST', /^\/api\/v2\/registrations\/?$/],
|
|
['POST', /^\/api\/v2\/registrations\/manual\/?$/],
|
|
['PUT', /^\/api\/v2\/registrations\/[^/]+\/items\/?$/],
|
|
['POST', /^\/api\/v2\/payments\/?$/],
|
|
['POST', /^\/api\/v2\/registrations\/[^/]+\/(checkout|payment-link(\/send)?)\/?$/],
|
|
['POST', /^\/api\/v2\/payment-links\/[^/]+\/?$/],
|
|
['POST', /^\/api\/v2\/waitlist\/?$/],
|
|
['POST', /^\/api\/v2\/coupons\/?$/],
|
|
['POST', /^\/api\/v2\/events\/[^/]+\/bundles\/?$/],
|
|
['POST', /^\/api\/v2\/volunteer-roles\/[^/]+\/(sign-up|assign)\/?$/],
|
|
['POST', /^\/api\/v2\/events\/[^/]+\/volunteer-roles\/?$/],
|
|
];
|
|
|
|
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 };
|