Skip to content

RBAC ​

Full user–role–permission RBAC provided by the identity + system services, across three granularities: API, button and data.

ObjectNotes
UsersDepartment, multiple positions, enable/disable, Excel import/export
RolesPermission set + data scope; super_admin bypasses checks
PermissionsCode convention {domain}:{resource}:{action}
MenusSeeded tree filtered by role; drives the sidebar
DepartmentsTree with a leader (used by the workflow "department leader" rule)
PositionsMany-to-many with users

Three granularities ​

  1. API level — route middleware checks the user's permission set, cached in a Redis Set (user:permissions:<userID>, 1 h TTL, DB fallback on miss). super_admin and the * / *:*:* wildcard codes bypass. Assigning role permissions invalidates the cache immediately.
  2. Button level — the usePermission() hook:
tsx
const { hasPerm } = usePermission()
{hasPerm('system:user:create') && <Button onClick={openCreate}>New user</Button>}
  1. Data level — the role's data_scope is applied by a GORM plugin before list queries (users, files, login/operation logs): all · department · department_tree · self (default) · custom (explicit department list) · none.

Walkthrough: onboard a teammate ​

Create a department (set its leader if you use workflow's dept-leader rule) → create a role (tick permission points, pick a data scope) → create the user (department, position, role) → log in as them to verify menus, buttons and list data all narrow accordingly. Bulk onboarding: Excel import (GET /users/import-template → POST /users/import, ≤5 MB, per-row error reporting; export via GET /users/export respects data scope).

Endpoint quick reference ​

Six resource groups share the same CRUD shape and {resource}:{action} permission codes:

MethodPathPermission
GET/POST/api/v1/userssystem:user:list / system:user:create
PUT/api/v1/users/:id, /users/:id/status, POST /users/:id/rolessystem:user:update
GET/POST/api/v1/roles, POST /roles/:id/permissionssystem:role:* (package-capped, see Multi-tenancy)
GET/api/v1/permissions/tree, /menus/tree, /departments/tree, /postssystem:{resource}:list

Full listing: OpenAPI contract (make api-contract).

Advice for extenders ​

Seed new permission codes via SQL migration and grant them to super_admin; never hard-code role names in business logic — check permission codes only.

MIT Licensed · Go microservices & business platform