Overview
ElectroFix AI implements a role-based access control (RBAC) system with three distinct user roles. Each role has different capabilities and access levels within their company’s scope.User Roles
1. Worker
Purpose: Front-line technicians and service workers Capabilities:- View and create service orders
- Access customer and equipment records
- Request AI diagnostics for equipment issues
- Update order status
- Automatically assigned as technician on orders they create
- Cannot assign orders to other technicians
- Module access controlled by permissions flags
- Can only access data within their company
2. Admin
Purpose: Company administrators and managers Capabilities:- Full access to all company data
- Manage company settings and profile
- Create and manage worker accounts
- Assign orders to any technician in the company
- Access all operational modules (billing, inventory)
- Manage subscription plan
- View company-wide analytics
- Can deactivate worker accounts
- Can configure module access for workers
- Can update company VAT and billing settings
3. Developer
Purpose: Platform administrators and developers Capabilities:- Cross-company access (bypass multi-tenancy)
- View all companies and subscriptions
- Access test company environment
- View company insights and analytics
- Full system access for debugging
Role Implementation
User Model
TheUser model includes role-checking methods:
Module-Level Permissions
Permission Flags
Worker users have granular module access control:can_access_billing- Access to billing documents and invoicescan_access_inventory- Access to inventory management
Permission Check Logic
Middleware
EnsureRole Middleware
Restricts route access based on user role:EnsureModuleAccess Middleware
Enforces module-level permissions for workers:Role-Specific Features
Worker: Auto-Assignment
Workers are automatically assigned as the technician on orders they create:Admin: Technician Assignment
Admins can assign orders to any active worker or admin in their company:Developer: Cross-Company Access
Developers bypass company scoping in queries:Account Status
Active Status Check
Theis_active flag controls account access:
Deactivation (Admin Only)
Admins can deactivate worker accounts without deleting them:Permission Matrix
| Feature | Worker | Admin | Developer |
|---|---|---|---|
| View own company orders | ✅ | ✅ | ✅ (all companies) |
| Create orders | ✅ | ✅ | ✅ |
| Assign orders to others | ❌ | ✅ | ✅ |
| Access inventory | 🔒 Permission flag | ✅ | ✅ |
| Access billing | 🔒 Permission flag | ✅ | ✅ |
| Manage workers | ❌ | ✅ | ❌ |
| Edit company settings | ❌ | ✅ | ❌ |
| Manage subscription | ❌ | ✅ | ❌ |
| Cross-company access | ❌ | ❌ | ✅ |
| View company insights | ❌ | ❌ | ✅ |
Dashboard Access
Each role has a dedicated dashboard:Best Practices
1. Always Check Role Before Operations
2. Use Middleware for Route Protection
3. Combine Role and Module Checks
4. Check Active Status
Always verifyis_active before allowing operations (handled by EnsureRole middleware).
5. Developer Role Security
Use the developer role sparingly and only for trusted users, as it bypasses tenant isolation.Database Schema
Related Topics
- Multi-Tenancy - Company data isolation
- Subscription Plans - Plan-based feature access
- AI Diagnostics - AI usage quotas by role