Repository navigation
feat(chat): check a person's brand access in Chat and agents (brand access PR 9, 00436) - #1975
Merged
Merged
Conversation
…ccess PR 9, 00436) BRAND-ACCESS PR 9 (spec §5.3, §10). Everyone still has All brands, so nothing anyone sees changes until the Team screen narrows someone. - web/src/lib/brand-access.ts: the web's one server-side rule, read with the service role as the API server's lib/access.js reads it: readBrandAccess (all, the shared brand ids plus the demo brand, or null for a non-member), canAccessBrand (the database's can_access_brand, optionally within a workspace), hasBrandAccess, allowedBrands, readAccessProfile and brandAccessOf. Before 00388 everyone counts as All brands. Chat's session-free writers (actor/access.ts) use it too. - Chat: readPrecedenceContext and readAgentContext read the real access from the profile they already read, so the precedence refuses a brand that wasn't shared (brand_scope). startChatRun and createChat refuse a brand the person can't use, and a chat about a brand they lost answers not found (§9 Q4). list_brands and list_connections list their brands only. - Agents: all_brands means all brands of the person a run acts as; runnableBrands takes that access, triggers queue on the owner's brands, and the driver checks again at start (a lost brand stops the run as brand_gone, none left pauses the agent). A scope brand the person can't use is refused as not found; list and detail show only their brands' names and runs; a Selected-brands owner sees their own All-brands agent. - 00436: chat_conversations/chat_files.touched_brand_ids (null = not known, every existing row), chat_start_touched_brands and chat_note_touched_brands (service role only), a chat_files trigger that copies its chat's set, the shared-chat and files policies that also let in a brandless row whose touched brands are all the person's, and can_see_chat_agent for chat_agents (versions, triggers and runs follow; off the coverage test's deferred list). The engine notes each call's brand before the call runs (a failed note refuses the call); a web deployed before 00436 notes nothing. schema.sql and types regenerated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o their owner's brands (00436) Review follow-ups for brand access PR 9, before PR 12 turns narrowing on. 00436 has been applied nowhere yet, so it changes in place. With everyone on All brands nothing anyone sees changes. - 00436: a chat or file about one brand that touched another is read by a Selected-brands person only when every touched brand is theirs: the shared-chat, agent-run-chat and files policies (admins and All-brands people as before; not-known rows stay hidden from Selected brands). A file made outside a chat keeps its own brand, and the files there are get it too. chat_agents' policy filters by the caller's organization before can_see_chat_agent. - An agent run's chat starts its touched set from the run's brand. A message's @ references note their brands before the message goes in (a prompt's or task's own brand, the page's brand chip for a page, chart, metric or table; the whole workspace when it can't tell). - A database without chat_note_touched_brands makes the chat's set not known instead of leaving it; a missing column is ignored. - The run's precedence hands its brand access to the tool context (McpAuthContext.brandAccess, brandAccessFor), so list_brands and list_connections read it once. The chat's own brand is never noted again. - A triggered agent whose owner may use none of its brands pauses as brand_gone. An Admin's Resume of someone else's agent checks the owner's brands and their connections. - brand-access.ts fails closed: All brands only for an Admin or an explicit 'all' scope, and canAccessBrand throws without can_access_brand. Co-Authored-By: Claude Opus 5.5 <[email protected]>
8 of 13 tasks
8 of 13 tasks
# Conflicts: # supabase/schema.sql
6 of 13 tasks
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
Brand access PR 9: Chat and agents check each person's real brand access. It adds one server-side rule for the web,
web/src/lib/brand-access.ts, which mirrorscan_access_brandand the API server'slib/access.js. Migration 00436. Everyone still has All brands, so nothing anyone sees changes until PR 12 (the Team UI).What changes
brand-access.ts:readBrandAccess,canAccessBrand,hasBrandAccess,allowedBrands,readAccessProfile/brandAccessOf,hasAllBrands. It fails closed: All brands only for an Admin or an explicit'all'scope, a read error throws, andcanAccessBrandthrows withoutcan_access_brand.'all'is gone);list_brandsandlist_connectionslist only their brands, from the same read precedence made.touched_brand_idsonchat_conversationsandchat_files):null) stays hidden from them.all_brandsmeans all brands of the person a run acts as, checked again at run start.brand_gone.chat_agentsRLS goes throughcan_see_chat_agent(id)(security definer, fixedsearch_path), after an organization pre-filter.schema.sqlandtypes/supabase.tsare regenerated.For PR 11 and PR 12:
list_membersstill says'all'.Related issue
None. Brand access plan, PR 9 (spec §5.3, §10).
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
Checked on the dev database with 00436 applied, in a rolled-back transaction. A second demo-workspace member shared four chats:
The admin (All brands) sees all four, as before. The same person as a Selected-brands manager with nothing shared sees only chat 2. The demo brand is everyone's, so that is the one they may read.
Counts the admin can see in conversations, files, agents and runs are the same before and after.
Unit tests:
brand-access,touched-brands, Chat precedence, agents, triggers and driver, Resume,list_brands/list_connections, and the migration-reading server tests.A pre-push review found no blocking issue; its follow-ups are in.
Needs migration on prod: 00436 (gkhngyk).
Checklist
yarn lintpasses (0 errors; 7 old warnings in files this PR doesn't touch)yarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change)CI passed on this branch (1776a4d), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41361035770): schema is up to date; web
format:check, lint, typecheck, all tests andyarn buildpass; server lint,format:checkand all tests pass.🤖 Generated with Claude Code