User Roles (System Role)
Overview
system_role is the role table that defines which modules each role has rights to, with the
detailed permissions stored in system_role_module.
On the API side this module is deliberately minimal: it exposes a single endpoint that feeds the
role dropdown on the user create and edit screens. Roles and permissions are not edited through
this API at all — they are master data configured in the database and overridden per organization
through the organization_module table.
One role value carries special meaning in code: roleId == 1 is SUPER_ADMIN, the value that
auth.SuperAdmin() checks for.
Business Flow
- The user management screen in cms-web needs the list of roles to render a dropdown.
- It calls
GET /api/system-role/find-all-objectbehindJwtLoginAuth, which is reachable before an OA has been selected. - The service queries
system_roleand returns an object/dropdown structure ordered the same way the original NestJS implementation did. - When a user is created with a
roleId, their baseline permissions come from that role's entries insystem_role_module. - When cms-web needs the effective permissions, it calls
GET /api/user/:id/permission, which merges the role baseline with the organization-level overrides.
Parity note: @CheckPolicies(read, ORGANIZATION) was commented out in the original TypeScript
source, so the Go route carries no policy annotation either.
Key Files & Functions
The code lives in internal/modules/systemrole/, consisting of controller.go, service.go,
repository.go, and dto.go.
| Method | Route | Handler | Guard |
|---|---|---|---|
| GET | /api/system-role/find-all-object | findAllObject(c, svc) | JwtLoginAuth on the public group |
RegisterRoutes uses only the public group; the _ = authed line confirms the authed group
is intentionally unused.
A sibling concept with no routes of its own is system_role_module, which has no separate Go
module (its TypeScript controller was empty too). Its data is read through the
User.SystemRoleModule relation inside the user module.
Connections to Other Services
- Permissions — requires a token that passes
JwtLoginAuth; nolineOaIdis needed and no policy check is applied. - Tables —
system_role,system_role_module - Related modules — the system module registry (the module master list), the permission resolution and module gate mechanism, and CMS user management, which consumes this dropdown.