User Roles & Permissions
HRS implements a role-based access control system to manage what different users can do within the application. This page explains the user model, roles, and permission structure.User Model
Fromsrc/services/authService.ts:5, the system defines users as:
The system separates
User (full model) from SafeUser (without password) to ensure sensitive data is never exposed in the client.User Attributes
Core Attributes
Unique identifier for the user
Unique username for login authentication
User’s email address (must be in whitelist for registration)
Hashed password (never stored in browser, only transmitted for authentication)
User’s role designation (determines permissions)
Whether the user account is active
true: User can log in and access systemfalse: User account is disabled
ISO date string of when the account was created
URL to user’s profile avatar image
Authentication Flow
Registration Process
Fromsrc/services/authService.ts:127:
User Submits Registration
User provides:
- Username
- Email (must be in whitelist)
- Password (must meet strength requirements)
Server Validation
Backend validates:
- Email is in approved whitelist
- Username is unique
- Password meets complexity requirements
- All required fields are present
Account Creation
System creates account with:
activo: true(active by default)fechaCreacion: current daterol: default role(if applicable)
Login Process
Fromsrc/services/authService.ts:104:
Server Verification
Backend verifies:
- User exists
- Password is correct
- Account is active (
activo: true)
Session Management
Session Storage Strategy: Fromsrc/services/authService.ts:62:
Session Storage
Stored Data:
authCredentials: Base64 encoded credentialsuser: User object without password
- Persists during browser tab session
- Cleared when tab/window closes
- Cleared on logout
- Cleared on 401 responses
Auto-Logout
Idle Timeout:
- 15 minutes of inactivity
- Tracks mouse, keyboard, touch events
- Warning before logout
- Automatic credential clearing
src/components/auth/IdleHandler.tsxProtected Routes
Fromsrc/App.tsx:42:
ProtectedRoute component:
Route Protection: Every route except
/login and /register requires authentication. Unauthenticated users are automatically redirected to login.User Roles (Conceptual)
While the system has arol field, the current implementation appears to grant all authenticated users full access to all features. Here’s how roles could be structured:
Administrator Role
Full System Access
Full System Access
Permissions:
- Create, read, update, delete all students
- Create, read, update, delete all instructors
- Create, read, update, delete all horses
- Create, read, update, delete all classes
- Access all calendar views
- Generate all reports
- Manage financial data
- Access system settings
- Manage user accounts
Use Cases
Use Cases
- School owner
- Office manager
- System administrator
- Anyone needing full control
Instructor Role (Potential)
Instructor Permissions
Instructor Permissions
Could Have:
- View all students
- View all horses
- View all instructors
- Create/update/view their own classes
- View calendar (all or filtered to their classes)
- Update class states (PROGRAMADA → INICIADA → COMPLETADA)
- Mark student absences (ACA, ASA)
- View reports related to their classes
- Modify other instructors’ classes
- Delete classes
- Access financial data
- Manage student enrollments
- Manage user accounts
Use Cases
Use Cases
- Riding instructors
- Part-time coaches
- Specialized trainers
Receptionist Role (Potential)
Receptionist Permissions
Receptionist Permissions
Could Have:
- Create/read/update students
- View instructors and horses
- Create/schedule classes
- View calendar (all views)
- Contact students (WhatsApp, Email)
- Generate student and class reports
- Delete students or classes
- Manage instructors
- Manage horses
- Access financial reports
- Modify completed classes
Use Cases
Use Cases
- Front desk staff
- Administrative assistants
- Customer service representatives
Read-Only Role (Potential)
Viewer Permissions
Viewer Permissions
Could Have:
- View students
- View instructors
- View horses
- View classes and calendar
- View reports
- Create, update, or delete anything
- Contact students
- Modify class states
- Access financial data
Use Cases
Use Cases
- Auditors
- Parents/guardians
- Observers
- Reporting analysts
Permission Matrix
Here’s a conceptual permission matrix showing what each role could access:| Feature | Admin | Instructor | Receptionist | Read-Only |
|---|---|---|---|---|
| Students | ||||
| View Students | ✅ | ✅ | ✅ | ✅ |
| Create Students | ✅ | ❌ | ✅ | ❌ |
| Edit Students | ✅ | ❌ | ✅ | ❌ |
| Delete Students | ✅ | ❌ | ❌ | ❌ |
| Instructors | ||||
| View Instructors | ✅ | ✅ | ✅ | ✅ |
| Manage Instructors | ✅ | ❌ | ❌ | ❌ |
| Horses | ||||
| View Horses | ✅ | ✅ | ✅ | ✅ |
| Manage Horses | ✅ | ❌ | ❌ | ❌ |
| Classes | ||||
| View All Classes | ✅ | ✅ | ✅ | ✅ |
| Create Classes | ✅ | 🟡 Own | ✅ | ❌ |
| Edit Classes | ✅ | 🟡 Own | ✅ | ❌ |
| Delete Classes | ✅ | ❌ | ❌ | ❌ |
| Change Class State | ✅ | 🟡 Own | ✅ | ❌ |
| Calendar | ||||
| View Calendar | ✅ | ✅ | ✅ | ✅ |
| Copy Classes | ✅ | ❌ | ✅ | ❌ |
| Cancel Day | ✅ | ❌ | 🟡 Maybe | ❌ |
| Export Excel | ✅ | ✅ | ✅ | ❌ |
| Reports | ||||
| View Reports | ✅ | 🟡 Own | ✅ | ✅ |
| Export Reports | ✅ | 🟡 Own | ✅ | ❌ |
| Finances | ||||
| View Finances | ✅ | ❌ | ❌ | ❌ |
| Manage Finances | ✅ | ❌ | ❌ | ❌ |
| System | ||||
| Manage Users | ✅ | ❌ | ❌ | ❌ |
| System Settings | ✅ | ❌ | ❌ | ❌ |
- ✅ Full access
- 🟡 Limited access (specified in cell)
- ❌ No access
User Profile Management
Fromsrc/services/authService.ts:184:
Updatable Fields
- Username
- Avatar (via
avatarUrl)
- User role (
rol) - Active status (
activo)
Current User Access
Getting Current User
Checking Authentication
Security Best Practices
Password Security
From the authentication flow:- Password never stored in browser
- Only transmitted during login
- Server handles hashing and verification
- Client receives user data without password
Logout Process
Fromsrc/services/authService.ts:168:
Future Enhancements
Role-Based UI
Implement conditional rendering based on user role:
- Hide features user can’t access
- Disable buttons for restricted actions
- Show role-appropriate navigation
Granular Permissions
More fine-grained control:
- Permission-based instead of role-based
- Custom permission sets
- Resource-level permissions
Audit Logging
Track user actions:
- Who created/modified records
- Timestamp of changes
- History of modifications
- Compliance reporting
Multi-Factor Auth
Enhanced security:
- SMS verification
- Email verification
- Authenticator apps
- Backup codes
Understanding the user roles and permissions structure is crucial for maintaining security and ensuring users have appropriate access to HRS features.