0004: RBAC policy centralised in the service layer¶
Status: Accepted
Context¶
Authorization rules were spread across endpoint handlers. That allowed inconsistencies, for example an ADMIN could create SUPER accounts through POST /users/.
Decision¶
app/services/users.py owns the policy (can_view, can_manage) and every user-management command. Endpoints call the service; route-level role dependencies (AllowSuper, AllowSuperOrAdmin, …) act only as a first coarse filter. The full role-by-role matrix is covered by parametrised tests.
Consequences¶
Policy changes happen in one module and one test matrix. Other domains (for example ToDos) keep their visibility rules in a single query helper (app/crud/todo.py::_visible_todos).