Overview
The Procurement Calendar application implements a role-based access control (RBAC) system to manage user permissions. Roles determine what actions users can perform, which pages they can access, and what data they can view or modify.Roles are stored in the
profiles table and enforced through Supabase Row-Level Security (RLS) policies at the database level.Available Roles
The application defines six user roles as a PostgreSQL enum:Despite the enum definition including six roles, the current implementation primarily uses admin, coordinadora, and consulta. The roles laboratorio, cedis, and pendiente are reserved for future feature expansion.
Role Definitions
Admin
Administrator
Full system access with all permissions enabled.
- ✅ Create requisitions
- ✅ Edit all requisitions
- ✅ Delete requisitions
- ✅ View all requisitions
- ✅ Create/update/delete catalog entries
- ✅ Toggle catalog active status
- ✅ View audit history
- ✅ Manage user profiles
- ✅ Access all dashboard pages
- ✅ Set confirmed delivery dates
- System administrators
- IT staff
- Senior procurement managers
- Users who need full control
Coordinadora
Coordinator
Procurement coordinator with operational permissions.
- ✅ Create requisitions
- ✅ Edit requisitions
- ❌ Delete requisitions (admin only)
- ✅ View all requisitions
- ✅ Create/update catalog entries
- ✅ Toggle catalog active status
- ❌ Delete catalog entries (admin only)
- ✅ View audit history
- ✅ Access requisitions and calendar pages
- ✅ Set confirmed delivery dates
- Procurement coordinators
- Supply chain managers
- Users who manage day-to-day operations
Consulta
Consultation
Read-only access for viewing and reporting.
- ❌ Create requisitions
- ❌ Edit requisitions
- ❌ Delete requisitions
- ✅ View all requisitions
- ❌ Modify catalogs
- ✅ View catalogs
- ✅ View audit history (limited)
- ✅ Access calendar and table views
- ❌ Cannot set delivery dates
- Warehouse staff
- Finance/accounting teams
- Reporting and analytics users
- External auditors
- Read-only stakeholders
Pendiente
Pending Approval
Newly registered users awaiting role assignment.
- ❌ All operations blocked
- ✅ Can see “pending approval” page
- ⏳ Waiting for admin to assign proper role
- New user sign-ups
- Users waiting for access approval
- Temporary lockout state
- User signs up via
/loginwith email/password - Profile created with
rol: 'pendiente'by default - User redirected to
/dashboard/pendientepage - Admin assigns appropriate role
- User gains access based on new role
By default, new users get the consulta role if not specified during signup. The pendiente role must be explicitly set.
Laboratorio & CEDIS
Reserved Roles
Future roles for specialized workflows (not currently implemented).
- laboratorio: Quality control staff who verify received materials
- cedis: Distribution center staff who manage inventory
Permission Matrix
| Action | Admin | Coordinadora | Consulta | Pendiente |
|---|---|---|---|---|
| View requisitions | ✅ | ✅ | ✅ | ❌ |
| Create requisitions | ✅ | ✅ | ❌ | ❌ |
| Edit requisitions | ✅ | ✅ | ❌ | ❌ |
| Delete requisitions | ✅ | ❌ | ❌ | ❌ |
| View catalogs | ✅ | ✅ | ✅ | ❌ |
| Create catalog entries | ✅ | ✅ | ❌ | ❌ |
| Update catalog entries | ✅ | ✅ | ❌ | ❌ |
| Delete catalog entries | ✅ | ❌ | ❌ | ❌ |
| Set confirmed dates | ✅ | ✅ | ❌ | ❌ |
| View audit history | ✅ | ✅ | Partial | ❌ |
| Manage users | ✅ | ❌ | ❌ | ❌ |
Profile Structure
User profiles extend Supabase authentication:Row-Level Security Policies
Permissions are enforced at the database level through RLS policies:Profiles Table
Requisiciones Table
Catalog Tables
The
get_my_role() helper function retrieves the current user’s role from the profiles table:Checking Permissions in Code
The application provides hooks and utilities for permission checks:useAuthRole Hook
Server-Side Permission Check
Assigning Roles
Only admins can assign or change user roles:Workflow by Role
Admin Workflow
- Full access to all features
- Manage requisitions (create, edit, delete)
- Manage catalogs (create, edit, delete)
- Assign roles to users
- View complete audit trails
- Configure system settings
Coordinadora Workflow
- Create and manage requisitions
- Set confirmed delivery dates
- Update requisition status as deliveries progress
- Add suppliers and products to catalogs
- Filter and view calendar/table views
- Cannot delete data or manage users
UI Permission Controls
The UI automatically adapts based on user role:Hide/Show Elements
Conditional Rendering
Security Best Practices
Never Trust the Client
Always validate permissions on the server side. UI controls are for UX only, not security.
Use RLS Policies
Enforce permissions at the database level with Row-Level Security policies.
Principle of Least Privilege
Grant users only the minimum permissions needed for their role.
Audit Role Changes
Log when user roles are modified, including who made the change and when.
Common Permission Errors
No tienes permisos para crear requisiciones
No tienes permisos para crear requisiciones
Cause: User has
consulta or pendiente roleSolution: Admin must update user’s role to admin or coordinadoraSolo administradores pueden eliminar
Solo administradores pueden eliminar
Cause: User has
coordinadora role trying to deleteSolution: Contact an admin to perform the deletion, or request admin role if appropriateNo se puede eliminar porque está siendo utilizado
No se puede eliminar porque está siendo utilizado
Cause: Trying to delete a catalog entry referenced by requisitionsSolution:
- Use
toggleCatalogStatusto deactivate instead - Or delete all related requisitions first (not recommended)
Future Enhancements
Laboratorio Role (Future)
Planned permissions:- View requisitions assigned to laboratory
- Record quality control results
- Approve/reject received materials
- Update requisition status to “approved” or “rejected”
CEDIS Role (Future)
Planned permissions:- View inventory levels
- Record material receipts
- Update delivery status
- Manage warehouse locations
Testing Permissions
To test different permission levels:- Create test users with different roles
- Sign in as each user
- Verify UI elements appear/disappear correctly
- Attempt restricted actions and verify error messages
- Check database directly to confirm RLS policies block unauthorized access
