Overview
VIGIA implements a comprehensive role-based access control (RBAC) system with multi-level permissions. The system combines predefined roles with custom permissions to provide flexible access control across all modules.Role Hierarchy
VIGIA uses a flat role structure with predefined roles, each designed for specific user types in pharmacovigilance operations.System Roles
Admin
Admin
Full system access with administrative privileges
- All module permissions (view, create, edit, delete)
- User management and role assignment
- System configuration
- Tenant management
- Audit log access
admin is automatically selected as the primary role.QF (Qualified Person)
QF (Qualified Person)
Qualified Person for Pharmacovigilance
- Full ICSR management
- Case evaluation and causality assessment
- Report generation and submission
- Signal management
- Document review and approval
Responsable FV (PV Manager)
Responsable FV (PV Manager)
Pharmacovigilance Manager
- Case assignment and workflow management
- Team oversight
- Report review
- Quality metrics monitoring
- Training coordination
QA (Quality Assurance)
QA (Quality Assurance)
Quality Assurance Specialist
- Quality review and audits
- Process compliance monitoring
- Documentation review
- Audit trail access
- Training records management
Dirección Técnica
Dirección Técnica
Technical Director
- Strategic oversight
- High-level reporting
- Regulatory strategy
- System configuration approval
Legal
Legal
Legal Department
- Legal review of cases and reports
- Access to litigation-related cases
- Document access for legal purposes
- Report viewing (limited edit)
Soporte
Soporte
Support / Help Desk
- User support
- Basic configuration
- Training assistance
- Limited case viewing
Permission Structure
Module-Based Permissions
Permissions are organized by module and action type. The system supports granular permissions for each functional area.Permission Schema
Core Modules
| Module | Description | Key Actions |
|---|---|---|
icsr | Individual Case Safety Reports | view, create, edit, delete, submit |
reports | Regulatory reporting | view, generate, submit, export |
products | Product management | view, create, edit, delete |
surveillance | Signal detection | view, create, edit, evaluate |
documents | Document management | view, upload, approve, sign |
training | Training management | view, create, assign, track |
audit | Audit logs | view, export |
users | User management | view, create, edit, delete, assign_roles |
config | System configuration | view, edit |
Role Assignment
Multiple Roles
Users can be assigned multiple roles simultaneously. The system handles this through:- Primary Role Selection: If
adminis present, it’s selected as primary; otherwise, the first role in the list - Permission Aggregation: Users receive the union of all permissions from assigned roles
- Token Claims: Both primary role and full role list are included in JWT tokens
Database Schema
Roles are stored in two ways:- Array Column:
users.roles(PostgreSQL ARRAY type) for backward compatibility - Many-to-Many Relationship:
user_rolesjunction table linkingusersandrolestables
User-Role Relationship
Custom Permissions
In addition to role-based permissions, users can have custom permissions that override or extend role defaults.User-Specific Permissions
Stored inusers.custom_permissions (JSONB column):
Example Custom Permissions
Permission Resolution Order
- Custom Permissions: User-specific overrides take highest priority
- Role Permissions: Combined permissions from all assigned roles
- Default Deny: If no permission is explicitly granted, access is denied
Checking Permissions
The/auth/me endpoint returns the current user’s permissions:
GET /api/v1/auth/me Response
Permission Enforcement
Backend Enforcement
Permissions are enforced at the API level using dependency injection:Permission Dependencies
Frontend Integration
Clients should check permissions before displaying UI elements:Permission Checking
Role Management
Assigning Roles
Roles can be assigned through:- Direct Database Update: Modify
users.rolesarray oruser_rolestable - Admin API: User management endpoints (requires admin role)
- Tenant Configuration: Default roles for new users per tenant
Role Activation
Roles have anactive flag that can be toggled without deleting the role:
- Active Roles: Applied to user permissions
- Inactive Roles: Retained in database but not enforced
System Roles Protection
Roles withis_system = true cannot be deleted to ensure system integrity. These core roles include:
- admin
- qf
- responsable_fv
- qa
Multi-Tenant Permissions
Tenant Isolation
Permissions are scoped to tenants:- Users in different tenants are completely isolated
- Roles are tenant-specific
- Cross-tenant access requires separate authentication
Tenant Header Validation
TheX-Tenant header is validated against the JWT token’s tenant claim:
Tenant Validation
Best Practices
Security Guidelines
- Principle of Least Privilege: Assign minimum necessary roles
- Regular Audits: Review user roles and permissions periodically
- Role Segregation: Separate duties for compliance (e.g., QA separate from data entry)
- Permission Checks: Always validate permissions server-side, never trust client
Implementation Patterns
Backend Pattern
Frontend Pattern
Troubleshooting
Common Permission Issues
403 Error: No Roles Assigned
403 Error: No Roles Assigned
Error:
El usuario no tiene roles asignados. Contacte al administrador.Solution: Assign at least one role to the user:Permission Not Working After Role Assignment
Permission Not Working After Role Assignment
Cause: Token still contains old role informationSolution: Re-authenticate to get a new token with updated roles:
Admin User Can't Access Endpoint
Admin User Can't Access Endpoint
Cause: Endpoint may require specific permission check beyond admin roleSolution: Check endpoint implementation for custom permission requirements
Tenant Access Denied
Tenant Access Denied
Cause: Token tenant doesn’t match X-Tenant headerSolution: Ensure X-Tenant header matches the tenant used during login:
Related Endpoints
Get Current User
Retrieve permissions for authenticated user
Login
Authenticate and receive role information