Skip to content

feat(web): choose the brands each person sees in Settings > Team (brand access PR 12, 00471) - #2050

Merged
gkhngyk merged 13 commits into
ansvisor:mainfrom
cihan-gyk:feature/brand-access-team
Nov 4, 2026
Merged

gkhngyk merged 13 commits into
ansvisor:mainfrom
cihan-gyk:feature/brand-access-team

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Brand access PR 12 (Team UI): admins choose which brands each person sees. This is the PR that turns the feature on: until now everyone had All brands. Migration 00471. Spec: BRAND-ACCESS §3.1, §3.2, §9 and §10 ("PR 12 must"). Stacked on #2042 (PR 14, 00470); merge it first (§10: Google per brand before anyone can be narrowed).

Settings › Team

  • Invite member: after the role comes Brands: All brands or Selected brands with a brand picker. Selected brands needs at least one brand. The invitation keeps the choice until it's accepted. An Admin is always All brands, so the choice is locked for that role. The demo brand isn't listed, since everyone sees it.
  • Each person's row shows admins All brands or N brands. Clicking it opens Edit brands (All / Selected + picker, then Save). An admin's own row and other admins' rows just say All brands. A non-admin sees only their own scope.
  • Pending invitations show admins the brands each one shares.
  • Plans: the choice appears only on a plan with more than one brand (§9 Q1), and only admins change it (§9 Q2).
  • Read-only workspace: Edit brands opens the upgrade dialog, as a role change does.

Roles & access and Your access

  • The Brands column shows the real scope: All brands, or N brands with the names. Names show for admins and for the person themselves; anyone else sees "Selected brands".
  • Your access lists the person's brands, with a note that an Admin chose them.

00471: writes in one transaction (§10)

  • accept_invitation(invitation, person) locks the invitation, then:
    • joins the person with its role and brand scope, written explicitly, so a Selected-brands invitation never becomes All brands;
    • shares the invited brands that still exist (deleted ones are skipped; the demo brand needs no grant);
    • marks the invitation accepted.
  • set_member_brand_access(org, person, scope, brands, by) locks the profile and replaces the person's brands exactly. It never narrows an admin, and Selected needs at least one brand of the organization.
  • Both are security invoker and callable by service_role only. The server checks the invitation's e-mail and expiry, and the caller's admin role, first.
  • Until 00471 is applied, acceptInvitation falls back to the old path for All-brands invitations only. A Selected one says it can't be accepted yet.

Help: new article help/settings/team-brands.md (approved: false).

Related issue

None. BRAND-ACCESS spec, PR 12.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Apply 00471. Sign in as an admin on a plan with more than one brand and open Settings › Team.
  2. Invite member: pick Selected brands. Send invitation stays off until a brand is ticked. Send it; the pending row shows "1 brand".
  3. Accept the invitation as that person. They see only that brand (and the sample brand) in the switcher, on every page and in Chat.
  4. As the admin, click the person's 1 brand and choose All brands, then Save. On their next page they see every brand.
  5. Roles & access shows each person's brands. Account › Your access shows your own.
  6. cd web && yarn vitest run src/lib/actions/team.test.ts src/lib/actions/team-brands.test.ts src/components/settings/team-section.test.tsx src/components/chat-access src/lib/actions/chat-access.test.ts src/lib/help
  7. cd server && npx vitest run src/lib/brand-access-team.test.js src/lib/brand-access-policies.test.js. The policy test's "nobody narrowed while a table is deferred" check now sees narrowing code and passes, since PR 14 emptied the list.

Screenshots (1024 px, light and dark): Team, the invite dialog with Selected brands, Roles & access, Your access.

Needs migration 00471 on prod (gkhngyk), after 00470.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes (changed files)
  • yarn typecheck passes
  • yarn format:check passes (changed files)
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

CI passed on this branch (8d3de26), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41568770690): schema is up to date; web format:check, lint, typecheck, all tests and yarn build pass; server lint, format:check and all tests pass.

🤖 Generated with Claude Code

cihan-gyk and others added 3 commits November 3, 2026 00:56
…ign-ins (brand access PR 14, 00470)

