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

+7 -5
View File
@@ -95,10 +95,10 @@ flag. See [frontend/admin-app.md](./frontend/admin-app.md):
Sponsors, Schedule (slots/sessions/speakers/material/AI-evaluate), Activity,
Events, and **Interfaces** (trigger Pretix/Sessionize syncs + export the QR CSV).
- **Auth guard** — same QR + email login, but non-admin sessions are rejected.
- **Key RPCs** — `reset_qr_token` (regenerate a lanyard token + sync the Auth
password), `adjust_points`, `upsert_contact`, `create_registration`,
`set_registration_type`, `evaluate_session_feedback` (AI stub), and
`set_session_material` (see [backend/rpcs.md](./backend/rpcs.md)).
- **Key RPCs** — `reset_registration_qr_token` (regenerate a registration's
lanyard token + sync the Auth password), `adjust_points`, `upsert_contact`,
`create_registration`, `set_registration_type`, `evaluate_session_feedback`
(AI stub), and `set_session_material` (see [backend/rpcs.md](./backend/rpcs.md)).
## 5. How a request flows (example: staff check-in)
@@ -182,7 +182,9 @@ Convivo/
│ ├─ migrations/
│ │ ├─ 20260822000000_init.sql # original schema (replaced by the Redesign)
│ │ ├─ 20260823000000_admin_app.sql # admin read RLS + reset_qr_token (superseded)
│ │ └─ 20260824000000_redesign.sql # ← current: multi-event model, RPCs, RLS, materials
│ │ ├─ 20260824000000_redesign.sql # multi-event model, RPCs, RLS, materials
│ │ ├─ 20260825000000_interfaces.sql # external_id + sync_runs + sync RPCs
│ │ └─ 20260826000000_registration_qr_token.sql # ← current: QR token on registration
│ └─ seed.sql # 1 event, 6 slots, 18 sessions, 14 contacts, demo state
├─ docker-compose.yml # Runs both app sidecars on the Supabase network
├─ docs/ # ← this documentation
+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)
+18 -14
View File
@@ -14,10 +14,10 @@ It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container
| View | Purpose |
|---|---|
| **Dashboard** | Active event card (name, dates, location, aggregates: avg feedback, #sessions, #speakers, #registrations, #checked-in) + top points + recent activity. |
| **Contacts** | Table of all contacts (email, name, LinkedIn, visibility toggles, `is_admin`, QR token). Edit, **reset the QR token**, toggle `is_admin`, set visibility. |
| **Registrations** | Per active event: list (contact, type, checked_in). Change type (enforces the sponsor rule), mark checked-in. |
| **Sponsors** | List (paid only visible to attendees; admin sees all). Add/edit (type, name, email, phone, paid, amount, contact lookup). |
| **Schedule** | Slots (with type) + sessions (with speakers 1:N, material upload, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). |
| **Contacts** | Table of all contacts (email, name, LinkedIn, visibility toggles, `is_admin`). Edit, toggle `is_admin`, set visibility, adjust points. (No QR token here — it lives on the registration.) |
| **Registrations** | Per active event: list (contact, type, **QR token**, checked_in, points). Change type (enforces the sponsor rule), mark checked-in, **view + reset the QR token** (per registration). |
| **Sponsors** | List (paid only visible to attendees; admin sees all). Add/edit (type, name, email, phone, paid, amount, **contact search-and-pick**). |
| **Schedule** | Slots (with type) + sessions (with speakers 1:N via a **multi-select search dropdown**, material upload with a **submitted / not submitted** state, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). |
| **Activity** | Tables of check-ins, connections, and feedback (per active event). |
| **Events** | Create event, set active (only one), edit dates/location. |
| **Interfaces** | Trigger **Pretix** and **Sessionize** syncs (per-source or "Sync all"), show the result counts, list recent sync runs, and **export the QR CSV** (name/email/type/qr_token for the active event). |
@@ -55,8 +55,8 @@ apps/admin/src/
│ └─ Login.tsx # QR + email login (admin-only)
└─ views/
├─ Dashboard.tsx # active event + aggregates + top points + activity
├─ Contacts.tsx # table + edit / QR-reset / is_admin / visibility
├─ Registrations.tsx# per-event list + type / checked-in
├─ Contacts.tsx # table + edit / is_admin / visibility / points
├─ Registrations.tsx# per-event list + type / QR token (+reset) / checked-in
├─ Sponsors.tsx # sponsor CRUD
├─ Schedule.tsx # slots + sessions + speakers + material + AI-evaluate
├─ Activity.tsx # check-ins / connections / feedback tables
@@ -76,18 +76,22 @@ key. Everything it can do is allowed by RLS:
- **Writes** — direct `insert` / `update` / `delete` on `contacts`, `events`,
`registrations`, `sponsors`, `slots`, `sessions`, and `session_speakers`
(admin-only policies).
- **RPCs** — `reset_qr_token` (regenerate a lanyard token), `adjust_points`
(manual, audited as `admin`), `upsert_contact`, `create_registration`,
`set_registration_type`, `evaluate_session_feedback` (AI stub), and
`set_session_material` (attach uploaded material). See
- **RPCs** — `reset_registration_qr_token` (regenerate a registration's lanyard
token), `adjust_points` (manual, audited as `admin`), `upsert_contact`,
`create_registration`, `set_registration_type`, `evaluate_session_feedback`
(AI stub), and `set_session_material` (attach uploaded material). See
[../backend/rpcs.md](../backend/rpcs.md).
### Resetting a QR token
`reset_qr_token(contact_email)` generates a new `CVV-XXX-NNNN` token, writes it to
`contacts.qr_token`, **re-hashes it as the Auth password** (so the old token stops
working), and deletes the contact's existing sessions (forcing a re-login). The UI
shows the new token as a scannable QR code.
The QR token lives on the **registration** (per event), not the contact. The
**Registrations** view shows each registration's token and a **QR** button that
opens a modal with the scannable code + a **Reset token** action. Reset calls
`reset_registration_qr_token(contact_email)`, which generates a new
`CVV-XXX-NNNN` token, writes it to `registrations.qr_token`, **re-hashes it as the
Auth password** (so the old token stops working), and deletes the contact's
existing sessions (forcing a re-login). The UI shows the new token as a scannable
QR code.
### Adjusting points
+3 -2
View File
@@ -37,8 +37,9 @@ Holds the Supabase **session**, the current **`Contact`**, the current
`refresh()`, `signOut()`.
> The contact is the app's source of truth for the current user's `is_admin`
> (staff powers) and `qr_token`; the registration holds the user's `type` and
> `points`. After any points-changing action, screens re-fetch.
> (staff powers); the registration holds the user's `type`, `points`, and
> `qr_token` (the lanyard token, per event). After any points-changing action,
> screens re-fetch.
## ToastContext (`context/ToastContext.tsx`)
+20 -7
View File
@@ -43,7 +43,10 @@ The landing screen. Shows:
- **Now card** — the session the user picked for the current slot, with a
"✓ Checked in" or "Show your QR to staff to check in" pill.
- **Next card** — the pick for the next slot.
- **My picks today** — the user's pick per slot (tap to change → opens Agenda).
- **My picks today** — shows only **2 rows** (the current slot's pick + the next
slot's pick). "tap to change" is a **hyperlink** to the Agenda.
- **Footer type badge** — the registration-type pill is shown **only for non-
attendee** types (Attendee is the default and is not shown at the bottom).
- **Quick actions** — Scan & connect / Check-in, Agenda, Connections, Leaderboard.
- **No active event** — a graceful empty state ("No active event right now.
Check back soon!").
@@ -98,15 +101,24 @@ Data: `useEvent()` (for the session list) + the RPCs above.
Two tabs: **My connections** and **Requests** (with a count badge).
- **My connections** — accepted connections (the other person's name +
registration type).
registration type). **Clicking a row** opens a bottom **sheet** with that
person's **public info + their points** (avatar, name, type pill, `⚡ N pts`,
LinkedIn if visible, email if `show_email`). **Other people's QR codes are
never shown.**
- **Requests** — incoming (`to_email = me`, pending) with **Accept / Decline**
buttons (`acceptConnection` / `rejectConnection`), and outgoing (`from_email =
me`, pending) shown as "Sent".
me`, pending) shown as "Sent". The person block is also clickable (same detail
sheet).
- Accepting awards +5 to both (see
[../backend/rpcs.md#accept_connectionp_connection_id--connections](../backend/rpcs.md#accept_connectionp_connection_id--connections)).
- **Live-ish:** polls every 5s while the tab is visible (`usePolling`).
- **Red dot** — any interaction with the connection logic (accept / decline / send)
dispatches a `connections-changed` window event; the Shell listens and
**recalculates the Connect red dot immediately** (it stays while any incoming
request is pending and disappears once none are). It also polls every 5s as a
fallback (`usePolling`).
Data: `getMyConnections()` + `getPublicContacts()` (to resolve names + types).
Data: `getMyConnections()` + `getPublicContacts()` (names + types) +
`getLeaderboard()` (points for the detail sheet).
## Feedback
@@ -144,8 +156,9 @@ event). The `leaderboard` table is kept in sync transactionally by the RPCs —
- **Header** — avatar, name, email, registration-type pill, a **staff** pill when
`contact.is_admin`, and a points pill.
- **My QR code** — renders `contact.qr_token` as a scannable QR (`QrImage`).
"Show this to staff for check-in and to peers to connect."
- **My QR code** — renders `registration.qr_token` (the token lives on the
registration, per event) as a scannable QR (`QrImage`). "Show this to staff for
check-in and to peers to connect."
- **Points breakdown** — sums `points_log` by category
(Session check-ins / Connections / Feedback / Other) + Total.
- **Log out** — `signOut()`.
+59 -2
View File
@@ -4,8 +4,10 @@ What's done, what's next, and the open decisions. The full roadmap lives in the
root [`roadmap.md`](../roadmap.md); this file is the working detail for the
current phase.
> **Current state:** Phases 0–8 are complete and verified. The **Redesign**
> (Phases 3–6) and the **Pretix + Sessionize interfaces** (Phases 7–8) are done.
> **Current state:** Phases 0–8 are complete and verified, plus a round of
> **Fixes & Refinements** (QR token moved to the registration, role-pill
> capitalization, connection detail sheet + red-dot recalc, admin schedule
> speaker multi-select + upload/speaker bug fixes, sponsor contact search).
> Remaining work is cross-cutting (real event clock, deployment, testing) and
> the open questions in [backend/interfaces.md](./backend/interfaces.md).
@@ -179,6 +181,61 @@ Sync the **real agenda** (slots, sessions, speakers, rooms) from
- **Auth** — the Edge Function accepts an admin JWT (verified via `is_admin()`)
or a `CRON_SECRET` header for scheduled runs.
## Fixes & Refinements — ✅ complete
A cross-cutting polish round (migration `20260826000000_registration_qr_token.sql`
+ app changes), all browser-verified.
**Datamodel — QR token moves from `contacts` to `registrations`.**
- The token is a property of the **registration** (generated per event by
Pretix), not the contact. `contacts.qr_token` is dropped; `registrations.qr_token`
is added (partial unique index `registrations_qr_token_uniq`).
- `lanyard_lookup`, `create_connection_request`, and `checkin_attendee` now
resolve tokens via `registrations` + the active event.
- `reset_qr_token(contact)` is replaced by `reset_registration_qr_token(email)`
(admin-only; regenerates the active-event registration's token + re-hashes the
Auth password + clears sessions). `upsert_contact` no longer takes a token;
`create_registration` generates one and syncs it as the password.
- The Pretix sync writes the token to the **registration** (keeps the existing
token on re-sync so a lanyard is never invalidated).
**Registration types.**
- Type pills have **distinct colors**; **red is reserved for Staff** (both apps).
- Roles are shown **capitalized** in both apps (Attendee / Speaker / Sponsor /
Staff). "Attendee" is **not shown at the bottom** of the Home screen (it's the
default); it *is* shown (capitalized) on Profile, Login, Scan, and Connections.
- The **reset-token button is removed from the Contacts view** (meaningless now
that the token lives on the registration) and moved to the **Registrations**
view (per-registration QR + reset).
**Sessions (APPE Admin).**
- Slot types are shown **capitalized** (Session, Keynote, Lunch Break, …).
- The session list shows whether material was **submitted / not submitted**.
- Speaker selection is a **multi-select search dropdown** (search + chips),
replacing the checkbox list.
- **Fixed:** editing a session no longer fails with "a session must have a
speaker" — `setSessionSpeakers` now **diffs** (insert the new set, then delete
only the removed ones) instead of delete-all-then-insert, so the
`session_needs_speaker` trigger (which counts the row being deleted) never
fires. This also **fixes the file-upload bug** (the speaker save no longer
aborts before the material upload runs).
**APPE Admin — Sponsors.**
- The sponsor **contact lookup is a search field** (filter + click-to-pick), not
a dropdown of all contacts.
**Convivo App.**
- **Other people's QR codes are hidden** — the connection detail sheet shows
public info + points only (no QR).
- **Connect red dot** — any interaction with the connection logic (accept /
decline / send) dispatches a `connections-changed` event; the Shell recalculates
the dot **immediately** (stays while any incoming request is pending, clears
when none are). 5s polling remains as a fallback.
- **Connect menu** — clicking any connection (connected or requested) opens a
sheet with that person's **public info + their points**.
- **"My picks today"** — shows only **2 rows** (current + next slot's pick);
"tap to change" is a **hyperlink** to the Agenda.
## Cross-cutting / later
- **Real event clock** — replace the simulated `DEFAULT_NOW`