Overview
MLM CMMS uses a Role-Based Access Control (RBAC) system to manage user permissions. Each user is assigned a single role, and each role has a collection of permissions that determine what actions the user can perform.Managing roles requires
rbac:manage_roles. Managing permissions requires rbac:manage_permissions.Accessing Roles & Permissions
Navigate to Administration → Settings and select the “Roles” or “Permissions” tab.RBAC Architecture
Roles
A role is a named collection of permissions. Users are assigned to roles, and inherit all permissions from that role. Role Properties:| Field | Type | Description |
|---|---|---|
id | Integer | Unique role identifier |
name | String | Role name (e.g., “Administrador”, “Técnico”) |
description | Text | Optional description of the role’s purpose |
created_at | Timestamp | Creation date |
Permissions
A permission is a specific action on a resource, represented by a permission code:users:read→ View usersusers:full_access→ Create and edit userswork_orders:create→ Create work ordersrbac:manage_roles→ Manage roles
| Field | Type | Description |
|---|---|---|
id | UUID | Unique permission identifier |
code | String | Permission code (e.g., users:read) |
resource | String | Resource name (e.g., users, work_orders) |
action | String | Action type (e.g., read, create, delete) |
label | String | Human-readable label |
description | Text | Optional description |
is_active | Boolean | Whether the permission is enabled |
Role-Permission Mapping
The relationship between roles and permissions is managed through therole_permissions table:
Permission Registry
The frontend maintains a permission registry insrc/rbac/permissionRegistry.ts. This registry defines all available permissions and is used to synchronize permissions to the database.
Resource Categories
RBAC
rbac:manage_permissionsrbac:manage_roles
Users
users:readusers:createusers:updateusers:full_accessusers:cancelusers:delete
Work Orders
work_orders:readwork_orders:read_ownwork_orders:creatework_orders:full_accesswork_orders:cancelwork_orders:delete
Work Requests
work_requests:readwork_requests:full_accesswork_requests:cancelwork_requests:delete
Assignees (Technicians)
assignees:readassignees:full_accessassignees:cancelassignees:delete
Locations
locations:readlocations:createlocations:updatelocations:deletelocations:disablelocations:full_access
Assets
assets:readassets:createassets:updateassets:deleteassets:disableassets:full_access
Inventory
inventory:readinventory:createinventory:updateinventory:deleteinventory:approveinventory:cancelinventory:workinventory:full_access
Special Incidents
special_incidents:readspecial_incidents:full_accessspecial_incidents:disablespecial_incidents:delete
Announcements
announcements:readannouncements:createannouncements:full_accessannouncements:disableannouncements:delete
Society
society:readsociety:createsociety:full_accesssociety:disablesociety:delete
Reports
reports:read
Common Permission Actions
| Action | Description |
|---|---|
read | View records |
read_own | View only records owned by the user |
create | Create new records |
update | Edit existing records |
delete | Delete records |
full_access | Create, read, update, and sometimes delete |
cancel | Activate/deactivate or cancel records |
disable | Deactivate records |
approve | Approve or publish records |
assign | Assign resources to other entities |
work | Perform work-related actions (e.g., reserve inventory) |
manage_roles | Manage roles (RBAC) |
manage_permissions | Manage permissions (RBAC) |
Role Management Workflows
Creating a Role
Fill in Role Details
- Name: Unique role name (e.g., “Supervisor de Mantenimiento”)
- Description (optional): Purpose or scope of the role
Assigning Permissions to a Role
Select Permissions
Permissions are grouped by resource. For each resource:
- Seleccionar todo: Check all permissions in the group
- Quitar todo: Uncheck all permissions in the group
- Individual checkboxes: Select specific permissions
Changes to role permissions take effect immediately. Users will inherit the updated permissions on their next API call.
Viewing Users in a Role
Deleting a Role
Permission Management
Synchronizing Permissions
The permission registry in the frontend must be synchronized with the database:Always synchronize permissions after updating the
permissionRegistry.ts file.Viewing Permission Details
The Permissions tab shows:- Code: Permission identifier (e.g.,
users:read) - Resource: Resource category
- Action: Action type
- Label: Human-readable name
- Description: Detailed explanation
- Status: Active/Inactive
Using Permissions in Code
Frontend Permission Checks
Component-Level Access Control
Hook-Based Permission Checks
Typed Permission Codes
Backend Permission Checks (RLS Policies)
PostgreSQL Row-Level Security policies enforce permissions at the database level:Database Functions
set_role_permissions
Assigns permissions to a role:
- Deletes all existing permissions for the role
- Inserts new permission assignments based on
p_perm_codes
sync_permissions_from_registry
Synchronizes permissions from the frontend registry:
- Inserts new permissions not in the database
- Updates labels/descriptions for existing permissions
- Marks permissions not in the registry as
is_active = false
current_user_has_permission
Helper function used in RLS policies:
true if the current authenticated user has the specified permission.
Best Practices
Principle of Least Privilege
Grant users only the permissions they need to perform their job functions.
Use Roles, Not Direct Assignments
Always assign users to roles rather than granting permissions individually.
Sync Permissions Regularly
After deploying code changes that add new permissions, sync the permission registry.
Document Custom Roles
Use the role description field to document the purpose and scope of custom roles.
Test Permission Changes
Verify that users can (and cannot) perform expected actions after role/permission changes.
Audit Permission Usage
Periodically review role assignments and remove unused permissions.
Troubleshooting
”No tienes permiso para…”
Cause: The user’s role does not include the required permission. Solution:- Verify the user’s role assignment
- Check if the role has the required permission
- If not, edit the role to add the permission
Permission Not Appearing in Role Editor
Cause: The permission is not synchronized from the registry. Solution:- Go to Administration → Settings → Permissions
- Click “Sincronizar permisos”
- Verify the permission appears in the list
Changes Not Taking Effect
Possible causes:- Frontend cache: Refresh the page or clear browser cache
- Permission context not refreshed: Log out and log back in
- RLS policy not updated: Redeploy database migrations