Skip to content

fix(rbac/ui): gate Settings → Agent Save / Remove controls behind canAdmin - #142

Merged
gkhngyk merged 1 commit into
mainfrom
fix/settings-agent-role-gate
Jun 1, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/settings-agent-role-gate

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Closes #131.

What

Same pattern as #141, smaller scope. The /api/settings/anthropic-key PUT and DELETE handlers already enforce role === 'admin' (returning 403 for anyone else), but AgentSection rendered the new-key Input, Save button, and Remove key button to every org member. Clicking any of them just produced an unhelpful toast from the catch.

This PR wraps that whole control surface in a single canAdmin branch using the useUserRole hook landed in #141. The GET endpoint stays member-readable (it only returns metadata — configured, last4, set_at, set_by_email — never the plaintext), so non-admins still see the same configured / unconfigured status block.

Non-admins now see:

🔒 Admin-only setting — Only org admins can add, replace, or remove the Anthropic API key. Ask an admin if you need it changed.

Test plan

  1. Sign in as admin → AgentSection behaves exactly as before: new-key input + Save + Remove button.
  2. Sign in as manager / analyst / agency_partner → status block visible (read), no input, no buttons, just the 🔒 banner.

Out of scope

Other write surfaces still using the same admin-or-manager RLS posture (brand_domains, brand_platforms, content_opportunities). Each becomes a small follow-up that reuses useUserRole.

…Admin

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.
@gkhngyk
gkhngyk merged commit 854beb1 into main Jun 1, 2026
3 checks passed
@gkhngyk
gkhngyk deleted the fix/settings-agent-role-gate branch June 1, 2026 14:11

This branch was successfully deployed

1 active deployment
Preview — fa071950 Deployed Jun 1, 2026 by vercel[bot]
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.

Settings → Agent: non-admin roles see Save / Remove key controls

1 participant