Permission Management
The Permission module provides a full Role-Based Access Control (RBAC) layer for the Smart SCADA platform. It governs who can log in, which menus are visible, which routes are reachable, and which buttons/actions are available on each page.
Interface Screenshot


Captured from the live Smart Site system with the English UI. See the
zh-CNcounterpart for the Chinese-UI screenshot.
1. Core Concepts
The system uses a three-level role hierarchy with numeric weights to resolve conflicts:
| Role | Code | Weight | Description |
|---|---|---|---|
| Admin | admin |
2 | Full access, can manage users and roles |
| User | user |
1 | Standard operator, can edit operational data |
| Viewer | viewer |
0 | Read-only access |
The weight ordering is viewer (0) < user (1) < admin (2). When a menu or button requires a minimum role, the user's role weight must be greater than or equal to the required weight.
2. Functional Areas
2.1 User Management
- Create / edit / disable users
- Reset password, force password change on first login
- Assign roles and positions to each user
- Bind users to specific projects and device groups (data-level authorization)
Users are stored in the sys_users table and managed by UserService in @ss-node/ss-core.
2.2 Role Management
- Built-in roles (
admin,user,viewer) are markedisSystem: trueand cannot be deleted - Custom roles can be created with a granular permission code list (
permissions: string[]) - Each role carries a
menuIdsarray that controls which menu items are visible to its members - The
RoleServiceexposes CRUD and permission assignment endpoints
2.3 Position Management
- Positions represent organizational titles (e.g. "Operator", "Engineer")
- Managed via
PositionController/PositionService - Used for filtering and reporting, independent of role-based permissions
2.4 Menu Permission Configuration
Menu visibility is driven by two sources that must stay in sync:
- Frontend —
system-menu.config.tsdefines menu items withrolesand optionalpermissioncodes - Backend —
system-menu-config.service.tsexposes theDEFAULT_SYSTEM_MENUand persists items to thesys_menustable
The backend insertMissingMenus() routine automatically backfills any missing menu rows on startup, so newly added items appear without manual SQL.
2.5 Button-Level Permissions
For fine-grained control inside a page, use the usePermission composable:
const { can, hasRole, hasPermission } = usePermission()
// Check by permission code
if (can('device:delete')) { ... }
// Check by minimum role weight
if (hasRole('user')) { ... }
Button-level checks read from the user's permissions array and role weight.
2.6 Route Access Control
Route guards rely on two helpers:
buildMenuRoleMap(menuConfig)— builds a lookup of route path → required role/permissioncanAccessPath(path, userRole, userPermissions)— returnstrueif the current user may enter the route
The frontend router guard calls canAccessPath before each navigation; unreachable routes are also hidden from the sidebar.
3. Permission Codes
Permission codes follow a module:action convention, for example:
| Code | Scope |
|---|---|
device:read |
View devices |
device:write |
Create / update devices |
device:delete |
Delete devices |
alarm:ack |
Acknowledge alarms |
user:manage |
Manage users and roles |
Codes are centrally defined in permission-codes.ts and enforced by the PermissionsGuard on the backend.
4. Authentication Flow
- The user submits credentials to
POST /api/v1/auth/login AuthServicevalidates the password and returns a JWT access token + refresh token- The frontend stores the token and attaches it as
Authorization: Bearer <token> JwtAuthGuardverifies the token on every protected endpoint- Optional MFA (TOTP) can be enabled per user via the
MfaController
5. FAQ
Q: A new menu item is invisible after deployment.
A: Confirm all 9 registration points listed in AGENTS.md section 10.5 are updated, especially init-system-db.sql (for existing deployments) and the roles array in system-menu.config.ts. Then restart the backend so insertMissingMenus() runs.
Q: A user with the user role cannot see a button that requires device:write.
A: Either add device:write to the role's permissions list, or raise the user's role to admin. Button visibility is driven by the usePermission().can() check.
Q: How is the role weight used?
A: Weights are compared numerically (viewer 0 < user 1 < admin 2). hasRole('user') returns true when the current user's weight is >= 1.
Q: Can I delete the built-in roles?
A: No. Roles with isSystem: true are protected and the delete endpoint returns 409 Conflict.
6. Related Links
- System Menu Configuration
- Permission Test Report
- user.entity.ts
- role.entity.ts
- API Architecture