Every admin panel I've worked on handled permissions the same way. To add one protected page, you touch four places:
Define a permission constant, like REPORTS_VIEW .
Seed it into the database.
Attach a check to the route.
Add a checkbox for it in the role editor.
Forget step 3 and the page is open to every signed-in user. Forget step 2 or 4 and the permission exists but no administrator can grant it. Nothing fails at compile time, and usually nothing fails in tests either.
While building Rustmin , an open-source admin panel starter kit in Rust, I wanted adding a protected route to be one line . This post shows how it works: permissions are derived from the route table at startup, enforced by one middleware, and tracked over time so new and removed routes show up for review.
The idea: the router already knows
The router has a list of every route: its method, its URI, its middleware and its handler.β¦