Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 81 additions & 11 deletions docs/features/discord.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/features/hackathons.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Steps, with the procedure that does each (under `trpc.hackathon.*` unless noted)
The Ramadan fasting answer (`ramadanFasting`) is optional on the server: the form asks it only when the event's dates overlap Ramadan (`overlapsRamadan` in `sites/mainweb/lib/ramadan.ts`, Umm al-Qura calendar on the venue's days) and sends nothing otherwise, so the column is empty for those events.
3. **Edit or leave.** `updateMyRegistration` edits answers (consent fields are not re-sent) and only works while the edition is `open`, before the deadline, and while the participant is still `pending`. `withdrawRegistration` takes the registration back, but is refused once the person is on a team, checked in, or has a project, because that affects others, and once the edition is `completed` or `cancelled`.
4. **Decision.** An organizer accepts, rejects or waitlists (see Acceptance below). `checked_in` can only be reached from `approved`.
5. **Confirm.** `confirmAttendance` lets an accepted hacker say they are coming. It stamps `attendance_confirmed_at` once, so organizers can free the seats of people who never answer.
5. **Confirm.** `confirmAttendance` lets an accepted hacker say they are coming. It stamps `attendance_confirmed_at` once, so organizers can free the seats of people who never answer. It also opens the [Discord](./discord.md) step: an accepted hacker cannot link until they have answered.
6. **Check in.** The first event scan or desk admit moves `approved` to `checked_in` and stamps `checked_in_at`. See Hackathon events and check-in.
7. **Team.** `createTeam`, `joinTeam`, `leaveTeam`, `disbandTeam` and `setOpen` live in `packages/api/src/routers/team.ts` and need an accepted participant (`approved` or `checked_in`), so teams can form before check-in. The team window closes 34 hours after hacking starts. Leave and disband are refused within 12 hours of the submission deadline.
8. **Submit.** `submitProject` (same router) requires `checked_in`. Submissions open 12 hours after hacking starts, close at 36 and edits close at 34. Times count from `hacking_start_time`, else `start_date`. Solo entries are allowed. `withdrawProject`, `mySubmission` and `submissionWindow` are in the same file. How submissions become judging entries is covered in [Judging](../judging/README.md).
Expand All @@ -60,7 +60,7 @@ It sends at most 200 a run, oldest first, with the Hacklytics look for editions

### Reminder setup

App Hosting has no scheduler, so a daily job posts to `POST /api/cron/application-reminders` with `Authorization: Bearer <CRON_SECRET>`. The job is Cloud Scheduler, set up separately; nothing in the repository triggers it yet. The route answers 404 when `CRON_SECRET` is unset (so it does nothing until then), 401 on a wrong token, 429 past 10 calls an hour from one address, and 200 with `{ claimed, sent, failed }`. The same secret has to be in App Hosting and in the scheduler job. Once:
App Hosting has no scheduler, so a daily job posts to `POST /api/cron/application-reminders` with `Authorization: Bearer <CRON_SECRET>`. The job is Cloud Scheduler, set up separately; nothing in the repository triggers it yet. The route answers 404 when `CRON_SECRET` is unset (so it does nothing until then), 401 on a wrong token, 429 past 10 calls an hour from one address, and 200 with `{ claimed, sent, failed }`. The same secret has to be in App Hosting and in the scheduler job. Once: The same daily run also finishes Discord role changes still pending and takes the volunteer role back from volunteers whose term has ended, capped at 15 people and 20 seconds a run (see [Discord](./discord.md#taking-roles-back)).

1. Generate a value: `node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"`.
2. `firebase apphosting:secrets:set CRON_SECRET` and paste it, then `firebase apphosting:secrets:grantaccess CRON_SECRET --backend query`.
Expand Down
1 change: 1 addition & 0 deletions docs/operations/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This page is the map of controls already in the product. It is not a pentest rep
- Email code requests are capped in the database per client network, per email domain, per address and for the whole deployment. A request any cap refuses is answered as busy, never as sent (see [email](../features/email.md#sign-in-codes-are-separate))
- `allowDangerousEmailAccountLinking` is on so Google/Discord can attach to an existing verified email. That is why CSRF on the OAuth callback must stay on, and why Discord sign-in is refused unless Discord marks the email `verified`
- Redirect callback only allows same-origin URLs
- Discord Linked Roles keep the person's OAuth tokens, encrypted with AES-256-GCM under a key derived from `AUTH_SECRET` (HKDF, its own label, bound to the person), so a role can be taken back when a judge, volunteer or hacker loses it. They are never logged or returned. See [Discord link](../features/discord.md#taking-roles-back)

## Authorization

Expand Down
2 changes: 1 addition & 1 deletion docs/packages/db.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Files in `src/schemas/`, re-exported from `schemas/index.ts`. `drizzle.config.ts
| `auth.ts` | `user`, `account`, `session`, `verificationToken` |
| `members.ts` | `user_profile`, `member`, `membership_history` |
| `admins.ts` | `admin` |
| `hackathons.ts` | `hackathon`, `hackathon_team`, `hackathon_participant`, `hackathon_project`, `hackathon_interest`, `hackathon_event`, `hackathon_event_attendee`, `hackathon_check_in_flag`, `hackathon_announcement`, `hackathon_announcement_recipient` |
| `hackathons.ts` | `hackathon`, `hackathon_team`, `hackathon_participant`, `hackathon_project`, `hackathon_interest`, `hackathon_event`, `hackathon_event_attendee`, `hackathon_check_in_flag`, `hackathon_announcement`, `hackathon_announcement_recipient`, `discord_link` |
| `judge.ts` | `judge`, `judge_assignment` (live roster); `judging_project`, `judge_vote`, `hackathon_result` (retired, kept for past editions) |
| `judging.ts` | `judging_*`: config, entries and members, challenges, buildings, rooms and room links, judges, guest sessions, presence, schedule and appointments, rubric, evaluations, deliberation, placements, repo checks |
| `points.ts` | `hackathon_point_adjustment`, `hackathon_store_item`, `hackathon_store_purchase` |
Expand Down
51 changes: 51 additions & 0 deletions packages/api/src/.internal-tests/application-drafts.db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@ const mailed = vi.hoisted(() => ({
deadline?: Date | null;
}[],
refuse: new Set<string>(),
/** While set, a mail waits here before it counts as sent. */
hold: undefined as Promise<void> | undefined,
inFlight: 0,
}));
vi.mock("@query/auth/email", () => ({
sendAcceptanceEmail: vi.fn(async () => {}),
sendApplicationReminderEmail: vi.fn(
async (message: (typeof mailed.calls)[number]) => {
mailed.inFlight++;
try {
await mailed.hold;
} finally {
mailed.inFlight--;
}
if (mailed.refuse.has(message.email)) throw new Error("550 mailbox full");
mailed.calls.push(message);
},
Expand Down Expand Up @@ -138,6 +147,7 @@ describe.skipIf(!URL)("application drafts against a real database", () => {
beforeEach(() => {
mailed.calls.length = 0;
mailed.refuse.clear();
mailed.hold = undefined;
});

afterAll(async () => {
Expand Down Expand Up @@ -499,6 +509,47 @@ describe.skipIf(!URL)("application drafts against a real database", () => {
expect(a.claimed + b.claimed + c.claimed).toBe(mailed.calls.length);
}, 60_000);

it("a Scheduler retry while the first run is still mailing sends nothing twice, because the claim comes first", async () => {
const h = await makeHackathon("rem-retry");
const addresses: string[] = [];
const ids: string[] = [];
for (let i = 0; i < 5; i++) {
const id = await makeUser(`retry${i}`);
await plantDraft(id, h.id, NOW, 4);
addresses.push(email(`retry${i}`));
ids.push(id);
}

// The mailer is slow, so the first run is mid-send when the retry arrives.
let release!: () => void;
mailed.hold = new Promise<void>((resolve) => {
release = resolve;
});
const first = run(NOW);
await vi.waitFor(() => expect(mailed.inFlight).toBe(5));

// Nothing has left yet, and every draft is already stamped as taken.
expect(mailedTo(addresses)).toEqual([]);
for (const id of ids) {
expect((await draftRow(id, h.id))?.reminderSentAt).not.toBeNull();
}

const retry = await run(new Date(NOW.getTime() + 60_000));
expect(retry).toEqual({ claimed: 0, sent: 0, failed: 0 });
expect(mailedTo(addresses)).toEqual([]);

release();
expect(await first).toEqual({ claimed: 5, sent: 5, failed: 0 });
expect([...mailedTo(addresses)].sort()).toEqual([...addresses].sort());
// And a retry after it finished has nothing left either.
expect(await run(new Date(NOW.getTime() + 120_000))).toEqual({
claimed: 0,
sent: 0,
failed: 0,
});
expect(mailedTo(addresses)).toHaveLength(5);
}, 30_000);

it("re-checks a draft it had to wait for, so one taken or edited meanwhile is not mailed", async () => {
const h = await makeHackathon("rem-lock");
const taken = await makeUser("lock-taken");
Expand Down
Loading
Loading