PATCH /usuarios//rol
Updates a user’s role. This is an admin-only operation for managing user permissions.Authentication
Only users with theadmin role can assign roles to other users.
Path Parameters
The MongoDB ObjectId of the user whose role will be updated
Request Body
The new role to assign. Must be one of:
visitante, editor, or adminRequest
cURL
Python
JavaScript
Response
Success message confirming the role update
The ID of the user whose role was updated
The newly assigned role
Example Response
Error Responses
| Status Code | Description |
|---|---|
| 400 | Bad Request - Missing rol field or invalid role value |
| 401 | Unauthorized - Invalid or missing JWT token |
| 403 | Forbidden - User is not an admin |
| 404 | Not Found - User with given ID does not exist |
| 500 | Internal Server Error - Database or processing error |
Valid Role Values
visitante
Default role for new users. Read-only access to public content.
editor
Can create and edit routes, toggle destination status.
admin
Full access to all platform features and user management.
Implementation Reference
This endpoint is implemented insrc/infrastructure/api/routers/usuario_router.py:202-223:
AsignarRol use case validates the role value and updates the user document in MongoDB.
Use Cases
- Promote user to editor: Grant content management permissions to trusted users
- Promote user to admin: Give full platform access to administrators
- Demote user: Revoke elevated permissions (e.g., from editor to visitante)
- User moderation: Adjust permissions based on user behavior
Role changes take effect immediately. The user will need to log in again to receive a JWT token with the updated role.
Related Documentation
- User Roles Overview - Understand role permissions
- Admin Role - Admin capabilities
- Editor Role - Editor capabilities
- List Users - View all users to manage roles