Overview
GIMA implements a comprehensive role-based access control (RBAC) system using Spatie Laravel Permission. The system defines four distinct roles with specific permissions, enabling secure and efficient workflow management across different user types.Role Hierarchy
Admin
Full System ControlComplete access to all features and settings. Can manage users, roles, and all system data.
Supervisor
Management & OversightManages assets, assigns tasks to technicians, and oversees maintenance operations.
Técnico
Task ExecutionExecutes assigned maintenance tasks, records activities, and manages spare parts usage.
Reporter
Fault ReportingReports asset failures and views their own submitted reports. Read-only access to assets.
Permission System
Permissions in GIMA are defined indatabase/seeders/RolesSeeder.php and assigned to roles during system initialization.
Permission Categories
Shared Permissions (All Roles)
Shared Permissions (All Roles)
Admin Permissions (Admin Only)
Admin Permissions (Admin Only)
Exclusive administrative capabilities:
gestionar usuarios: Full CRUD operations on usersgestion maestra: Manage master data (Locations, Spare Parts, Suppliers)- All permissions: Admins inherit every permission in the system
Supervisor Permissions
Supervisor Permissions
Management and coordination capabilities:
ver dashboard supervisor: Access supervisor dashboardgestionar activos: Create, modify, and list assetsgestionar reportes: Assign fault reports to techniciansgestionar mantenimientos: Create and modify maintenance plans- Plus all shared permissions
Técnico Permissions
Técnico Permissions
Technical execution capabilities:
ver mis tareas: View assigned tasksregistrar actividad tecnica: Record task start, progress, and completionregistrar repuestos usados: Register spare parts usage and consumption- Plus all shared permissions
Role Definitions in Code
Fromdatabase/seeders/RolesSeeder.php:source/database/seeders/RolesSeeder.php:
Admin Role Assignment
The Admin role automatically receives all current and future permissions, ensuring complete system access.
Supervisor Role Assignment
Técnico Role Assignment
Reporter Role Assignment
User Model Integration
TheUser model integrates Spatie’s permission system:
User Approval Workflow
Route Protection
Routes are protected using role middleware from Spatie Permission:Admin-Only Routes
Multi-Role Routes
Supervisor Routes
Permission Checking
In Controllers
In Blade Templates
In API Responses
Role Comparison Matrix
| Permission | Admin | Supervisor | Técnico | Reporter |
|---|---|---|---|---|
| User Management | ||||
| Gestionar usuarios | ✅ | ❌ | ❌ | ❌ |
| Asset Management | ||||
| Gestionar activos | ✅ | ✅ | ❌ | ❌ |
| Ver catálogo activos | ✅ | ✅ | ✅ | ✅ |
| Maintenance | ||||
| Gestionar mantenimientos | ✅ | ✅ | ❌ | ❌ |
| Ver mis tareas | ✅ | ✅ | ✅ | ❌ |
| Registrar actividad técnica | ✅ | ✅ | ✅ | ❌ |
| Reports | ||||
| Crear reporte fallas | ✅ | ✅ | ✅ | ✅ |
| Gestionar reportes | ✅ | ✅ | ❌ | ❌ |
| Ver mis reportes | ✅ | ✅ | ✅ | ✅ |
| Inventory | ||||
| Registrar repuestos usados | ✅ | ✅ | ✅ | ❌ |
| Gestión maestra | ✅ | ❌ | ❌ | ❌ |
| Dashboards | ||||
| Ver dashboard supervisor | ✅ | ✅ | ❌ | ❌ |
Default Test Users
The seeder creates default users for testing:Permission Cache
Spatie Permission caches permissions for performance. Clear the cache when modifying permissions:The cache is automatically cleared in
RolesSeeder.php:source/database/seeders/RolesSeeder.php at line 21.Best Practices
Principle of Least Privilege
Assign users the minimum permissions needed for their role. Avoid granting unnecessary access.
Role Naming
Use lowercase, singular names for roles (
admin, not Admin or admins) to match Spatie conventions.Permission Naming
Use descriptive, action-based names (
gestionar activos, not assets or manage).Middleware Protection
Always protect routes with
auth:sanctum and role middleware. Never rely on client-side checks alone.Next Steps
Architecture
Learn about system architecture
Asset Management
Understand asset lifecycle
Authentication
API authentication guide