Overview
The Roles API provides endpoints to manage role catalog entries in the furniture store system. Roles are used for permission management and user profile assignment. Base URL:/roles
Endpoints
List Roles
Retrieve all active roles from the catalog.Response
Returns an HTML page with the list of roles. For API consumption, roles are represented as:Unique identifier for the role
Name of the role (max 50 characters)
Whether the role is active
ISO 8601 timestamp of creation
ISO 8601 timestamp of last update
Example Request
Example Response
Create Role
Create a new role entry in the catalog.Request Parameters
Name of the roleValidation:
- Required field
- Maximum 50 characters
- Must be unique
Response
Success:- Flash message: “Rol creado exitosamente”
- Redirects to
/roles/create
Returned when a role with the same name already exists
Example Request
Success Response
Error Response
Edit Role
Update an existing role in the catalog.Path Parameters
Unique identifier of the role to edit
Request Parameters
Updated name for the roleValidation:
- Required field
- Maximum 50 characters
- Must be unique
Response
Success:- Flash message: “Rol actualizado exitosamente”
- Redirects to
/roles/
Returned when the role ID does not existRedirects to
/roles/ with error messageReturned when the updated name conflicts with an existing role
Returned when validation rules are violated
Example Request
Delete Role
Perform logical deletion of a role (marks as inactive).Path Parameters
Unique identifier of the role to delete
Response
Success:- Flash message: “Rol eliminado exitosamente”
- Redirects to
/roles/
Returned when the role ID does not existRedirects to
/roles/ with error messageExample Request
Data Model
Role Object
Validation Rules
- name: Required, unique, max 50 characters
- active: Boolean, defaults to
true - All endpoints require CSRF token for POST requests
Error Messages
| Error | Message |
|---|---|
| Missing name | ”El nombre del rol es requerido” |
| Name too long | ”El nombre no puede exceder 50 caracteres” |
| Duplicate name | ”Ya existe un rol con ese nombre” |
| Not found | Role-specific error message from service |
Implementation Details
- Source:
app/catalogs/roles/routes.py:13-104 - Form:
app/catalogs/roles/forms.py:10-19 - Model:
app/models/role.py:4-58 - Pattern: Post-Redirect-Get (PRG) for all form submissions
- Deletion: Logical (soft delete) - sets
active=falseanddeleted_attimestamp
Common Role Examples
Typical Role Hierarchy
Security Considerations
Best Practices
- Use descriptive, self-explanatory role names (e.g., “Sales Manager” instead of “SM”)
- Maintain a clear role hierarchy with minimal overlap
- Avoid deleting roles that are actively assigned to users
- Consider implementing role permission mapping for fine-grained access control
- Regular audit of active roles and their assignments
Related Endpoints
Roles are typically used in conjunction with:- User management endpoints
- Permission assignment endpoints
- Access control middleware