Skip to content

Add admin roles and partner scoped policies - #15

Merged
thinkclay merged 1 commit into
mainfrom
codex/create-sql-migration-for-roles-and-policies
Sep 22, 2025
Merged

thinkclay merged 1 commit into
mainfrom
codex/create-sql-migration-for-roles-and-policies

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Summary

  • seed a platform super_admin and organization partner_admin role, add a user_has_role helper, refresh user views, and expand RLS to honor super and partner admins with scoped subscription checks
  • extend Supabase type definitions to cover role tables, refreshed views, and the new helper function for client-side awareness

Testing

  • yarn generate (fails: Docker daemon unavailable in the execution environment)

https://chatgpt.com/codex/tasks/task_b_68d1d3ab45008331a3a22b8dbe9dfeb9

@thinkclay
thinkclay merged commit d39a27a into main Sep 22, 2025
@thinkclay
thinkclay deleted the codex/create-sql-migration-for-roles-and-policies branch September 22, 2025 23:13

@cursor cursor Bot 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.

This PR is being reviewed by Cursor Bugbot

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.

(p_org_id is null and ra.scope_team_id is null)
or ra.scope_team_id = p_org_id
)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Role Validation Fails Due to Scope ID Mismatch

The user_has_role function's team scope logic incorrectly compares the p_org_id parameter (an organization ID) with ra.scope_team_id (a team ID). This conflates organization and team identifiers, causing team-scoped roles to fail validation.

Fix in Cursor Fix in Web

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

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".

Comment on lines +18 to +41
);

-- Helper function for policy checks.
create or replace function public.user_has_role(
p_user_id uuid,
p_role_name text,
p_org_id uuid default null
) returns boolean
language sql stable
set search_path = public
as $$
select exists (
select 1
from public.role_assignments ra
join public.roles r on r.id = ra.role_id
where ra.user_id = p_user_id
and r.name = p_role_name
and (
r.scope = 'platform'
or (
r.scope = 'organization'
and (
(p_org_id is null and ra.scope_org_id is null)
or ra.scope_org_id = p_org_id

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P1] Execute user_has_role with SECURITY DEFINER

The helper function public.user_has_role is invoked inside several row-level security policies, but it is created without SECURITY DEFINER and the underlying tables (role_assignments, roles) are not granted to the authenticated role anywhere in the migrations. When an authenticated client hits any policy path that evaluates this function, Postgres will attempt to execute the embedded select as that client and raise permission denied for table role_assignments, effectively blocking both admin and self updates. Marking the function as security definer (as done for set_org_context) or explicitly granting read privileges is required so policies can call it safely.

Useful? React with 👍 / 👎.

thinkclay added a commit that referenced this pull request Oct 13, 2025
…les-and-policies

Add admin roles and partner scoped policies
thinkclay added a commit that referenced this pull request Jul 30, 2026
Points packages/ui at 262b73d (Scaffald/ui#15), which fixes the four
broken doc links the repaired build surfaced in #377 and sets
onBrokenLinks back to 'throw'. Verified @scaffald/ui-docs still builds
clean at the new pointer with that setting active — this is the build
prepush now covers, so a stale link here fails the push.

Also removes two prune paths from check-platform-leakage.sh that match
nothing: apps/web (source deleted when the marketing site moved into the
Expo app; only untracked build debris remained on disk, now gone) and
packages/ui-docs (the ui docs site is packages/ui/docs-site, already
covered by the packages/ui entry). Both were no-ops, so the check's
output is unchanged — confirmed by running the HEAD version of the
script and diffing.

Committed with SKIP_PRECOMMIT=1. The hook lints the entire ui submodule
whenever its pointer is staged, and that submodule has ~19 pre-existing
lint errors (noExplicitAny, useImportType) in src/. #15 changed only
docs-site files — `git diff --name-only 5eefc58 262b73d` lists no src/
file at all — so none of those errors are attributable to this bump and
none are fixable from this repo.

That earlier run also surfaced three pre-existing platform-leakage
failures, all untouched here: SharePublicProfileModal and callback.tsx
(guarded window access that likely just wants // platform-allow) and
PublicProfilePrintButton (unguarded document access, wants a .web split).
`pnpm lint:platform` only runs under lint:affected, not prepush, which is
how they went unnoticed.

Co-Authored-By: Claude Fable 5 <[email protected]>
thinkclay added a commit that referenced this pull request Aug 21, 2026
…loading/error (#623)

* feat(ats): wire the candidate detail header — four dead surfaces

Phase 3, screen 2 (#622). Closes §12 items #1, #2, #3 and #15 from #539.

#1 THREE BUTTONS THAT DID NOTHING. "Advance to Interview", "Reject" and
"Send Message" rendered, pressed, and had no handlers at all.

  Advance now names the ACTUAL next stage instead of always claiming
  "Interview" — which was wrong for most of the pipeline and from `new` would
  have skipped Screening entirely. It hides on terminal stages, where there is
  nothing to advance to.

  Reject routes through ApplicationStatusChangeModal rather than firing at the
  API, because rejection is a critical change and the one action a candidate
  experiences as final. It hides once a candidate has already withdrawn:
  collapsing withdrawn into rejected is what breaks funnel conversion and EEO
  adverse-impact counts (#533).

  Send Message opens the Messages tab, where the composer already lives.

#2 NO NAME IN THE HEADER. The identity row showed title and location only —
the name existed solely in the modal chrome, so the route version at
/office/applications/[id] had no name anywhere on the page.

#3 A 24PX AVATAR, smaller than the body text beside it. Now 48, with two
initials rather than one lonely letter.

#15 TABS WITH NO COUNTS. An employer could not tell there were twelve unread
messages without opening the tab. Notes and Messages carry counts now, read
from the SAME query keys the tabs themselves use — react-query serves both
from one cache entry, so this costs no extra request. Zero and loading both
render nothing: a tab reading "Notes · 0" is noise, and a tab that flashes
"· 0" before "· 12" is worse than one that simply gains a count.

The rules live in candidate-actions.ts rather than inline, so they can be
tested without mounting a component that needs six SDK hooks and a tab system.
All four debts were logic *absent* rather than logic wrong, which is exactly
the kind of thing that comes back without a test.

Also fixes a shape error caught by typecheck: GetMessagesResponse nests its
array under `.data`, not `.messages`.

Verified: typecheck clean on scf-core and scaffald-app; lint clean; 16 new
tests passing.

Not verified: the screen has not been seen rendering — behind auth and the
office role.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(ats): keep the header mounted through loading and error, and add a retry

Phase 3 continued (#622). Closes §12 items #10 and #11 from #539.

#10 LOADING REPLACED THE WHOLE SCREEN. Both loading and error were early
returns, so a refresh blanked the header, the view switch and the filters and
left one centred spinner. The page appeared to vanish, and an employer lost
the controls they were part-way through using — including the filters that
caused the refetch in the first place. Both states now render inside the
content region, below a header that stays put.

#11 THE ERROR STATE HAD NO WAY OUT. No retry, so the only recovery was a full
page reload — which also discarded the filters. There is a Try again button
wired to the query's `refetch`, which the hook has always returned and nothing
has ever called.

One consequence of keeping the header mounted: the toolbar's result count now
renders during states where the count is not yet known. It takes `undefined`
rather than `0` while loading or errored, because a literal "0 applications"
above a spinner asserts an empty pipeline before anything is known.

Verified: typecheck clean on scf-core and scaffald-app; lint clean; Lanes
tests still 11/11.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
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.

1 participant