Repository navigation
Add profile verification audit table and triggers - #17
Conversation
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
| if p_actor_id is not null then | ||
| if p_subject_type in ('user', 'profile', 'user_private') then | ||
| v_subject_user := p_subject_id; | ||
| elsif p_subject_type = 'project' then | ||
| if to_regclass('public.projects') is not null then | ||
| select profile_id into v_subject_user from public.projects where id = p_subject_id; | ||
| end if; | ||
| end if; | ||
|
|
||
| v_has_permission := public.user_has_role(p_actor_id, 'super_admin', null); | ||
|
|
||
| if not v_has_permission and v_subject_user is not null then | ||
| v_has_permission := exists ( | ||
| select 1 | ||
| from public.role_assignments ra | ||
| where ra.user_id = v_subject_user | ||
| and ra.scope_org_id is not null | ||
| and public.user_has_role(p_actor_id, 'partner_admin', ra.scope_org_id) | ||
| ); | ||
| end if; | ||
|
|
||
| if not v_has_permission then | ||
| raise exception 'insufficient privileges to revoke %', v_field | ||
| using errcode = '42501'; | ||
| end if; | ||
| end if; |
There was a problem hiding this comment.
[P1] Enforce actor authentication in revoke_profile_field
The public.revoke_profile_field RPC only performs its permission check when p_actor_id is non‑null. Because the function is security definer and lives in the public schema, any caller who passes null for p_actor_id can revoke verification rows for any subject without possessing super_admin or partner_admin roles. This effectively bypasses the authorization gate and allows unprivileged users to clear verification state. The function should require a non‑null actor or run the permission logic regardless of parameter nullability.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is the final PR Bugbot will review for you during this billing cycle
Your free Bugbot reviews will reset on October 1
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| set source = 'verified', | ||
| last_verified_at = p_verified_at | ||
| where user_id = p_subject_id; | ||
| end if; |
There was a problem hiding this comment.
Bug: Profile Effects Fail Without Table Check
The apply_profile_verification_effects and apply_profile_revocation_effects functions attempt to update public.user_skills without first checking if the table exists. This can lead to runtime errors if user_skills is not present, which is inconsistent with other conditional table operations in this migration.
Additional Locations (1)
| v_fields := array_append(v_fields, 'basic.industry'); | ||
| end if; | ||
|
|
||
| if coalesce(new.years_of_experience, -1) is distinct from coalesce(old.years_of_experience, -1) then |
There was a problem hiding this comment.
Bug: Triggers Mask Changes with Sentinel Values
The tg_profile_verifications triggers use coalesce with sentinel values (like -1 or a default geography point) in is distinct from comparisons. This incorrectly masks changes between NULL and the sentinel, preventing automatic revocation of verifications for fields such as years_of_experience, geo, travel_mileage, hourly_rate_cents, and number_of_days.
Additional Locations (4)
This branch pinned packages/sdk and packages/ui at the tips of Scaffald/sdk#12 and Scaffald/ui#17. Both were squash-merged, which creates a new commit and leaves the branch tips unreachable from their mains — so the pointers here referenced commits that no longer exist on any branch. Merging in that state would have pinned SaaS main to orphaned submodule commits. packages/sdk f96f4180 -> e4a47e5 (sdk main, #12 squashed) packages/ui 39f950d1 -> fdaa0d4 (ui main, #17 squashed) Verified the squashed commits carry what this branch needs — sdk has resources/legal.ts and prerequisites' needsLegalAcceptance, ui's Checkbox forwards testID — and that scf-core typechecks clean against them.
…ce, web PKCE (#519) * fix(auth): keep the auth Stack mounted during the session check so OAuth callback tokens survive The (auth)/auth layout returned a Loading view *instead of* its <Stack> while useProtectedRoute was pending — which is always the case on first render. With the navigator unmounted during hydration, react-navigation resolved the focused route back to the group's initial route and expo-router's history sync rewrote the URL to /auth, destroying the #access_token fragment on /auth/callback ~5ms before supabase-js initialized and read the URL. Result: every web OAuth login (Google/ Apple) on prod silently bounced back to the login screen. Render the Stack unconditionally and overlay the loading state instead. Verified end-to-end against a local dev server: minted a real GoTrue session, loaded /auth/callback#access_token=... — supabase-js now issues the /auth/v1/user validation call, stores the session, and lands on /dashboard signed in. Before the fix the same URL produced zero auth requests and a silent bounce (reproduced on prod with an instrumented iframe probe). Also add the apex + www domains to the local config.toml redirect allow-list and fix its stale production comment (prod's hosted uri_allow_list already had them). Co-Authored-By: Claude Fable 5 <[email protected]> * feat(auth): versioned legal acceptance, passive login notice, layout hydration fix, web PKCE Four related auth changes. 1. Versioned legal acceptance (migration 342) core.legal_documents holds one is_current row per document type and is the single source of truth for which version users must accept. It replaces five drifting hardcoded version constants (login screen, cookie provider x2, both prerequisites routers, the document page subtitles). Publishing new terms is now an UPDATE+INSERT documented in the migration header — no code deploy. GET /v1/prerequisites/check reads it and reports which gate, if any, is unresolved: needsOnboarding (profile fields missing -> full onboarding form) or needsLegalAcceptance (profile complete, legal stale -> the new lightweight /legal-update screen). Acceptance now only counts at the current version, so a version bump forces re-acceptance; the seeded current version is 'v1.0', which every existing preferences row already carries, so nobody is re-prompted at cutover and no data migration is needed. POST /v1/prerequisites/accept-legal backs the re-acceptance screen. Both it and /complete stamp versions read from the table and write consent_records audit rows server-side, with first-class 'terms_of_service'/'privacy_policy' consent_type values (CHECK extended) instead of the previous metadata.type shoehorn. 2. Login screen: passive notice replaces the consent checkbox The checkbox was theater: a SIGNED_IN listener wrote two consent_records rows unconditionally, without consulting it, on web and native alike. That client-side write is deleted. The notice is browsewrap; the real versioned, audited clickwrap now happens in onboarding and /legal-update. Adds i18n keys in en/es/fr (the old copy was hardcoded English). 3. (protected) and (admin) layouts: same hydration bug as the OAuth callback Both rendered <Slot /> only once ready, so during web hydration the navigator was unmounted and expo-router rewrote the URL to the group's initial route — the mechanism that ate the OAuth callback hash in the previous commit, here eating deep-link paths. Both now keep the navigator mounted behind an opaque overlay, which also closes a one-frame flash of protected content before a redirect. Redirect refs became target-aware so a user can move between gates without getting stuck. 4. Web OAuth switched to PKCE flowType is pkce on web (native keeps implicit; it signs in via signInWithIdToken and never parses URLs). A pkce client rejects implicit-style #access_token callbacks AND calls _removeSession on the way out, which is what GoTrue's {{ .ConfirmationURL }} email links produce — so the email templates now link to a new flow-agnostic /auth/confirm route that verifies a token_hash. See the deploy-order constraint in client.ts: hosted templates must be updated and old links allowed to expire before a build with this flag ships. Also removes dead code: PrerequisiteWidget (rendered nowhere, validated legal fields it never rendered) and the SDK's six phantom prerequisites endpoints; fixes extensionless edge-function imports that broke `supabase functions serve` for the whole stack; and reconciles the three-way testID drift between the onboarding form, the Playwright helpers, and tests/TEST_IDS.md. Verified against a live local stack: 8 new Deno route tests cover the check/complete/accept-legal contract including the stale-version round trip and its audit rows. Manually exercised a real version publish — an onboarded user flipped to needsLegalAcceptance with needsOnboarding still false, then accept-legal restored isComplete with the new version stamped. Unit suites (scf-core 304, SDK 764, root-route 23, schemas 53) and the SDK/route contract test pass; typecheck clean. Co-Authored-By: Claude Fable 5 <[email protected]> * chore(auth): hold the web PKCE flag for a follow-up deploy The flowType flip and the /auth/confirm route were in one commit, which made every web deploy of this branch order-dependent: shipping the flag before the hosted email templates are updated (and before links issued under the old templates expire) breaks magic-link sign-in AND signs the clicking user out, because a pkce client rejects the implicit-style #access_token callback and _initialize() then calls _removeSession(). Dropping just the flag makes this branch safe to deploy in any order. The /auth/confirm token_hash lander and the template changes still ship here — they are flow-agnostic and are the prerequisite for the flag. The flip follows once templates are live and old links have expired. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(legal): format effective dates in UTC effective_at is stored as midnight UTC, so formatting it in the viewer's local timezone shifted it a day backwards for anyone west of UTC: the terms page rendered "Last updated: February 2025" for a document that took effect 2025-03-01. Caught on the dev deploy. Adds a shared formatEffectiveDate() so the document pages and the re-acceptance screen cannot drift on this again. The effective date is a legal fact, not a local timestamp. Co-Authored-By: Claude Fable 5 <[email protected]> * chore(submodules): repoint at the squashed sdk/ui mains This branch pinned packages/sdk and packages/ui at the tips of Scaffald/sdk#12 and Scaffald/ui#17. Both were squash-merged, which creates a new commit and leaves the branch tips unreachable from their mains — so the pointers here referenced commits that no longer exist on any branch. Merging in that state would have pinned SaaS main to orphaned submodule commits. packages/sdk f96f4180 -> e4a47e5 (sdk main, #12 squashed) packages/ui 39f950d1 -> fdaa0d4 (ui main, #17 squashed) Verified the squashed commits carry what this branch needs — sdk has resources/legal.ts and prerequisites' needsLegalAcceptance, ui's Checkbox forwards testID — and that scf-core typechecks clean against them. * fix(work-logs): select team_id, which WorkLogRow requires `pnpm build` failed on this branch with TS2741 at work-logs.router.ts:900 — fetchWorkLog declares Promise<WorkLogRow> but WORK_LOG_SELECT never asked for team_id, so the returned row was missing a field the regenerated DB types make required. Pre-existed the submodule repoint in the previous commit; verified by checking out HEAD~1 and reproducing the same error. Blocking the push, so fixed here. * style(api): satisfy `deno fmt --check` on the prerequisites/legal routes The "Lint REST API Code" job runs `deno fmt --check`, which this branch's three new/changed files did not satisfy: routes/prerequisites.ts and the legal and prerequisites route tests. Mechanical; no behavioural change. --------- Co-authored-by: Claude Fable 5 <[email protected]>
Phase 3, screen 1 of the prototype-parity plan (#622). Closes five items from §12 of the ATS design brief in one screen. LANES — the pipeline as stage-grouped, full-width rows, now the default view with Board and Metrics alongside. Seven columns already overflow a laptop and the recruiter and NationSearch flows have eleven and twelve, so the board's answer to "more stages" is sideways scrolling that hides work. Rows also have room for the columns a card cannot carry. This answers open question #1 in the ATS brief. DAYS IN STAGE (§12 #7) — the board showed days since *applied*, which is a different and much less useful number: a candidate who applied 30 days ago and moved to Interview yesterday is not stale, and one who applied 8 days ago and has sat untouched in New is. `stage-timing.ts` derives the real figure from `stageHistory` — the transitions recorded in core.application_activity — by taking the most recent entry into the current status, so a candidate moved backwards gets a fresh clock. No history means the candidate has never moved, and their clock starts at appliedAt, which is correct rather than a fallback: entering the pipeline IS their entry into `new`. It returns null rather than 0 when timestamps do not parse, and clamps future timestamps to now — local Supabase has been observed running behind the host clock, which would otherwise render as "-2d in stage". Overdue is per-stage against the promises the public transparency stats are computed from, and every overdue row carries a reason ("Overdue — screening decision"), because an amber number alone says something is wrong without saying what. Terminal stages are never overdue: nobody is waiting on a hired candidate. ALSO CLOSED §12 #8 score, source, union status and assignee are on every row — these are the reasons an employer picks one candidate over another and none of them were on a card §12 #9 each stage gets its own empty state saying what would fill it, instead of "No applications" seven times §12 #17 Withdrawn reads as "Withdrawn by candidate" rather than a grey pill in a red column — the conflation the data model works to prevent §12 #6 the Interview column was error[50], the same red as rejected, so advancing a candidate moved them into a column that reads as a warning. It is a progress stage and now tints with the primary ramp Rows sort stalest-first within each stage, so the row that most needs acting on is the one at the top. TEST SEAM — scf-core resolves @scaffald/ui to a mock, so the four new primitives are added there. They mirror the real contracts rather than being stubbed: LaneGroup honours count/emptyState and Lane renders age first, since a stub that dropped those would make the screen logic under test unobservable. The change is additive — 171 insertions, zero deletions — so no existing consumer is affected. Verified: typecheck clean on scf-core and scaffald-app; lint clean; 17 new stage-timing tests and 11 new Lanes tests, all passing; an existing mock consumer (TeamMembersList) still passes. Not verified: the screen has not been seen rendering — it is behind auth and the office role. Note also that the full scf-core suite cannot be run locally: an unfiltered vitest run OOMs the worker, which is why prepush excludes it. Co-Authored-By: Claude Opus 5 <[email protected]>
…n primitives (#621) * feat(redesign): phase 1 tokens, prototype reference shots, and the parity plan Applies the SCF prototype (~/Development/SCF-Prototype) to the app. This is Phase 0 + Phase 1 of docs/plans/redesign/2026-08-19-prototype-parity-plan.md. PHASE 0 — the reference. 58 screenshots of the prototype, 29 screens across five roles at desktop 1440x900 and mobile 390x844, captured by driving the prototype's own state (capture-prototype.mjs re-runs it when the prototype moves). The plan doc records what the prototype decides that we have not, and measures the audit's findings against our code: 699 literal fontSize sites across 15 values, ~350 literal borderRadius across a dozen, 392 raw hex across 57 files, three separate page-header components. PHASE 1 — tokens, in the @scaffald/ui submodule (see its own commit). Teal stays the one primary; amber becomes the reserved attention role. App-side changes here: - global.css declares 'Scaffald Display' for headings, with a Georgia fallback so the serif intent survives until the Cormorant WOFF2 lands. The family name is indirect so swapping the display face later is a change to two rules rather than to every component. - login-screen.tsx: the title hard-coded `fontFamily: 'RobotoSerif_400Regular'` in an inline style, which overrode getFontFamily entirely and pinned the screen to the body serif — the token system could never reach it. Removed. It was also an H5 used as a card title; H5 is now the body-size step, so this is an H4, which preserves the shipped 17px exactly. Verified: typecheck clean across @scaffald/ui, scf-core and scaffald-app; UI suite 634/655, identical to the pre-change baseline; auth feature tests 44/46 with 0 failures; lint clean; computed styles and both themes confirmed in the browser on a cold Metro cache. Not included: the Cormorant Garamond WOFF2 files (downloading them needs sign-off), and the prototype push to Scaffald/Prototype@main. Co-Authored-By: Claude Opus 5 <[email protected]> * feat(fonts): self-host Cormorant Garamond as the display face Completes Phase 1. Headings now render in the prototype's actual face on web rather than falling back to Georgia. Cormorant Garamond is a variable font, so one 37 KB WOFF2 covers the whole weight axis — Google serves the same file for its 400 and 600 faces, which is why this is one file and not the two the plan assumed. The fallback moved to its own family name ('Scaffald Display Fallback') and into the stack that getFontFamily emits. Declared as a second @font-face under the same family it shadowed the real font entirely: the browser matched it and never requested the WOFF2, so headings rendered as Georgia while still looking serif in a screenshot. It keeps `size-adjust: 92%` to stop headings jumping size during the swap. Native is unchanged and still on Roboto — see getFontFamily for why. Verified: font served 200 (37776 bytes), document.fonts.check true, and Cormorant measures 119.9px against the fallback's 125.23px for the same string, confirming the real face is what loaded. Typecheck clean across all three packages; UI suite 634/655, identical to baseline. Co-Authored-By: Claude Opus 5 <[email protected]> * feat(redesign): phase 2 primitives, first caller, and two plan corrections Picks up the four screen primitives from the @scaffald/ui submodule (see its own commit) and proves them on one screen. MIGRATED — the ATS applications screen now uses ScreenHeader + ListToolbar. It gains the kicker and the tip the prototype gives it, a collapse caret, and moves its count out of an ad-hoc subtitle ("14 total applications") into the toolbar's result slot, which owns the one "{n} {noun}" template. This is the only screen migrated so far — the plan warns that a mechanical sweep produces a diff nobody can review, so the rest go per-screen in phase 3. DELETED — features/office/components/OfficePageHeader.tsx, which had zero callers. SaaSSectionHeader is also unused by the app but stays: it is a published export of the component library with stories and a docs page, so removing it is an API decision rather than dead-code cleanup. TWO CORRECTIONS to the plan, both from checking rather than assuming: 1. The prototype push is unnecessary. github.md's sync note claims Scaffald/Prototype@main still holds the 13 Aug build against 677 KB locally, and I repeated that as the one item with a real bus factor. After a fetch, local main and origin/main are the same commit and the file is 772,808 bytes on both. The note is stale; the reference was never laptop-only. 2. "Three competing page headers" overstated it. Two of the three are dead, and the third is a toolbar, not a header. Recorded in the ui commit. Verified: typecheck clean across all three packages; lint clean; UI suite 670 tests / 649 passing / the same 21 pre-existing environment failures. NOT verified: the migrated ATS screen has not been seen rendering. It sits behind auth and the office role, and reaching it means authenticating — which I do not do. The dev server is up on :8087 if you want to look. Co-Authored-By: Claude Opus 5 <[email protected]> * feat(ats): Lanes view for the pipeline, and a real days-in-stage clock Phase 3, screen 1 of the prototype-parity plan (#622). Closes five items from §12 of the ATS design brief in one screen. LANES — the pipeline as stage-grouped, full-width rows, now the default view with Board and Metrics alongside. Seven columns already overflow a laptop and the recruiter and NationSearch flows have eleven and twelve, so the board's answer to "more stages" is sideways scrolling that hides work. Rows also have room for the columns a card cannot carry. This answers open question #1 in the ATS brief. DAYS IN STAGE (§12 #7) — the board showed days since *applied*, which is a different and much less useful number: a candidate who applied 30 days ago and moved to Interview yesterday is not stale, and one who applied 8 days ago and has sat untouched in New is. `stage-timing.ts` derives the real figure from `stageHistory` — the transitions recorded in core.application_activity — by taking the most recent entry into the current status, so a candidate moved backwards gets a fresh clock. No history means the candidate has never moved, and their clock starts at appliedAt, which is correct rather than a fallback: entering the pipeline IS their entry into `new`. It returns null rather than 0 when timestamps do not parse, and clamps future timestamps to now — local Supabase has been observed running behind the host clock, which would otherwise render as "-2d in stage". Overdue is per-stage against the promises the public transparency stats are computed from, and every overdue row carries a reason ("Overdue — screening decision"), because an amber number alone says something is wrong without saying what. Terminal stages are never overdue: nobody is waiting on a hired candidate. ALSO CLOSED §12 #8 score, source, union status and assignee are on every row — these are the reasons an employer picks one candidate over another and none of them were on a card §12 #9 each stage gets its own empty state saying what would fill it, instead of "No applications" seven times §12 #17 Withdrawn reads as "Withdrawn by candidate" rather than a grey pill in a red column — the conflation the data model works to prevent §12 #6 the Interview column was error[50], the same red as rejected, so advancing a candidate moved them into a column that reads as a warning. It is a progress stage and now tints with the primary ramp Rows sort stalest-first within each stage, so the row that most needs acting on is the one at the top. TEST SEAM — scf-core resolves @scaffald/ui to a mock, so the four new primitives are added there. They mirror the real contracts rather than being stubbed: LaneGroup honours count/emptyState and Lane renders age first, since a stub that dropped those would make the screen logic under test unobservable. The change is additive — 171 insertions, zero deletions — so no existing consumer is affected. Verified: typecheck clean on scf-core and scaffald-app; lint clean; 17 new stage-timing tests and 11 new Lanes tests, all passing; an existing mock consumer (TeamMembersList) still passes. Not verified: the screen has not been seen rendering — it is behind auth and the office role. Note also that the full scf-core suite cannot be run locally: an unfiltered vitest run OOMs the worker, which is why prepush excludes it. Co-Authored-By: Claude Opus 5 <[email protected]> * fix(ats): segmented control for the view switch, not three Buttons Picks up the layout fixes from the @scaffald/ui submodule and fixes the same inversion on the app side. The view switch gave the ACTIVE view `variant="outline"` and left the other two on the default filled variant — so Board and Metrics rendered as the primary action while the view you were actually on looked disabled. It reads as a segmented control now, which is what the prototype uses and what the control is for. It carries an explicit width: SegmentedControl's segments are `flex: 1` inside a container with no intrinsic width, so left to the header row it collapsed to 160px and clipped "Metrics" to "Metr…". Worth fixing centrally later — noted rather than done here, because the component has other callers and there is currently no automated gate that would catch a regression in them (#375, #469). Found by rendering the primitives in Storybook, which needs no auth and so is the first look any of this work has had at a real browser. Verified: typecheck clean across all three packages; lint clean; Lanes tests 11/11; UI suite 649/670 with the same 21 pre-existing failures. Co-Authored-By: Claude Opus 5 <[email protected]> * chore(ui): point the submodule at merged main (Scaffald/ui#18) The branch pointer would have referenced a commit that only exists on redesign/phase1-tokens; the squash merge rewrote it. This points at 8b27d54 on origin/main so a fresh clone can resolve the submodule. Typecheck clean across all three packages against the merged pointer. Co-Authored-By: Claude Opus 5 <[email protected]> --------- Co-authored-by: Claude Opus 5 <[email protected]>
Summary
profile_verificationstable with verification/revocation functions and triggers that keep profile data in syncfieldidentifiers for client mappingTesting
https://chatgpt.com/codex/tasks/task_b_68d1d851d7e083319b862045fc9a2a83