Fixes & Refinements: QR token on registration, role caps, connection detail + red dot, admin schedule/sponsors

Datamodel:
- Move qr_token from contacts to registrations (per event); new migration
  20260826000000. lanyard_lookup / create_connection_request / checkin_attendee
  resolve via registrations + active event.
- reset_qr_token -> reset_registration_qr_token (fixes ambiguous 'email' col).
- upsert_contact drops the token arg; create_registration generates + syncs it.
- Pretix sync writes the token to the registration (keeps it on re-sync).

Registration types:
- Distinct pill colors; red reserved for Staff (both apps).
- Roles capitalized everywhere (Attendee/Speaker/Sponsor/Staff); 'Attendee'
  hidden only at the Home footer.
- Reset-token button moved from Contacts to Registrations (per registration).

Sessions (APPE Admin):
- Slot types capitalized; material submitted/not-submitted state.
- Speaker selection = multi-select search dropdown.
- Fix 'a session must have a speaker' on edit (diff-based setSessionSpeakers)
  and the file-upload bug (speaker save no longer aborts first).

APPE Admin:
- Sponsors contact lookup = search field (filter + pick).

Convivo App:
- Other people's QR codes hidden; connection detail sheet shows public info +
  points.
- Connect red dot recalculates immediately on accept/decline/send.
- 'My picks today' = 2 rows (current + next); 'tap to change' links to Agenda.

Docs updated across backend + frontend.
This commit is contained in:
Lago committed 2026-08-23 10:39:21 +02:00
1 parent 005f1d404f
commit b52d8ab007
30 files changed
+1083 -232

No files matched your search

+10 -7
View File
@@ -98,15 +98,18 @@ Input: a JSON array of
`{ email, full_name, ticket_type, qr_token?, linkedin_url?, external_id? }`.
For each item:
- **Upsert the contact** by `email`. Keeps the existing QR token unless a new
one is supplied; **generates a token** (`CVV-XXX-NNNN`) for new ticket holders
(Pretix doesn't provide one) so they can log in.
- **Ensure the auth user** exists (`_ensure_auth_user` — QR token = password).
- **Upsert the contact** by `email` (no token on the contact).
- **Map the ticket type** to a registration type via `_map_ticket_type`
(case-insensitive substring: `speaker` / `staff` / `sponsor`, else `attendee`).
- **Auto-create a sponsor row** if the type is `sponsor` (the sponsor rule
requires a sponsor lookup).
- **Upsert the registration** for the active event (by contact).
- **Upsert the registration** for the active event (by contact). The **QR token
lives on the registration**: it keeps the existing token unless a new one is
supplied (so a re-sync never invalidates a lanyard), and **generates a token**
(`CVV-XXX-NNNN`) for new ticket holders (Pretix doesn't always provide one) so
they can log in.
- **Ensure the auth user** exists and **sync the token as the Auth password**
(QR token = password).
Returns `{ created, updated, skipped, errors[] }`.
@@ -114,7 +117,7 @@ Returns `{ created, updated, skipped, errors[] }`.
Input: a JSON array of
`{ external_id, title, description?, room?, capacity?, date, start_time, end_time,
speakers: [{ email, full_name, qr_token? }] }`.
speakers: [{ email, full_name }] }`.
For each item:
- **Find or create the slot** by `(event, date, start, end)` (new slots get an
@@ -146,7 +149,7 @@ Interfaces view shows the last 8 runs.
| `attendee_name` | `contacts.full_name` |
| `ticket_type` | `registrations.type` (via `_map_ticket_type`) |
| `order_code` | `contacts.external_id` + `registrations.external_id` |
| *(generated)* | `contacts.qr_token` (for new ticket holders) |
| `qr_token` / *(generated)* | `registrations.qr_token` (Pretix per-ticket, or generated for new holders) |
| Sessionize field | → Convivo |
|---|---|
+20 -7
View File
@@ -125,28 +125,41 @@ Used by the APPE Admin console to award prizes or correct mistakes. Goes through
`_award_points`, so it floors at 0, writes `points_log`, and re-syncs the
leaderboard.
### `reset_qr_token(p_contact_email)` → `(email, qr_token)`
**Admin-only.** Regenerates a contact's lanyard QR token.
- Generates a fresh `CVV-XXX-NNNN` token and writes it to `contacts.qr_token`.
### `reset_registration_qr_token(p_contact_email)` → `(email, qr_token)`
**Admin-only.** Regenerates the lanyard QR token of a contact's **registration**
for the active event (the token lives on the registration, not the contact).
- Requires the contact to have a registration for the active event.
- Generates a fresh `CVV-XXX-NNNN` token and writes it to
`registrations.qr_token`.
- **Re-hashes it as the Auth password** (`extensions.crypt(token,
extensions.gen_salt('bf'))` on `auth.users.encrypted_password`), so the **old
token stops working** and the contact must re-scan with the new one.
- **Deletes the contact's existing `auth.sessions`**, forcing a re-login.
- Returns the new token so the admin can print/show it as a QR code.
> **Implementation note:** the function's output column is named `email`
> (`returns table (email, qr_token)`), so any reference to `auth.users.email`
> inside the body must be **qualified** (`auth.users.email`) — a bare `email`
> is ambiguous between the output column and the table column.
> **Implementation note:** pgcrypto's `gen_salt` / `crypt` live in the
> `extensions` schema (not `public`), so the function — whose `search_path` is
> pinned to `public` — must qualify them as `extensions.gen_salt(...)` /
> `extensions.crypt(...)`. The function owner (`postgres`) can write
> `auth.users` and `auth.sessions`, which is what makes this possible.
### `upsert_contact(p_email, p_full_name, p_linkedin_url, p_is_admin, p_qr_token)` → `contacts`
**Admin-only.** Creates a contact if it doesn't exist (generating a QR token when
none is given) or updates the existing one. Returns the contact row.
### `upsert_contact(p_email, p_full_name, p_linkedin_url, p_is_admin)` → `contacts`
**Admin-only.** Creates a contact if it doesn't exist or updates the existing
one. Contacts carry **no QR token** — the token is generated when a registration
is created. Ensures an `auth.users` row exists (with a placeholder password) so
the contact can log in once a registration token is issued. Returns the contact
row.
### `create_registration(p_contact_email, p_type)` → `registrations`
**Admin-only.** Creates a registration for the active event (enforces the
sponsor-type rule).
sponsor-type rule). **Generates a `CVV-XXX-NNNN` token** on the registration and
**syncs it as the Auth password**, so a newly registered contact can log in
immediately.
### `set_registration_type(p_contact_email, p_type)` → `registrations`
**Admin-only.** Changes a contact's registration type for the active event.
+6 -4
View File
@@ -44,7 +44,9 @@ erDiagram
## `contacts` — people (source of truth)
One row per person. **`email` is the primary key** (a natural key that matches
`auth.users.email`). The `qr_token` doubles as the Supabase Auth password.
`auth.users.email`). Contacts carry **no QR token** — the token lives on the
registration (it is generated per event by Pretix and doubles as the Auth
password).
| Column | Type | Notes |
|---|---|---|
@@ -54,11 +56,9 @@ One row per person. **`email` is the primary key** (a natural key that matches
| `show_email` | `boolean` | default `false` — visibility toggle |
| `show_linkedin` | `boolean` | default `false` — visibility toggle |
| `is_admin` | `boolean` | default `false` — **staff = admin (merged)**; grants check-in + APPE Admin access |
| `qr_token` | `text` **unique** | The lanyard token; **doubles as the Auth password** |
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
| `created_at` | `timestamptz` | |
Index: `contacts_qr_token_idx (qr_token)` — fast lanyard lookups.
Partial unique index: `contacts_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
## `events` — a conference
@@ -96,11 +96,13 @@ Points are scoped **per event** here (one row per contact per event).
| `type` | `text` | `attendee` \| `speaker` \| `staff` \| `sponsor` (default `attendee`) |
| `checked_in` | `boolean` | default `false` |
| `points` | `integer` | `>= 0`, default 0 |
| `qr_token` | `text` | nullable — the lanyard token; **doubles as the Auth password** (generated per event) |
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
| `created_at` | `timestamptz` | |
**Constraint:** `unique (event_id, contact_email)` — one registration per contact
per event. Partial unique index: `registrations_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
per event. Partial unique indexes: `registrations_external_id_uniq (external_id) WHERE external_id IS NOT NULL`
and `registrations_qr_token_uniq (qr_token) WHERE qr_token IS NOT NULL` (fast lanyard lookups).
## `sponsors` — a sponsor for an event
+4 -4
View File
@@ -8,9 +8,9 @@ Source of truth: [`supabase/seed.sql`](../../supabase/seed.sql). The seed runs o
| Data | Count | Notes |
|---|---|---|
| `auth.users` + `auth.identities` | 13 | 12 attendees + 1 admin; **QR token = bcrypt password** |
| `contacts` | 14 | 13 with QR tokens + 1 external keynote speaker (no token) |
| `contacts` | 14 | 13 registrants + 1 external keynote speaker (no token — tokens live on registrations) |
| `events` | 1 | **APPE 2026**, 2026-10-23, São Paulo, Brazil, **active** |
| `registrations` | 13 | one per contact (Elena has none); points scoped here |
| `registrations` | 13 | one per contact (Elena has none); points + **QR token** scoped here |
| `sponsors` | 3 | Nubank (headline, paid), Acme Corp (gold, paid), Globant (community, unpaid) |
| `slots` | 6 | 23 Oct, 09:00–15:45 (see table below) |
| `sessions` | 18 | 3 per slot (Main Stage / Room A / Room B) |
@@ -62,8 +62,8 @@ Login = **QR code** (typed or scanned) + **email**. The QR token is the password
| Dr. Elena Vasquez | (external speaker) | — | elena.vasquez@keynote.com | — |
> **Dr. Elena Vasquez** is an external keynote speaker: she has a `contacts` row
> (and speaks in `session_speakers`) but **no QR token and no auth user**, so she
> can't log in — she only appears as a speaker on the agenda.
> (and speaks in `session_speakers`) but **no registration, no QR token, and no
> auth user**, so she can't log in — she only appears as a speaker on the agenda.
## Ana's demo state (so the app looks alive on first login)