changed role permission
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled

This commit is contained in:
guwandyk committed 2026-09-26 16:34:28 +05:00
1 parent f0ecf23879
commit 323e131216
74 files changed
+2915 -4713

No files matched your search

+9
View File
@@ -180,6 +180,15 @@ Seed data (`db/seed.sql`) loads a consolidated, idempotent set of test accounts/
make seed
```
## Roles & permissions (RBAC)
- **Permission = module.** One code per module (`cards`, `loans`, `users`, `roles`, `branches`, `provinces`, `currencies`, `payment-settings`, `backups`, `activity-logs`, `dashboard`), defined in `internal/identity/rbac/perm`. Holding it grants read and write in that module. The catalog is synced to the `permissions` table on startup; the API only lets roles pick from it.
- **Role = permissions + scope.** `scope` decides whose records: `own` (clients — only their own), `branch` (the user's `branch_user` branches, possibly several), `all` (every branch). E.g. a head of loans is `scope=all` + `loans`. `is_super` roles hold every permission; `is_system` roles (`superadmin`, `user`) cannot be deleted or re-scoped.
- **One role per user:** `users.role_id`.
- **Every `/api/admin` route declares its policy** with `rbac.Group(router, path, policy)` — `Require(perm.X)`, `RequireStaff`, `Catalog`, `StaffRead`, `Staff`, `Authenticated`, `Public`. Startup fails if a route has none, and an undeclared route is denied at runtime.
- **No escalation:** a caller can only create/assign roles within their own scope and permissions, cannot touch superadmin unless superadmin, cannot change their own role, and cannot remove the last superadmin.
- Principals are cached per user; DB triggers bump `rbac_version` on role/permission/branch changes, which clears the cache within ~2s.
## Development
### Run tests