- 00470: integration_accounts (the Account's Google logins and CMS sites,
  Composio's entity and connected account ids, never a token) and
  brand_integrations (the sign-in each brand uses per provider, settings
  jsonb for later). The Account's Google rows are copied as sign-ins used by
  every brand; each CMS connection as a sign-in used by its brand. Triggers
  keep the pool in step while Settings > Integrations and the CMS cards still
  write the old tables, and give a new brand the Account's Google sign-ins.
  RLS: a brand's rows for people who can access it (user_brand_ids), a
  sign-in for people who can access a brand that uses it; the server writes.
  integration_connections loses its unused admin/manager write policy.
- Server: lib/brand-integrations.js resolves a brand's connection; the GSC
  and GA syncs, the Action Center's Analytics tool and sources use it, and
  every Google call names the connected account (several may share a
  Composio entity). The property lists take ?brandId= for the brand's own
  sign-in; without it, the Account's list for All brands as before.
- Web: lib/brand-integrations.ts; suggestion sources, AI Referral Traffic and
  Chat's Google reads ask it. Both resolvers read the Account's row until
  00470 is applied.
- Tests: resolver, schema, policy coverage (integration_connections off the
  deferred list), demo coverage, syncs, routes.

Behaviour-neutral while everyone is 'all': every brand uses the Account's
Google connection, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… database stub

resolveBrandSources reads the brand's Analytics connection through
lib/brand-integrations.js (00470), which asks for one row with maybeSingle;
the generate test's PostgREST stub had no maybeSingle, so every
generateActionsForBrand test threw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd access PR 12, 00471)

- Invite: role, then All brands or Selected brands with a brand picker (at
  least one); the invitation keeps the choice. Admins are always All brands.
  Only on plans with more than one brand.
- Team: each person's row shows All brands or "N brands" to admins, with
  Edit brands; pending invitations show theirs. Admins only change it.
- Roles & access: the Brands column shows the real scope (names for admins
  and for the person); Your access lists the person's brands.
- 00471: accept_invitation joins the person with the invitation's role and
  brand scope and shares the invited brands that still exist, in one
  transaction; set_member_brand_access replaces a person's brands in one,
  the profile locked. Both service-role only. acceptInvitation falls back to
  the old path for All-brands invitations until 00471 is applied.
- Help: settings/team-brands (approved: false).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 3, 2026
…ery brand on them

A brand's property list, its one-brand sync and its property pick now need
access to every brand that uses the brand's Google sign-in (All brands before
00470), since every brand still shares the Account's sign-in. Property picks
move from a direct brands update to a server route that checks the pick
against the brand's own sign-in's list, then starts the brand's sync.
Chat's list_members said every member had All brands. Read the scope from
member_brands as Settings > Roles & access does: 'all' or 'selected', with
the brand names for admins and for the person themselves only.
A brand's Search Console site and Analytics property are picked through
the server, which checks the pick against the brand's sign-in. A
trigger now refuses a member's own insert or update of those two
columns, so the check can't be gone around.
gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
00472 is taken by another open PR (report cards).
gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
@gkhngyk

gkhngyk commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

This PR now conflicts with main: #2042 was squash-merged, so its commits are on main under new hashes. Could you merge main into this branch (or rebase it onto main) and resolve the conflicts? Once CI is green I'll merge it.

Stacked on it and needing the same, in order: #2055. Updating each after the one below it has merged keeps the conflicts small.

@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main in (no rebase): #2042's squash recorded with -s ours after checking its content matches, so the diff is again only this PR (00471 + Team UI + list_members).

@gkhngyk gkhngyk closed this Nov 4, 2026
@gkhngyk gkhngyk reopened this Nov 4, 2026
@gkhngyk gkhngyk closed this Nov 4, 2026
@gkhngyk gkhngyk reopened this Nov 4, 2026
@gkhngyk
gkhngyk merged commit ecee900 into ansvisor:main Nov 4, 2026
11 of 13 checks passed
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 4, 2026
Brand access PRs 12 and 14 landed on main as ansvisor#2050 and ansvisor#2042 with review
changes. Main's versions are kept, and PRs 13 and 15 and their fixes are
re-applied on top: the integrations routes keep main's sign-in reach check
(assertSignInReach) and per-brand property PUT routes next to the brand's
own sign-in routes, and the demo guard names both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants