Overview
MotorDesk implements a hierarchical role-based access control (RBAC) system with four distinct user roles, each designed for specific responsibilities within a fleet management business.All user roles are centrally defined in
src/constants/roles/roles.ts for easy maintenance and consistency across the application.Available Roles
The system defines four roles with decreasing levels of access:src/constants/roles/roles.ts
Role Hierarchy
Role Details
1. DUEÑO (Owner)
Business Owner
The highest level of access with complete control over the system. Typically the business owner or primary stakeholder.
- Complete business configuration
- Tax and legal settings (RUC, SUNAT credentials)
- User management (create, modify, delete users)
- Branch management
- Financial reports and analytics
- System-wide settings
- Electronic billing configuration
Dashboard & Analytics
Dashboard & Analytics
- View all business metrics
- Access financial reports
- Export data across all branches
- View profit/loss statements
User Management
User Management
- Create new users with any role
- Edit user information and roles
- Delete or deactivate users
- Assign branch access to users
- Reset user passwords
Branch Management
Branch Management
- Create new branch locations
- Configure branch settings
- Assign users to branches
- View cross-branch analytics
Financial Operations
Financial Operations
- Configure pricing and margins
- Set discount policies
- Manage payment methods
- Configure tax settings
- Access all financial reports
System Configuration
System Configuration
- Electronic billing setup (SUNAT)
- Invoice series configuration
- Backup and data management
- Integration settings
src/hooks/useAuth.ts
2. ADMINISTRADOR (Administrator)
Branch Administrator
Second-highest access level with administrative capabilities for day-to-day operations.
- Daily operations management
- Staff supervision
- Inventory management
- Customer relationship management
- Sales oversight
- Report generation
Sales & Billing
Sales & Billing
- Create and process all invoice types
- Issue refunds and credit notes
- Apply discounts (within limits)
- View sales history
- Cancel or modify invoices
Inventory Management
Inventory Management
- Add/edit/delete products
- Manage stock levels
- Set product pricing
- Create product categories
- Import/export product data
Customer Management
Customer Management
- Full CRUD on customer records
- Manage customer vehicles
- View customer history
- Export customer data
Reporting
Reporting
- Generate sales reports
- View inventory reports
- Access customer analytics
- Export reports
Team Oversight
Team Oversight
- View seller/cashier activities
- Assign tasks to team members
- Cannot create or delete users
- Cannot access system configuration
- Cannot create or delete users
- Cannot modify owner settings
- Limited to assigned branches only
Example: Admin User
3. VENDEDOR (Seller)
Sales Representative
Front-line staff focused on sales and customer service.
- Process sales and create invoices
- Customer registration
- Vehicle information entry
- Product search and recommendation
- Service documentation
Sales Processing
Sales Processing
- Create invoices and receipts
- Add products to sales
- Calculate totals and taxes
- Print/email invoices
- Create proforma invoices
Customer Interaction
Customer Interaction
- Register new customers
- Update customer information
- Add vehicle records
- Update vehicle service history
- View customer purchase history
Product Lookup
Product Lookup
- Search product catalog
- View product availability
- View product prices
- Cannot modify prices or inventory
Limited Reporting
Limited Reporting
- View own sales statistics
- Generate daily sales summary
- Limited access to reports
- Cannot modify product prices
- Cannot access inventory management
- Cannot delete invoices
- Cannot apply large discounts (policy-dependent)
- Cannot access financial reports
- Cannot manage users
Example: Seller User
4. CAJERO (Cashier)
Cashier
Specialized role focused on payment processing and transaction recording.
- Process payments
- Handle cash transactions
- Close sales
- Issue receipts
- Daily cash reconciliation
Payment Processing
Payment Processing
- Accept cash payments
- Process card transactions
- Issue payment receipts
- Handle mixed payment methods
- Process refunds (with approval)
Transaction Management
Transaction Management
- View pending transactions
- Close sales
- Print receipts
- Email invoices to customers
Cash Register
Cash Register
- Open/close register
- Record cash movements
- Generate cash count reports
- Handle change requests
Basic Reporting
Basic Reporting
- Daily cash summary
- Transaction log
- Personal sales totals
- Cannot create new sales (only process payments)
- Cannot access inventory
- Cannot modify customer records
- Cannot access financial reports
- Cannot manage products or pricing
- Cannot manage users
- Limited to single branch
Example: Cashier User
Role Comparison Matrix
| Feature | DUEÑO | ADMINISTRADOR | VENDEDOR | CAJERO |
|---|---|---|---|---|
| System Configuration | ✅ | ❌ | ❌ | ❌ |
| User Management | ✅ | ❌ | ❌ | ❌ |
| Branch Management | ✅ | ✅ | ❌ | ❌ |
| Create Sales | ✅ | ✅ | ✅ | ❌ |
| Process Payments | ✅ | ✅ | ✅ | ✅ |
| Manage Inventory | ✅ | ✅ | ❌ | ❌ |
| Modify Prices | ✅ | ✅ | ❌ | ❌ |
| Manage Customers | ✅ | ✅ | ✅ | ❌ |
| Full Reports Access | ✅ | ✅ | ❌ | ❌ |
| Own Sales Reports | ✅ | ✅ | ✅ | ✅ |
| Multi-Branch Access | ✅ | ✅ | ❌ | ❌ |
| Electronic Billing Setup | ✅ | ❌ | ❌ | ❌ |
Implementing Role-Based Access
Checking User Role
Access the current user’s role from the Redux store:Example: Role Check
Creating Permission Guards
Create reusable permission check functions:utils/permissions.ts
Component-Level Protection
Protect UI components based on permissions:Example: Conditional Rendering
Route-Level Protection
Protect entire routes based on role:Example: Protected Route
Branch Access Control
Users can be assigned to specific branches:Example: Branch Assignment
DUEÑO (Owner) users automatically have access to all branches regardless of their
branchIds array.Managing Users
Creating New Users
Only owners can create new users (typically through Settings):Example: Create User
Role Assignment Best Practices
Assess responsibilities
Determine what the user needs to do daily:
- Full business control? → DUEÑO
- Daily operations & staff management? → ADMINISTRADOR
- Customer service & sales? → VENDEDOR
- Payment processing only? → CAJERO
Apply principle of least privilege
Assign the minimum role needed for the user to perform their job. You can always upgrade later.
Assign branch access
- Owners: Automatic access to all branches
- Admins: Can manage multiple branches
- Sellers/Cashiers: Usually single branch
Security Considerations
Common Scenarios
Scenario 1: New Branch Opening
Scenario 2: Employee Promotion
Example: Promote User
Scenario 3: Temporary Access Needs
Next Steps
Authentication
Learn how login and registration work
Settings Management
Configure users and team settings
State Management
Understand Redux store structure
API Reference
Explore hooks and utilities
