Overview
The Sistema de Permisos Municipales implements role-based access control (RBAC) with three distinct user roles. Each role has specific permissions that determine what actions users can perform.User roles
Desarrollador
Highest privilegesFull system access including all administrative functions and user management.
Administrador
Administrative accessCan manage users and permits but cannot modify other administrators or developers.
Analista
Standard accessCan create, view, and manage permits but cannot access user management.
Role capabilities
Desarrollador (Developer)
Full system access with no restrictions:User management
User management
- Create all types of users (Desarrollador, Administrador, Analista)
- Edit all user accounts
- Delete any user account
- View all users
- Change any user’s role
Permit management
Permit management
- Create permits
- Edit permits
- Approve permits
- Cancel permits
- Delete permits
- Generate reports
- Export PDFs
System access
System access
- Access all routes and endpoints
- View system configuration
- Access administrative interfaces
- Full database access
Administrador (Administrator)
Administrative access with some restrictions:User management
User management
✅ Can:
- Create Administrador and Analista users
- Edit Administrador and Analista accounts (except Desarrollador accounts)
- Delete Administrador and Analista accounts
- View all users
- Create Desarrollador accounts
- Edit Desarrollador accounts
- Delete Desarrollador accounts
- Edit their own account
Permit management
Permit management
- Full permit management capabilities (same as Desarrollador)
- Create, edit, approve, cancel permits
- Delete permits
- Generate reports
System access
System access
- Access administrative interfaces
- View configuration (but cannot modify system settings)
Analista (Analyst)
Standard operational access:Permit management
Permit management
- Create permits
- Edit own permits (before approval)
- View all permits
- Search and filter permits
- Export approved permits as PDF
- Generate reports
Restrictions
Restrictions
❌ Cannot:
- Approve permits (requires Administrador/Desarrollador)
- Delete permits
- Access user management
- Access administrative settings
- Edit other users’ information
Role verification
The system uses middleware to enforce role-based access:verifySession middleware
Checks if a user is authenticated:verifyRoles middleware
Restricts access to specific roles:Usage example
Protected routes
User management routes
Required role: Administrador or DesarrolladorList all users in the system.
Required role: Administrador or DesarrolladorCreate a new user account.
Required role: Administrador or DesarrolladorEdit restrictions:
- Cannot edit own account
- Administrador cannot edit Desarrollador accounts
Required role: Administrador or DesarrolladorDelete restrictions apply (same as edit).
Permit deletion routes
Required role: Administrador or DesarrolladorDelete beverage permits with validation.
Required role: Administrador or DesarrolladorDelete advertising permits with validation.
Required role: Administrador or DesarrolladorDelete event permits with validation.
Access control logic
User account editing
The system prevents users from editing their own accounts or higher-privileged accounts:Route protection patterns
Pattern 1: Session onlyPermission matrix
| Action | Analista | Administrador | Desarrollador |
|---|---|---|---|
| Authentication | |||
| Login | ✅ | ✅ | ✅ |
| Change own password | ✅ | ✅ | ✅ |
| Logout | ✅ | ✅ | ✅ |
| Permit Operations | |||
| View permits | ✅ | ✅ | ✅ |
| Create permits | ✅ | ✅ | ✅ |
| Edit permits | ✅ | ✅ | ✅ |
| Search permits | ✅ | ✅ | ✅ |
| Approve permits | ❌ | ✅ | ✅ |
| Cancel permits | ❌ | ✅ | ✅ |
| Delete permits | ❌ | ✅ | ✅ |
| Generate PDFs | ✅ | ✅ | ✅ |
| Generate reports | ✅ | ✅ | ✅ |
| User Management | |||
| View users | ❌ | ✅ | ✅ |
| Create Analista | ❌ | ✅ | ✅ |
| Create Administrador | ❌ | ✅ | ✅ |
| Create Desarrollador | ❌ | ❌ | ✅ |
| Edit Analista | ❌ | ✅ | ✅ |
| Edit Administrador | ❌ | ✅ | ✅ |
| Edit Desarrollador | ❌ | ❌ | ✅ |
| Delete users | ❌ | ✅ | ✅ |
| Edit own account | ❌ | ❌ | ❌ |
Session storage
User role information is stored in the session:tipo_usuario field determines the user’s capabilities throughout the application.
Best practices
Principle of least privilege
Assign users the minimum role needed for their job functions. Most users should be Analistas.
Regular audits
Periodically review user roles and remove unnecessary elevated privileges.
Desarrollador protection
Limit the number of Desarrollador accounts. They have unrestricted system access.
Role changes
Document why users receive elevated privileges (Administrador or Desarrollador).
Security considerations
If you need to add a new role or modify permissions, you’ll need to:
- Update the database schema to include the new role
- Modify validation rules in
src/routes/usuarios.js - Update middleware role checks
- Update the UI to show/hide features based on role
Next steps
User management
Learn how to create and manage users
Authentication
Understand the authentication system