fix(dashboard): permission-gate the Recycle bin tabs and nav entry#1294
Merged
Conversation
The Trash page's five tabs were hard-coded with no permission check, so a user with rights to restore some resources but not others (e.g. catalog but not Files) could click a tab and hit a 403 error band. The dashboard already gates its sidebar nav this way; the Trash tabs just never got the treatment. Gate each tab on the permission its trash endpoint enforces (the resource's Restore, or Files.ViewTrash), hide tabs the user can't reach, and fall back to the first visible tab when the hard-coded default (Products) is gated away. Add anyPerm[] to NavSpec so the Trash sidebar entry hides when none are reachable, and show a no-access empty state on a direct visit. Server still enforces 403 as defence-in-depth. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
The Trash page (
/system/trash) renders five tabs — Products, Brands, Categories, Tickets, Files — that were hard-coded with no permission check. A user with rights to restore some resources but not others could click a tab and hit a403error band (e.g. a tenant member without Files access opening the Files tab).The dashboard already permission-gates its sidebar nav (
nav-data.ts→visibleSections); the Trash tabs just never got the same treatment. This closes that gap.How
src/lib/trash-permissions.ts(new) — single source of truth mapping each trash tab → the permission its endpoint enforces (Permissions.Catalog.{Products,Brands,Categories}.Restore,Permissions.Tickets.Restore,Permissions.Files.ViewTrash), plus a flatALL_TRASH_PERMISSIONS.src/components/layout/nav-data.ts— addedanyPerm?: readonly string[]toNavSpec(visible if the user holds any listed permission, AND-combined withperm); gated the Trash sidebar entry onALL_TRASH_PERMISSIONSso it hides when the user can reach no tab.src/pages/system/trash.tsx— filters tabs to those the user can access; when the hard-coded default (Products) is gated away, falls back to the first visible tab; shows a "no recycle bins available" empty state on a direct visit with zero trash permissions.The server keeps enforcing every permission with a
403— this is purely the UX layer.Tests
tests/system/trash.spec.ts— existing specs now grant the trash permissions inbeforeEach(the gate otherwise hides everything); two new specs cover tabs hiding + defaulting to the first visible tab, and the no-access empty state. All 5 green;tsc -b+eslintclean.Docs
Changelog entry added in the docs repo.
🤖 Generated with Claude Code