UZDI implements a Role-Based Access Control (RBAC) system that enforces authorization at two independent layers: the Vue 3 frontend router and the NestJS backend API. Every authenticated user carries aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Zapiony/PUCE_UZDI_2026/llms.txt
Use this file to discover all available pages before exploring further.
tppr_id integer (a foreign key to the seguridad.tipo_persona catalogue) that maps to a named role. The frontend router uses the numeric tppr_id to evaluate minimum-access thresholds per route, while the backend uses the string-valued Rol enum attached to the request user object and evaluated by RolesGuard before any controller handler runs.
Roles Overview
Theseguridad.tipo_persona table seeds five person types on first run. Four of them are consumed by the RBAC system; the fifth (Otro) is a catch-all for non-system users.
| Role (enum key) | tppr_id | Spanish display name | Access level |
|---|---|---|---|
TRABAJADOR_SOCIAL | 1 | Trabajador Social | Técnico — read-only on most modules |
PSICOLOGO | 1 | Psicólogo | Técnico — read-only on most modules |
EDUCADOR | 1 | Educador | Técnico — read-only on most modules |
JURIDICO | 1 | Jurídico | Técnico — read-only on most modules |
COORDINADOR | 2 | Coordinador | Can access Reportes in addition to Técnico routes |
ADMINISTRADOR | 3 | Administrador | Full write access; can manage users and parameters |
SUPERADMINISTRADOR | 3 | Superadministrador | Same as Administrador, reserved for platform-level operations |
The
tppr_id values seeded by the DDL are 1 = Técnico, 2 = Coordinador, 3 = Administrativo, 4 = Director, 5 = Otro. The frontend router guard uses tppr_id thresholds of 2 and 3 to gate protected routes. All four technical roles (Trabajador Social, Psicólogo, Educador, Jurídico) map to tppr_id = 1.Frontend Route Guards
The Vue Router applies abeforeEach navigation guard that reads uzdi_user from localStorage and compares the user’s tppr_id against a static ROUTE_MIN_ROL map. Any navigation to a protected route where the user’s tppr_id is below the threshold is silently redirected to /app/dashboard.
Protected routes
| Route | Required tppr_id | Minimum role |
|---|---|---|
/app/reportes | ≥ 2 | Coordinador |
/app/usuarios | ≥ 3 | Administrador |
/app/parametros | ≥ 3 | Administrador |
/app/* routes (dashboard, adolescentes, expedientes, medidas, perfil) are accessible to every authenticated user regardless of role.
Router guard code
/app/** without a valid uzdi_token in localStorage is sent to /login, and a logged-in user visiting /login is redirected back to /app/dashboard.
Backend Endpoint Guards
On the API side, RBAC is enforced through a@Roles() decorator and a RolesGuard that inspects request.user.rol on every incoming request.
@Roles() decorator
Rol enum values as metadata on the route handler or controller class using NestJS’s SetMetadata.
RolesGuard
RolesGuard uses Reflector.getAllAndOverride so that a method-level @Roles() annotation takes precedence over a class-level one. If no @Roles() annotation exists on either the handler or the class, the guard returns true (public endpoint).
Example: AdolescenteController
The adolescente controller applies @UseGuards(RolesGuard) at the class level and restricts each HTTP verb separately:
ADMINISTRADOR / SUPERADMINISTRADOR — is the standard convention across the UZDI domain modules.
Rol Enum Reference
The enum lives in UZDI_BACK/src/common/enums/rol.enum.ts and defines the exact string values that must appear in request.user.rol for guard evaluation to succeed.
| Enum key | String value |
|---|---|
Rol.ADMINISTRADOR | 'Administrador' |
Rol.PSICOLOGO | 'Psicólogo' |
Rol.TRABAJADOR_SOCIAL | 'Trabajador Social' |
Rol.EDUCADOR | 'Educador' |
Rol.JURIDICO | 'Jurídico' |
Rol.SUPERADMINISTRADOR | 'Superadministrador' |
The string values use Spanish characters (e.g.,
'Psicólogo', 'Jurídico'). Any JWT payload or mock user object must use these exact strings — including accents — for RolesGuard comparisons to pass.Development: MockAuthMiddleware
In local development, the NestJS application wiresMockAuthMiddleware globally across all routes via AppModule. This middleware inspects the incoming Authorization header: when a Bearer token is present, it injects a synthetic request.user object so that protected endpoints can be exercised without a real authentication workflow.