Overview
SushiGo uses a role-based access control (RBAC) system powered by Spatie Laravel Permission. Roles define what employees can do in the system, from operational tasks to administrative functions.Roles are assigned to the User entity (authentication identity), not directly to the Employee profile. The employee record links to the user via
user_id.Role Architecture
Position Roles vs Other Roles
SushiGo distinguishes between:- Position roles: Job titles that define operational responsibilities (e.g., cook, manager)
- Other roles: Non-position permissions (e.g., inventory-manager)
Employee management focuses on position roles. The system preserves non-position roles when updating employee roles.
Available Position Roles
Operational Roles
Manager
Code:
managerBranch manager with operational oversight:- Record daily attendance
- Authorize overtime
- Manage schedules
- View reports for their branch
Cook
Code:
cookKitchen staff responsible for food preparation:- View their own schedule
- Check-in/check-out (when implemented)
- View their attendance history
Kitchen Assistant
Code:
kitchen-assistantSupport staff in the kitchen:- View their own schedule
- Check-in/check-out (when implemented)
- View their attendance history
Delivery Driver
Code:
delivery-driverResponsible for order deliveries:- View their own schedule
- Check-in/check-out (when implemented)
- View their attendance history
Acting Manager
Code:
acting-managerTemporary manager designation:- Same permissions as manager
- Used for temporary promotions
- Can be combined with other roles
Administrative Roles
Admin
Code:
adminSystem administrator with elevated permissions:- Edit historical records
- Manage catalogs
- Override system restrictions
- Access all branches
- Cannot assign super-admin role
Super Admin
Code:
super-adminFull system access:- All admin permissions
- Manage users and permissions
- Assign any role including super-admin
- System configuration
- Privileged: Only assignable by other super-admins
Role Assignment Rules
Creating Employees
When creating an employee:- At least one role is required
- Multiple roles can be assigned simultaneously
- Non-super-admins cannot assign
super-adminrole - Roles are validated against the actor’s assignable roles list
Updating Employee Roles
When updating an employee’s roles:System determines assignable roles
Based on the acting user’s role:
- Super-admin: Can manage all roles
- Others: Can manage all roles except
super-admin
System filters incoming roles
Only roles the actor can assign are processed. Invalid roles are ignored.
System preserves non-manageable roles
Roles outside the actor’s scope are preserved:
- Non-position roles (e.g.,
inventory-manager) - Privileged roles the actor cannot assign
Assignable Roles by Actor
| Actor Role | Can Assign | Cannot Assign |
|---|---|---|
| Super Admin | All roles | None |
| Admin | All except super-admin | super-admin |
| Manager | All except super-admin | super-admin |
| Other roles | All except super-admin | super-admin |
Code Reference
The assignable roles logic is defined inEmployee.php:60:
Assigning Roles to Employees
During Employee Creation
Roles are provided in theroles array:
Updating Employee Roles
To change an employee’s roles, send a PATCH/PUT request:You can update roles independently without sending other employee fields. The system performs a partial update.
Role Synchronization Logic
How syncPositionRoles Works
ThesyncPositionRoles() method in Employee.php:131 implements safe role management:
Example Scenarios
- Scenario 1: Admin Updates Cook
- Scenario 2: Admin Updates Super-Admin
- Scenario 3: Preserving Non-Position Roles
- Scenario 4: Super-Admin Full Control
Initial state: Employee has role
cookAdmin sends: ["manager", "admin"]Result: Employee has roles ["manager", "admin"]Clean replacement - admin can manage both roles
Reading Employee Roles
Get Position Roles Only
To retrieve only position roles for an employee:Employee::POSITION_ROLES:
API Response Format
Employee responses include roles in theuser object:
Role Constants Reference
All role constants are defined inEmployee.php:20-46:
Common Validation Errors
422 - No Roles Provided
422 - No Roles Provided
roles array422 - Invalid Role
422 - Invalid Role
403 - Cannot Assign Super-Admin
403 - Cannot Assign Super-Admin
super-admin roleSolution: Only super-admins can assign the super-admin rolePermission Checking
In Code
Use Spatie Permission helpers to check roles:In Policies
In Blade/Frontend
Best Practices
Principle of Least Privilege
Assign only the roles necessary for the employee’s job function
Regular Audits
Periodically review role assignments to ensure they remain appropriate
Document Changes
Use the
meta field or audit logs to track why roles were changedTest Permissions
Verify role changes in a test environment before applying to production
Related Documentation
Creating Employees
Learn how to create employees with initial roles
Employee Overview
Understand the employee management system
API Reference
Complete API documentation for updating employees
Spatie Permission Docs
Official Spatie Permission documentation