The five permission actions
ThePermisosAccion interface in useAuth.ts defines the five actions that can be granted or denied per module:
| Action flag | Description |
|---|---|
bitConsulta | View / list records |
bitAgregar | Create new records |
bitEditar | Edit existing records |
bitEliminar | Delete records |
bitDetalle | Open the detail view of a record |
false in the database. A flag must be explicitly set to true for the action to be permitted.
Data model
Thepermisos_perfil table stores one row per profile-module combination:
| Column | Type | Description |
|---|---|---|
id | serial PK | Auto-increment primary key |
idModulo | integer FK | References modulo.id |
idPerfil | integer FK | References perfil.id |
bitAgregar | boolean | Create permission (default false) |
bitEditar | boolean | Edit permission (default false) |
bitConsulta | boolean | View permission (default false) |
bitEliminar | boolean | Delete permission (default false) |
bitDetalle | boolean | Detail permission (default false) |
Permission loading
After a successful login,cargarMisPermisos(idPerfil) fetches the current user’s permission set from the server:
app/composables/useAuth.ts
Record<string, PermisosAccion> where each key is the module name in uppercase (e.g. "USUARIO", "PERMISOS-PERFIL"). This object is stored in useState('misPermisos') and is available reactively across the entire app.
restaurarSesion() calls cargarMisPermisos again after a hard refresh if the in-memory state is empty, so permissions survive F5.
Checking permissions at runtime
tienePermiso() is the single function used everywhere in the UI to check whether the current user can perform an action:
app/composables/useAuth.ts
misPermisos (because no permission row exists for this profile-module pair), the function returns false — deny by default.
Usage in pages
UsetienePermiso with v-if to conditionally render UI elements based on the current user’s permissions:
app/pages/seguridad/usuario.vue
Route protection
Each security page checksbitConsulta in its onMounted hook. If the user lacks view permission, they are redirected to / before the page renders:
This check is client-side only. API routes have their own server-side validation and return HTTP 401/403 for unauthorised requests regardless of the UI state.
Permissions matrix
Administrators configure permissions through the visual permissions matrix UI. Selecting a profile loads all modules as rows, each with five toggleable checkboxes. Saving posts the entire matrix to/api/permisos/guardar-matriz in a single request.
If the profile being edited belongs to the currently logged-in user, cargarMisPermisos is called immediately after saving so the session reflects the changes without a logout.
See Permissions matrix for the full walkthrough.
Example permissions layout
| Module | bitConsulta | bitAgregar | bitEditar | bitEliminar | bitDetalle |
|---|---|---|---|---|---|
| USUARIO | ✓ | ✓ | ✓ | ✗ | ✓ |
| PERMISOS-PERFIL | ✓ | ✗ | ✓ | ✗ | ✗ |