Overview
The Permissions API enables fine-grained access control by managing permissions and their assignments to roles. The system includes 12 predefined permission types covering all major platform features.Permission Types
The following permissions are available in the system (defined in types.ts:11):admin_completo
Full administrative access to all platform features
asignar_roles
Ability to assign and modify user roles
comentar
Permission to create comments on posts
crear_categoria
Create new content categories
crear_post
Create new blog posts and drafts
editar_categoria
Edit existing category information
editar_post_cualquiera
Edit any post in the system (not just own posts)
editar_post_propio
Edit only posts authored by the user
eliminar_categoria
Delete categories from the system
publicar_post
Publish posts to make them publicly visible
reaccionar
React to posts and comments (likes, etc.)
rechazar_post
Reject submitted posts during moderation
Get All Permissions
Function Reference:
getAllPermisos() - rbacService.ts:117Request
Response
Returns an array of permission objects.Array of permission objects
Example
Create Permission
Function Reference:
createPermiso(data) - rbacService.ts:144Request
Parameters
Name of the permission. Use snake_case convention (e.g., “export_analytics”).
Optional description explaining what the permission grants access to.
Response
Returns the created permission object ornull if creation fails.
The newly created permission object with all fields populated
Example
Delete Permission
Function Reference:
deletePermiso(id) - rbacService.ts:172Request
Parameters
The unique identifier of the permission to delete
Response
true if the permission was successfully deleted, false otherwiseExample
Delete Multiple Permissions
Function Reference:
deletePermisos(ids) - rbacService.ts:187Request
Parameters
Array of permission IDs to delete
Response
true if all permissions were deleted successfully, false otherwiseExample
Get Permissions by Role
Function Reference:
getPermisosByRole() - rbacService.ts:206Request
Response
Returns an object where keys are role IDs and values contain role information with their permissions.Object mapping role IDs to role data with permissions
Example
Assign Permission to Role
Function Reference:
assignPermisoToRole(rolId, permisoId) - rbacService.ts:223Request
Parameters
The ID of the role to assign the permission to
The ID of the permission to assign
Response
true if the permission was successfully assigned, false otherwiseExample
Permission assignments take effect immediately for all users with the specified role.
Revoke Permission from Role
Function Reference:
revokePermisoFromRole(roleId, permisoId) - rbacService.ts:244Request
Parameters
The ID of the role to revoke the permission from
The ID of the permission to revoke
Response
true if the permission was successfully revoked, false otherwiseExample
Revoke Multiple Permissions from Role
Function Reference:
revokeManyPermisosFromRole(rolId, permisoIds) - rbacService.ts:264Request
Parameters
The ID of the role to revoke permissions from
Array of permission IDs to revoke from the role
Response
true if all permissions were successfully revoked, false otherwiseExample
Helper Functions
Check Role Permission
Function Reference:
roleHasPermiso(rolId, permisoNombre) - rbacService.ts:287Parameters
The role ID to check
The permission name to look for (e.g., “crear_post”)
Response
true if the role has the specified permission, false otherwiseExample
Get Role Permissions
Function Reference:
getPermisosDeRol(rolId) - rbacService.ts:308Parameters
The role ID to fetch permissions for
Response
Array of permission objects assigned to the role
Example
Type Definitions
Permiso Interface
Permission Type
Thetypes.ts file defines all available permission types:
Best Practices
Permission Granularity
Permission Granularity
- Keep permissions specific and focused on single capabilities
- Use separate permissions for different levels of access (e.g.,
editar_post_propiovseditar_post_cualquiera) - Follow the principle of least privilege when assigning permissions
- Document custom permissions thoroughly
Role-Permission Mapping
Role-Permission Mapping
- Regularly audit role-permission assignments
- Use
getPermisosByRole()to review the complete permission landscape - Test permission changes in a staging environment first
- Maintain documentation of which roles should have which permissions
Security Considerations
Security Considerations
- Never grant
admin_completopermission to roles that don’t require it - Monitor permission assignments for compliance with security policies
- Implement proper authentication checks before permission operations
- Log all permission changes for audit trails
Error Handling
Error Handling
- Always verify the role and permission IDs exist before assignment
- Check return values from assignment/revocation operations
- Implement proper error messages for failed operations
- Handle edge cases like duplicate assignments gracefully
Permission Matrix Example
Here’s a typical permission matrix for the predefined roles:| Permission | Creador | Administrador | Editor | Escritor | Autor | Comentador |
|---|---|---|---|---|---|---|
| admin_completo | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| asignar_roles | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| crear_post | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
| editar_post_cualquiera | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| editar_post_propio | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
| publicar_post | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ |
| crear_categoria | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| eliminar_categoria | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| comentar | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| reaccionar | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Related Resources
Roles API
Manage roles and role assignments
User Management
Manage users and their role assignments