Skip to content

feat(settings): choose which left-menu sections each role sees (menu access, part 3) - #1704

Merged
gkhngyk merged 15 commits into
ansvisor:mainfrom
cihan-gyk:feature/menu-access-settings
Oct 28, 2026
Merged

gkhngyk merged 15 commits into
ansvisor:mainfrom
cihan-gyk:feature/menu-access-settings

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Menu access, part 3: a new Settings › Menu access section. Stacked on #1703 (part 2), which is stacked on #1702.

  • It's for admins and the managers an admin lets change menus; MenuAccessProvider now also carries canManageMenus from getMyMenu. Others don't see it in Settings' list. At its address they get one line saying who can, and nothing is read. The server actions check again (requireMenuManager).
  • A table of the menu's sections by group (Execution, Analytics, Other), with one column per role:
    • each box saves at once (setRoleMenu, which revalidates the layout, so the sidebar follows without a client refresh); a failed save shows a toast and reads the settings again, so two quick clicks never leave the table out of step with what was saved;
    • the Admin column is always on, and Action Center can't be turned off;
    • "Use a set…" fills a role from a work area's ready-made set (Founders & leaders, AEO/GEO & Audit, Content, Brand & PR, …) or Everything.
  • Fixed column shares keep the table inside Settings' column at 1024 px, with the sidebar open or collapsed.
  • The copy is in en.json under settings.menuAccess, including the nine work areas' names and lines for the later Account and welcome-step parts.
  • Not in this PR: per-person exceptions and "who can change menus" (next part), and the plan dialog for a workspace whose plan has ended (after feat(web): let a workspace whose plan ended browse read-only, with one "Choose a plan" dialog #1599).

Related issue

None.

Type of change

  • feat — New feature

How to test

Same setup as part 2 (00374 on the dev database). Demo user 1111…, demo org 2222….

  1. cd web && yarn dev, then sign in as [email protected] / demo123.
  2. Settings: "Menu access" sits between Team and Authors, with a New badge. Its table has the Admin column and the Action Center row ticked and greyed out.
  3. Untick Analyst › Content, then reload: it stays unticked. select role, hidden_sections from organization_menu_roles where organization_id = '2222…'; shows analyst {content}.
  4. Manager › Use a set… › Brand & PR: the Manager column keeps only Action Center, Chat, Brand Visibility, Mentions, Citations and Reports.
  5. Permissions (as the database owner): update profiles set role = 'manager' where id = '1111…'; Reload. Settings has no Menu access, /dashboard/settings/menu-access says who can change menus, and the sidebar follows the Manager column from step 4. Then update profiles set can_manage_menus = true where id = '1111…'; Reload: Menu access is back and loads.
  6. Check light and dark themes, and 1024 px wide with the sidebar open and collapsed: no horizontal scroll.
  7. Put it back: update profiles set role = 'admin', can_manage_menus = false where id = '1111…'; delete from organization_menu_roles where organization_id = '2222…';

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes (0 errors; 7 warnings in files this PR doesn't touch)
  • yarn typecheck passes
  • yarn format leaves no changes
  • Changes are focused — one concern per PR
  • yarn test and yarn build pass, run on part 6's tip: 465 files, 4,561 tests; build OK (on part 6's tip 8c2e172).
  • bash supabase/build-schema.sh leaves schema.sql unchanged
  • Tests added (menu-access-section.test.tsx, incl. Use a set… and a failed save after a second click; _settings-view.test.tsx: Menu access listed only for menu managers)
  • npm run version:check (fails on main too: docker-compose images 0.2.0)

🤖 Generated with Claude Code

cihan-gyk and others added 14 commits October 28, 2026 14:02
… part 1)

Menu access, part 1 of 7: the data and the rule, with no UI yet.

- 00374 adds organization_menu_roles, the sections a role (not admin)
  doesn't see. Members of the organization read it and the server
  writes it.
- On profiles it adds menu_shown, menu_hidden and can_manage_menus,
  which only the server sets (00228's guard is extended), and
  work_areas and work_areas_asked_at, which the person sets.
- lib/menu-access.ts holds the rule: the role's sections, then the
  person's exceptions, narrowed to their work areas.
  - Action Center is always on.
  - Nobody takes a section off an admin's menu; only their own work
    areas narrow it.
  - A section is named by its route, so a new one shows by default.
- lib/actions/menu-access.ts covers getMyMenu, the Settings data, the
  role table, per-person exceptions and menu managers (admin only).
  It also writes the person's own work areas.

Hide only: pages still open from a link, roles and data access don't
change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…enu access, part 2)

The dashboard layout reads the viewer's menu once (getMyMenu, part 1) and
hands the sections it leaves out to a MenuAccessProvider. Both menus filter
by them through shouldShowDashboardNavItem:

- the sidebar drops a group whose sections are all off the menu, title and
  all;
- the mobile menu drops the active brand's Prompts link with the Prompts
  section.

If the menu can't be read, the whole menu shows. Hide only: an address
still opens its page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A removed member keeps their profile and an invitation moves it to the
next organization, so a menu manager of one organization arrived in
another still able to change its menus, with their old exceptions. A
trigger now clears menu_shown, menu_hidden and can_manage_menus on a new
organization and can_manage_menus on a new role, unless the same update
sets them; it fires after the guard, so the guard still checks what the
person asked for.

