Repository navigation
feat(db): add per-brand access for people: brand scope, member brands and access helpers (00388) - #1878
Merged
Conversation
… and access helpers (00388)
BRAND-ACCESS PR 1 of 16: the data and the rule, no behaviour change.
Everyone starts with All brands, and no policy reads it yet.
- profiles.brand_scope ('all' | 'selected', default 'all'), set by the
server: 00374's guard refuses a person's own change; admins are always
'all' (a check, and a reset on promotion); leaving the organization
resets it to 'all'. A move straight into another organization keeps the
scope the update gives, so it never widens access by itself.
- member_brands (organization, person, brand, granted_by, granted_at),
one row per person and brand, gone with the brand, the person or the
organization; a trigger keeps the brand and the person in the row's
organization. The person reads their own rows, admins the
organization's; only the server writes. The rows go when the person
moves, leaves or gets All brands.
- invitations.brand_scope / brand_ids, checked against the organization.
- public.can_access_brand(brand, person default auth.uid()) and
public.user_brand_ids(): STABLE, SECURITY DEFINER, empty search path,
for authenticated and service_role only. Admin, All brands, a shared
brand or the demo brand, in the person's organization; another
person's id only for the service role.
- A brand added by a Selected-brands person is shared with them (after
insert trigger).
- web types, and member_brands on the demo coverage's skipped list.
- server/src/lib/brand-access-schema.test.js reads the migration.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
8 of 13 tasks
gkhngyk
approved these changes
Oct 31, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Merging in order with the other approved PRs. This head merges current main; its tree is what main will be after this squash, checked with the full server and web suites, tsc, lint, format and next build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The first PR of brand-level access (spec: one Account, several brands; a person sees All brands or Selected brands). Migration 00388. Nothing changes for anyone yet: everyone stays
all, and nothing reads the new pieces until the RLS and UI PRs.Owner's decisions (2026-10-30):
00388
profiles.brand_scope('all'|'selected', default'all'):'all'(check), and promotion to Admin resets it;'all';'selected', so a Selected-brands invite can't turn into All brands. Grants are deleted in both cases.member_brands(organization_id, user_id, brand_id, granted_by, granted_at):(user_id, brand_id); cascades on brand, user and Account deletion;invitations.brand_scopeandbrand_ids uuid[]. The ids are only allowed with'selected', an Admin invite must be'all', and the ids must be the invitation's Account's brands.can_access_brand(p_brand_id, p_user_id default auth.uid())anduser_brand_ids():search_path = '';'all', was given the brand, or the brand is the demo brand;'selected'person is granted to them (after-insert trigger).web/src/types/supabase.tsupdated.member_brandsis on the demo coverage skip list.Related issue
None. Brand-level access, PR 1 of ~16 (spec
BRAND-ACCESS).Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
psql -1 -f).update profiles set brand_scope='selected' where id = auth.uid()→ 42501;insert into member_brands …→ 42501.select public.user_brand_ids()as anon → permission denied.server/src/lib/brand-access-schema.test.jsandcoverage.test.js.Applied on the dev database and checked:
allwith ids → check, Admin +selected→ check.Checklist
yarn lintpasses (0 errors; 7 old warnings in files this PR doesn't touch)yarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change): no user-visible changesupabase/schema.sqlwas rebuilt withbuild-schema.sh. Web and server suites pass. The one exception waschat-menu.test.tsx's clock case, fixed in #1876.For production (@gkhngyk): apply 00388 in one transaction. It sorts before 00400–00423, so it needs
--include-all, as #1873's 00387 did. No env or cron.🤖 Generated with Claude Code