Repository navigation
fix(office): the verification queue and violation reports answer at all (#900, #901) - #909
Conversation
|
Reviewed while clearing the queue. Strong PR — the "a query error nobody read, turned into a plausible-looking empty state" framing is exactly right, and pinning both directions of the gate because "a gate that denies everyone satisfies half its contract" is the detail that makes the tests worth having. Correcting your own diagnosis on #901 in the issue rather than quietly shipping the right fix is the right call too. Not touching the branch — 1. Migration number collision — blocking
2.
|
…ll (#900, #901) Two admin screens were dead in the product. Both failed the same way — a query error that nobody read, turned into a plausible-looking empty state. ## #900 — verification 403s for everyone, including super_admin The gate was a local helper in `office-communities.ts`: const { data: user } = await supabase .schema("core").from("users").select("role").eq("id", userId).maybeSingle(); return user?.role === "office" || user?.role === "admin"; `core.users` has no `role` column. The select errored, only `data` was destructured so the error went nowhere, `user?.role` was `undefined`, and the helper returned false unconditionally. Listing the queue, approving and rejecting were all unreachable — for every caller, including holders of `super_admin`, `admin` and `office`. Roles live in `core.role_assignments` joined to `core.roles`, which is what the shared `requireRole("office", "platform")` middleware reads. Every other office route already mounts it; this file now does too, and gets the `supabaseAdmin` client it attaches — which these handlers need, since an administrator reads pending verifications across every community and `community.memberships` is RLS-scoped to the member. The same file had a second instance of the same mistake: the enrichment selected `id, display_name, email` from `core.users`, which has no `email` column either, so every row in the queue came back nameless. A queue of "Unknown User" is not a queue anyone can act on. Names come from the columns that exist; email comes from the admin API, since `auth.users` is not exposed through PostgREST even to the service role. The `limit` cap of 100 bounds that fan-out. ## #901 — violation reports 500 on every request I filed this one with the wrong cause and have corrected the issue. I said the foreign key was missing, having read `information_schema.constraint_column_usage` — which is privilege-filtered on the *referenced* table, so keys pointing into `auth` are invisible there. `pg_constraint` shows them. The constraints exist. Migration 129 created the table with its user columns split across two schemas: `worker_user_id` references `core.users`, while `reported_by_user_id` and `reviewed_by_user_id` reference `auth.users`. The request runs against `core`, and PostgREST resolves named embeds only within the schemas it exposes — `auth` is not one — so the embed had no target and the whole select failed, taking the `worker` embed down with it even though that one was always fine. Migration 360 re-points both at `core.users`. `core.users.id` is itself `REFERENCES auth.users(id) ON DELETE CASCADE`, so the two share an id space and nothing is lost. It also gives them `ON DELETE SET NULL`, which the old constraints lacked: they defaulted to NO ACTION against `auth.users`, so deleting the account of anyone who had filed or reviewed a report would fail at that constraint — account deletion blocked by a violation report. The report should outlive the accounts; that is what the table is for. Behind that sat the same `email` bug, since the embeds select it from `core.users` as a display-name fallback. `username` is on the table and is the name people are known by. ## Tests Six api tests in `tests/routers/`, hitting real HTTP. They were run against `origin/main`'s handlers first: five fail. The sixth — "a worker is refused" — passes on the broken code, which is the point of pinning both directions: a gate that denies everyone satisfies half its contract. ## Constraints recorded `.radium/supabase-backend.md` gains two notes: never destructure only `data` from a Supabase query (both bugs here), and PostgREST embeds only resolve inside exposed schemas — with the `information_schema` filtering trap that sent me down the wrong path on #901. Verified locally: an office user lists, rejects and approves (queue total 1 → 0); a worker gets 403; `/office/violations` renders rows naming reporter, organisation and worker; both screens at 1440 and 390 with no horizontal scroll. Co-Authored-By: Claude Opus 5 <[email protected]>
a7226de to
2710be3
Compare
|
Pushed a fix for the red CI. Three things, one of them a real defect in the branch: 1. Migration number collision (the actual failure). #905 merged its own My local 2. 3. All six api tests re-run green after the rebase. One thing worth flagging separately, since it is why both of these outages lasted: the tests I added do not run in CI. So these six tests protect a local run and a reviewer, not the build. I have not changed that here because it is a CI-topology decision rather than part of this fix, but it seems worth its own issue — happy to file one. |
📊 Performance Benchmark Results |
Closes #900. Closes #901.
Two admin screens were dead in the product — the two whose layouts #839 had just rebuilt. Both failed the same way: a query error nobody read, turned into a plausible-looking empty state.
#900 — verification 403s for everyone,
super_adminincludedThe gate was a local helper in
office-communities.ts:core.usershas norolecolumn. The select errored, onlydatawas destructured so the error went nowhere,user?.rolewasundefined, and the helper returned false unconditionally. Listing, approving and rejecting were all unreachable for every caller.Roles live in
core.role_assignments→core.roles, which is what the sharedrequireRole("office", "platform")middleware reads. Every other office route already mounts it; this file now does too, and uses thesupabaseAdminclient it attaches — which these handlers need, since an administrator reads across every community andcommunity.membershipsis RLS-scoped to the member.The same file had the same mistake twice. The enrichment selected
id, display_name, emailfromcore.users, which has noemailcolumn either — so every row came back nameless. A queue of "Unknown User" is not a queue anyone can act on. Names now come from columns that exist; email comes from the admin API, sinceauth.usersisn't exposed through PostgREST even to the service role.#901 — violation reports 500 on every request
I filed this one with the wrong cause, and have corrected the issue. I claimed the foreign key was missing, having read
information_schema.constraint_column_usage— which is privilege-filtered on the referenced table, so keys pointing intoauthare invisible there.pg_constraintshows them.The constraints exist. Migration 129 created the table with its user columns split across two schemas:
The request runs against
core, and PostgREST resolves named embeds only within exposed schemas —authis not one. So the embed had no target and the whole select failed, taking theworkerembed down with it even though that one was always fine.Migration 359 re-points both at
core.users(core.users.idalready referencesauth.users(id)on cascade, so they share an id space). It also gives themON DELETE SET NULL, which they lacked: defaulting toNO ACTIONagainstauth.usersmeant deleting the account of anyone who had filed or reviewed a report would fail at that constraint — account deletion blocked by a violation report.Behind that sat the same
emailbug, since the embeds use it as a display-name fallback.usernameis on the table.Tests
Six api tests in
tests/routers/, hitting real HTTP. Run againstorigin/main's handlers first:The one that passes is "a worker is refused" — which the broken code passes for the wrong reason. That is why both directions are pinned: a gate that denies everyone satisfies half its contract.
With the fix:
ok | 6 passed | 0 failed.Constraints recorded
.radium/supabase-backend.mdgains two notes — never destructure onlydatafrom a Supabase query, and PostgREST embeds only resolve inside exposed schemas, including theinformation_schematrap that sent me down the wrong path above.Verification
Requires office role with platform scope/office/violationshScroll 0pnpm prepushgreen; migration numbers unique (195).Note for whoever merges: migration 359 needs applying to dev/preview/prod. It is idempotent and touches two constraints on one table.
🤖 Generated with Claude Code