Also reloads PostgREST's schema at the end of 00374, validates
setMenuManager's flag with Zod, and tests that the work-area check in
the database lists exactly the app's work areas.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…access, part 3)

A new Settings section, Menu access, for admins and the managers they let
change menus. Others don't see it in Settings, and its address tells them
who can.

- A table of the menu's sections by its groups, with a column per role:
  - each box saves at once, and is put back with a toast if the save
    fails;
  - Admin is always Everything, and Action Center can't be turned off;
  - "Use a set…" fills a role from a work area's ready-made set, or
    Everything.
- Fixed column shares keep the table inside Settings' column at 1024 px.
- en.json carries the copy and the nine work areas' names and lines, so
  the Account and welcome-step parts can use them too.
- MenuAccessProvider also carries whether the viewer can change menus.

The plan dialog for a workspace whose plan has ended follows once ansvisor#1599
lands.

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

"What do you work on?" is for new sign-ups and people joining from an
invite, once. Without this, every existing person would get the step at
their next sign-in. They can still pick work areas in Settings › Account.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… access, part 2 review)

The dashboard layout read the viewer's menu through getMyMenu, a second
user check and profile read after its own: two or three requests in a row
on every render. The menu columns now come with the profile the layout
already reads. The role's row (none for admins) is read alongside the
organization and the brands. menuOfProfile builds the menu from both,
and getMyMenu uses the same.

- A role row that can't be read is logged (console.error) and the menu
  shows whole, rather than the failure passing silently.
- The sidebar no longer reads the tracked prompts' count while Prompts is
  off the menu.
- Tests cover a group dropped with its title when all its sections are
  hidden, the whole menu without a menu to go by, the count not read, the
  mobile menu leaving hidden sections off (the brand's Prompts link with
  Prompts), and readRoleHidden.

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

# Conflicts:
#	web/src/app/[locale]/(dashboard)/layout.tsx
…let "Use a set…" fit (menu access, part 3 review)

- A failed save on Menu access reads the role table again, instead of
  putting back the state from before it, which also undid a later save
  that had gone through.
- No router.refresh after a save: setRoleMenu's revalidatePath already
  brings the menu up to date, so each click no longer renders twice.
- The role columns get a little more of the table, and the select's
  chevron is smaller, so "Use a set…" isn't cut at 1024 px with the
  sidebar open.
- Tests: picking a ready-made set saves it; a failed save next to a
  successful one keeps the successful one; Settings lists Menu access
  only for someone who can change menus.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…menu access, part 3 review)

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 Oct 28, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, with follow-ups.

What I checked:

  • Own change. The diff from part 2's head (c323a26) to c00f8e1: f87fd5b (feature), fc4d5f4 and c00f8e1 (review fixes), and three merges of part 2. It touches no migration, so 00374 is the same as in part 1. On today's main, only part 1's supabase/schema.sql conflicts. en.json changed on main too, but merges cleanly.
  • Who sees it. The layout now passes canManageMenus to the provider. Settings lists Menu access only for admins and the managers an admin allowed. Anyone else who opens /dashboard/settings/menu-access from a link sees a short "not allowed" card, and their settings are never read. The server still decides: getMenuAccessSettings and setRoleMenu both call requireMenuManager, work only on the caller's organization, and setRoleMenu refuses any role outside manager, analyst and agency partner. So nobody can change the admins' row, whatever the client sends.
  • Hide only. The admins' column is ticked and can't be changed, and so is Action Center for every role. The note says the pages still open from a link and that nothing about what a role can do changes, which matches parts 1 and 2.
  • Saving. Each box saves the role's whole list in the menu's order, and the change shows at once. When a save fails, the section shows an error message and reloads the settings from the server, so another save that did go through stays. "Use a set…" stays a placeholder (value="" plus items), so you can pick the same set again. "Everything" hides nothing. Each set hides the sections its work area doesn't name, and never Action Center. The Select has items on its root, as our Select rule asks.
  • Copy. The role names come from the existing settings.team_role_* keys, and the section names from nav, so the table reads like the menu. en.json is the only locale file.
  • Tests. I ran the section's tests, the Settings view and _sections tests, and part 2's sidebar, mobile-nav, navigation, menu-access and actions tests on the PR's tree: 83 tests pass. menu-access.test.ts reads supabase/migrations, so I laid that folder out next to web. tsc shows no errors in the changed files. It does report 13 errors elsewhere, from packages missing in my test setup; those are the same without this change.
  • Deploy. This part depends on part 2's layout, so the same merge condition applies: 00374 goes on the database first.

Follow-ups (none block):

  1. Picking a set replaces every box the role had, with no undo and no confirmation. Either ask first ("Replace Manager's sections with Brand & PR?") or show an "Undo" toast that saves the previous list back.
  2. Wording of settings.menuAccess.notAllowed. "Only admins, and managers an admin lets, choose…" reads as if a word is missing. Suggest: "Only admins, and managers an admin has allowed, can choose what each role sees on the menu."
  3. hiddenForSet hides every section the set doesn't name. A person's work areas, in contrast, keep any section no work area names (AREA_SECTIONS in hiddenMenuSections). Today every menu section is in some work area, so the result is the same. But a section added later would be hidden by a set and kept by work areas. Use the same rule here (skip sections not in any area) so the two can't drift apart.

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.

2 participants