import * as dotenv from 'dotenv'; dotenv.config(); /** * The shared calendar passwords, and nothing else. * * Before the step 4 cutover each function here also took a sessionId/sessionKey * pair and checked it against the calendar's own sessions table, so "is this a * signed-in user?" and "did they send the right shared password?" were tangled * together in five places. Signed-in access is now decided by * requireAppAccess('calendar') before the handler runs; what is left is the * fallback for people who have no account at all. * * That fallback survives on purpose, for one reason: an iCal client subscribing * to a calendar URL cannot send a cookie. Everything the Angular app does goes * through the session cookie instead. See docs/calendar-auth-migration.md. * * `public` is deliberately open to everyone with no credential of any kind - * nachklang.art reads it anonymously to show the next upcoming event. Pinned by * test/calendar/credentials.service.test.ts. */ /** * The shared password for a calendar, or undefined for `public` (which needs * none), an unknown calendar, or one whose credential is not configured. * Exported for the subscriptions endpoint, which hands signed-in editors the * ready-made iCal URLs - see GET /calendar/events/subscriptions. */ export const credentialFor = (calendarName: string): string | undefined => { switch (calendarName) { case 'members': return process.env.MEMBER_CREDENTIAL; case 'choir': case 'birthdays': return process.env.CHOIR_CREDENTIAL; case 'management': return process.env.MANAGEMENT_CREDENTIAL; default: return undefined; } }; /** * Whether the given shared password opens the given calendar. Answers false * for an unknown calendar, and - importantly - for a calendar whose credential * is not configured at all: an unset MEMBER_CREDENTIAL must not turn into * "everyone with an empty password gets in". */ export const hasAccess = async (calendarName: string, password: string): Promise => { if (calendarName === 'public') { return true; } const expected = credentialFor(calendarName); if (!expected) { return false; } return password === expected; };