feat: hide write UI from read-only users (no WRITE_ALL permission) #17
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Users without
WRITE_ALLpermission (read-only users) currently see all edit buttons, "New Document" links, "New Person" links, edit forms, and merge sections. The backend correctly blocks the actual mutations via@RequirePermission(Permission.WRITE_ALL), but the UI gives no indication that those actions are unavailable — users click a button, get a 403, and are confused.Reference pattern: The admin nav link is already conditionally hidden using
isAdminderived frompage.data.user.groups. The same approach should be applied to all write UI.Approach
1. Expose
canWritecentrally in the layout loadAdd
canWriteto+layout.server.tsso it is available aspage.data.canWriteon every page — no per-page boilerplate needed.2. Hide write UI in components
Use
{#if page.data.canWrite}to wrap write-only elements (same pattern as the admin nav link):src/routes/+page.sveltesrc/routes/documents/[id]/+page.sveltesrc/routes/persons/+page.sveltesrc/routes/persons/[id]/+page.svelte3. Server-side route guards on write-only routes
Add a
WRITE_ALLcheck in theloadfunction of each write-only route — same pattern as the admin page. Throws 403 if a read-only user navigates there directly via the URL bar.src/routes/documents/new/+page.server.tssrc/routes/documents/[id]/edit/+page.server.tssrc/routes/persons/new/+page.server.tsAcceptance Criteria
/documents/new,/documents/:id/edit,/persons/newreturns 403 for read-only usersWRITE_ALLsee and can use all write UI as beforeADMINusers are unaffected (admin implies separate permissions, not write access per se — check existing group setup)