Repository navigation
feat(settings): store who sees which menu sections, by role, person and work area (menu access, part 1) - #1702
Merged
Conversation
… 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]>
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]>
…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]>
This was referenced Oct 28, 2026
Merged
gkhngyk
approved these changes
Oct 28, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good, with follow-ups.
What I checked:
- Own change. 8a04bfa (feature) and 5120e33 (reset on an organization or role change), with one merge of main in between (c572e41); a re-merge of its parents gives the same tree. On today's main only
supabase/schema.sqlconflicts. 00374 clashes with no other open PR. - 00374.
organization_menu_roles: RLS on,authenticatedgets select only, and only for the person's own organization; no grant toanon; writes go through the service role.role <> 'admin'is a check.guard_profile_server_columnskeeps 00228's role and organization rules word for word and adds the three menu columns.work_areasandwork_areas_asked_atstay the person's own, and the check lists exactlyWORK_AREA_IDS(tested).reset_profile_menu_accessruns after the guard (name order, tested), only editsNEW, and hassearch_path = ''. Removing someone and then inviting them elsewhere clears their exceptions and the menu right. A role change clears the right.- The new columns are
not nullwith constant defaults, so adding them doesn't rewrite the table.
- Actions. Every write re-reads the caller's profile on the server, and changes another member's row only within the caller's organization. Admin-only and manager-only targets are enforced, and inputs are bounded by Zod.
setMyWorkAreaswrites through the person's own client. I removed the admin check, the organization filter, the manager-only target and the role condition incanManage, one at a time, and the tests caught each one. - Tests. Both test files pass on the PR's tree (35 tests). Without the change they don't run, because the modules are new.
- Deploy. 00374 is applied to production (re-checked as signed-in and anonymous users before applying). The combined tree of parts 1–6 passes the server and web tests, lint, format, typecheck and the schema build.
Follow-ups (none block):
- No test covers the guard's new menu block. If I delete it, every test still passes. Add a text test like the reset one: 00374's
guard_profile_server_columnsbody is 00228's plus a block that namesmenu_shown,menu_hiddenandcan_manage_menus. That way a later edit can't drop the menu block or 00228's role and organization rules without a test failing. - Make each check and its write one statement. In
setMemberMenu, add.neq('role', 'admin')to the update. InsetMenuManager, add.eq('role', 'manager'). Then read the updated row back (.select('id')) and throw when nothing matched. A role change between the read and the write then can't slip through. - For part 2:
currentProfilethrows "No organization" for someone without one, for example during onboarding or after removal. Have the layout'sgetMyMenucall return an empty menu for them instead of failing the page.
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
Menu access, part 1 (data + rules, no UI yet): admins, and managers they allow, choose which left-menu sections each role sees, with per-person exceptions; each person can pick what they work on, which narrows their own menu. Hide only: a hidden section's pages still open from a link, and roles and data access don't change.
00374_menu_access.sql:organization_menu_roles: per organization and non-admin role, the hidden sections. Members read; the server writes.profiles:menu_shown,menu_hidden,can_manage_menus(server-set; the 00228 guard now blocks a person's own change),work_areas(checked against 9 ids) andwork_areas_asked_at.web/src/lib/menu-access.ts: the pure rule. The role's hidden sections, changed by the person's exceptions, then narrowed to their work areas. Action Center is always on. Nobody hides a section from an admin; only their own work areas narrow it. A section no work area names stays.web/src/lib/actions/menu-access.ts: server actionsgetMyMenu,getMenuAccessSettings,setRoleMenu,setMemberMenu(never on admins),setMenuManager(admins only, managers only),setMyWorkAreas.schema.sqlandtypes/supabase.tsregenerated.Next, stacked: part 2 filters the sidebar by this, part 3 adds Settings › Menu access, then the "What do you work on?" step. No read-only lock here: menu settings cost nothing; the read-only guard (#1612 chain) decides once it is on main.
Spec and mockup: Drive › Ansvisor Product Developments › Menu Access.
Related issue
None.
Type of change
How to test
supabase/migrations/00374_menu_access.sqlto a dev database.cd web && yarn test src/lib/menu-access.test.ts src/lib/actions/menu-access.test.ts.update profiles set can_manage_menus = true where id = auth.uid()→ "profile menu access is managed server-side";update profiles set work_areas = '{brand}'→ succeeds;'{sales}'→ check violation.can_manage_menus = trueandmenu_hidden = '{content}', then set theirorganization_idto null → all three are cleared; change only theirrole→can_manage_menusgoes false.insert into organization_menu_roles (organization_id, role) values (…, 'admin')→ check violation.Checklist
yarn format && yarn lint && yarn typecheck && yarn test && yarn buildpass inweb/(459 files, 4,516 tests)bash supabase/build-schema.shleavesschema.sqlunchangednpm run version:check(fails on main too: docker-compose images 0.2.0)🤖 Generated with Claude Code