Repository navigation
feat(rbac/ui): hide write controls on Manage Prompts & Manage Topics for non-admin/manager roles - #141
Merged
Conversation
…for non-admin/manager roles Closes #140. Analyst-role users (and agency_partner) were seeing Generate Suggestions, Save Selected, Add Prompt, Add Topic, Edit, Delete — all the write controls — even though the DB-side RLS on prompts / prompt_sets / topics restricts inserts to admin | manager. Clicking any of them fired the action, Postgres rejected it, and the user got a generic 'Failed to save' toast with no explanation. The fix mirrors the existing PlanProvider / useFeatureGate pattern: - RoleProvider + TeamRole type in web/src/components/providers/role-provider.tsx. - useUserRole() hook returning { role, canManage, canAdmin }. canManage matches the admin-or-manager RLS gate used across prompts, prompt_sets, brand_domains, content_opportunities — the same shape the DB enforces. canAdmin is the stricter admin-only check. - Optional <RoleGate roles={[...]} fallback?> sugar wrapper. - The dashboard layout already fetches profile.organization_id / onboarding_completed; just add role to the select and pass it into RoleProvider. Then apply canManage on the two pages this issue called out: - Manage Prompts: the top 'Add Prompt + AI Generate' section and the 'Review AI Suggestions' Save Selected card are gated. Read-only users see a small banner explaining 'ask an admin or manager to make changes'. - Manage Topics: per-row Pencil + Trash2 controls and the bottom Add Topic form are gated. Same banner pattern in the empty space. Per-row edit / delete inside the prompt list (PromptSuggestionCard mode='manage') is out of scope for this PR — those controls also fail silently for analyst, but the issue specifically called out the suggestions flow as the painful path. Tracked in the issue body as a follow-up that should reuse useUserRole once the primitive exists.
gkhngyk
added a commit
that referenced
this pull request
Jun 1, 2026
…Admin (#142) Closes #131. Same pattern as #141 — server-side /api/settings/anthropic-key PUT and DELETE already enforce role === 'admin' (returning 403 for anyone else), but the AgentSection rendered the Save input + Remove Key button to every member. Clicking either just produced an unhelpful toast. Wraps the new-key input, Save button, and Remove key button in a single canAdmin branch via the useUserRole hook landed in #141. Non-admin users see the same configured / unconfigured status block (GET is intentionally member-readable — only metadata is returned, never the key) plus a small 'Admin-only setting' banner explaining why the controls are gone.
Closed
7 tasks
This branch was successfully deployed
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.
Closes #140.
What
Analyst-role users (and agency_partner) were seeing Generate Suggestions, Save Selected, Add Prompt, Add Topic, Edit, Delete — all the write controls — even though the DB-side RLS on
prompts/prompt_sets/topicsrestricts inserts toadmin | manager. Clicking any of them fired the action, Postgres rejected it, and the user got a generic 'Failed to save' toast.Pieces
Reusable RBAC primitive (mirrors the PlanProvider / useFeatureGate pattern)
web/src/components/providers/role-provider.tsx—RoleProvider+ theTeamRoletype. Lives next to the provider so client components can import the type without crossing the'use server'boundary inlib/actions/team.ts.web/src/hooks/use-user-role.ts— returns{ role, canManage, canAdmin }.canManage=admin | manager(matches the DB RLS gate onprompts,prompt_sets,brand_domains,content_opportunities,topics).canAdmin=adminonly (matches team management + Anthropic-key write gate).web/src/components/auth/role-gate.tsx— small<RoleGate roles={[…]} fallback?>sugar wrapper. Not used in this PR's diff but included so the next surface can use either the hook or the wrapper without a fresh round-trip through the codebase.profile.organization_id/onboarding_completed; this PR addsroleto the same select and passes it intoRoleProvider.Apply it to the two pages this issue called out
brands/[id]/prompts/page.tsx): the entire top 'Add Prompt + AI Generate' grid and the 'Review AI Suggestions' Save Selected card are wrapped in{canManage && …}. Read-only users see a small<Lock>banner explaining 'ask an admin or manager to make changes'.brands/[id]/topics/page.tsx): per-row Pencil + Trash2 controls and the 'Add Topic' form are gated. Same banner in the bottom slot.Test plan
Out of scope (separate PRs that should reuse
useUserRole)PromptSuggestionCard mode='manage'). Those controls also fail silently for analyst — same RLS — but the issue specifically called out the suggestions flow as the painful path. Tracked.brand_domains(Manage Brand Domains),brand_platforms,content_opportunities(Content page approve / dismiss).useUserRolelanded, that issue collapses to a few-line change.Verification
pnpm tsc --noEmitcleanyarn lintclean (0 errors, 11 pre-existing warnings)