Skip to content

Store Gamma IDs instead of names for bookings - #120

Merged
Goosetaf merged 2 commits into
mainfrom
t3/fix-booked-by-auth-url
Oct 28, 2026
Merged

Goosetaf merged 2 commits into
mainfrom
t3/fix-booked-by-auth-url

Conversation

@Portals

@Portals Portals commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Clicking "Booked by" or "Booking as" on a booking took you to gamma.chalmers.it, which no longer hosts Gamma, and even on auth.chalmers.it the links would 404. Gamma only routes users and super groups by ID, and we stored the super group name and the booker's cid.

What changed

  • Bookings store Gamma IDs: booked_as is the super group ID and booked_by the user ID, both as uuid columns. A cleared booker is NULL instead of ''.
  • The booking page shows the group's pretty name (digIT) and the booker as First "Nick" Last, fetched from Gamma and cached in memory. Both link to Gamma by ID.
  • The Gamma URL comes from ISSUER_BASE_URL, so the links also work against the local Gamma in development.
  • The "Booking as" dropdown lists groups by pretty name.
  • The privacy text now mentions the Gamma user ID instead of the cid.

Upgrading: nothing to do by hand

Existing bookings are converted automatically the first time the new version starts:

  1. prisma migrate deploy runs as usual from the entrypoint.
  2. Before the server starts accepting requests, it runs any pending data migrations from bookit/src/data-migrations. This one looks up group names and cids in Gamma and replaces them with IDs. Each data migration runs once and is recorded in a new data_migration table, so later starts skip it.
  3. If Gamma can't be reached, startup fails and the container restarts and tries again. Nothing is changed until the conversion succeeds, and the database stays usable by the previous version in the meantime.

A few things to know:

  • Everyone is signed out once, since sessions now hold group IDs instead of names.
  • Values that have no Gamma ID are set to NULL and logged by booking ID: groups Gamma no longer has, old private bookings, and bookers who no longer accept BookIT in Gamma. A booking without a booker works like one whose personal data was already cleared.
  • Going back to the previous version after a successful upgrade means restoring the backup taken before upgrading.

Testing

  • Upgrade test: ran the current main against Postgres, Redis and the local Gamma, made bookings through the old app (plus an unknown group, an old private booking and a cleared booker), then started this branch on the same database. Everything was converted on startup, updated_at was untouched, old sessions were signed out, the links opened the right pages in Gamma, members could still edit, move and delete their old bookings, phone numbers stayed private, and a restart didn't convert again. Starting with Gamma down failed and left the data untouched, then worked once Gamma was back.

Bookings stored the super group name in booked_as and the booker's cid in
booked_by. The "booked by" and "booking as" links pointed at
gamma.chalmers.it with those values, but Gamma only routes users and super
groups by ID, so both links went to "not found".

Bookings now store Gamma UUIDs in uuid columns. Names are looked up in
Gamma and cached in memory: the group's pretty name, and the booker as
First "Nick" Last. Links use ISSUER_BASE_URL, so they also work against the
local Gamma.

Existing bookings are converted automatically on the first start of the new
version. Data migrations that need more than SQL live in
bookit/src/data-migrations and run once, before the server accepts
requests, tracked in a new data_migration table. If Gamma can't be reached,
startup fails and the next start retries; nothing is changed until it
succeeds.

Sessions now hold super group IDs, so everyone is signed out once.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The user cache retains personal data after privacy cleanup because expired entries are never removed, allowing retention beyond the stated period until process restart.

1 open issue
What changed in this PR

This PR switches booking ownership from Gamma names and cids to UUIDs, enabling working profile links and readable names while updating permissions and privacy cleanup.

Changes:

  • Adds transactional startup migrations to convert existing bookings and record completed conversions.
  • Resolves Gamma display names through an in-memory cache and builds profile links from ISSUER_BASE_URL.
  • Updates booking forms, authorization checks, schemas, documentation, and tests for ID-based ownership.
File Description
README.md Documents Gamma links, caching, and upgrade behavior.
frontend/​src/​pages/​booking.tsx Displays Gamma names and ID-based profile links.
frontend/​src/​lib/​privacy.ts Updates disclosures for Gamma IDs and displayed names.
frontend/​src/​generated/​graphql.ts Regenerates frontend types and query documents.
frontend/​src/​components/​booking-form.tsx Uses group IDs with readable dropdown labels.
frontend/​src/​api/​operations.graphql Requests Gamma names, groups, and base URL.
e2e/​permissions.spec.ts Expects pretty names in group options.
e2e/​booking-lifecycle.spec.ts Checks displayed names and Gamma profile links.
e2e/​booking-helpers.ts Selects booking groups by display label.
codegen.ts Maps GraphQL users to session-user types.
bookit/​src/​tests/​groups.test.ts Updates group eligibility tests for IDs.
bookit/​src/​tests/​gamma.test.ts Tests ownership conversion and display-name formatting.
bookit/​src/​tests/​event.test.ts Tests permissions with UUIDs and nullable ownership.
bookit/​src/​tests/​directory.test.ts Tests cache sharing, refreshes, and retries.
bookit/​src/​tests/​booking-group.test.ts Tests group validation and Gamma failure handling.
bookit/​src/​services/​rule.service.ts Removes ownership from the rule-booking type requirement.
bookit/​src/​services/​event.service.ts Uses IDs and nullable ownership in booking logic.
bookit/​src/​schemas/​v1/​user.gql Adds Gamma profile types and URL query.
bookit/​src/​schemas/​v1/​event.gql Adds resolved profiles and nullable ownership fields.
bookit/​src/​resolvers/​user.resolver.ts Exposes the configured Gamma base URL.
bookit/​src/​resolvers/​index.ts Wires profile lookups and ID-based phone access.
bookit/​src/​resolvers/​gamma.resolver.ts Formats Gamma profiles with lookup fallbacks.
bookit/​src/​resolvers/​event.resolver.ts Validates booking groups and stores user IDs.
bookit/​src/​index.ts Runs data migrations before serving requests.
bookit/​src/​generated/​schema.ts Regenerates backend schema and resolver types.
bookit/​src/​gamma/​directory.ts Adds Gamma directory access and caching.
bookit/​src/​data-migrations/​index.ts Coordinates and records transactional data migrations.
bookit/​src/​data-migrations/​0001-gamma-ids.ts Converts legacy ownership values to Gamma UUIDs.
bookit/​src/​cleanup.ts Clears booker IDs using NULL.
bookit/​src/​auth/​session-store.ts Invalidates sessions using the previous ownership format.
bookit/​src/​auth/​groups.ts Derives bookable memberships using group IDs.
bookit/​prisma/​schema.prisma Defines nullable UUID ownership and migration records.
bookit/​prisma/​migrations/​20261028000001_gamma_id_columns/​migration.sql Converts columns directly when legacy lookup is unnecessary.
bookit/​prisma/​migrations/​20261028000000_data_migration/​migration.sql Creates the data-migration tracking table.

Review effort: Balanced

Comment thread bookit/src/gamma/directory.ts Resolved
The user cache never removed entries, so a booker's name could stay in
memory after the cleanup had cleared them from the booking.

@Goosetaf Goosetaf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Goosetaf
Goosetaf merged commit a01c27d into main Oct 28, 2026
3 checks passed
@Goosetaf
Goosetaf deleted the t3/fix-booked-by-auth-url branch October 28, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants