2.8 KiB
2.8 KiB
PLAN: Branch Manager Scope & Map UI
1. Context & Objectives
- Objective 1: Improve the Map UI in
LocationPicker.tsxby hiding the manual latitude and longitude inputs, leaving only the map and potentially the radius input. Make the radius visually draggable on the map. - Objective 2: Implement branch-level isolation for managers. Managers with a specific role/permission (e.g.,
manage-branch-employees) should only be able to view, edit, and manage employees that belong to their own branch.
2. Technical Approach
Phase 1: Map UI Enhancements (Location Picker)
- Hide Lat/Lng Inputs: Modify
resources/js/components/LocationPicker.tsxto hide the Latitude and Longitude input fields to clean up the UI. - Draggable Radius:
- Since standard Leaflet circles aren't draggable by default, we will implement a secondary "handle" marker on the edge of the circle.
- When the user drags this handle, it will dynamically calculate the new distance to the center (using Haversine or Leaflet's
distanceTo) and update the radius state in real-time.
Phase 2: Branch Manager Scope Restriction
- Database/Permissions: Add a new permission
manage-branch-employeesvia a Laravel migration (using Spatie Permissions) to allow strict scoping. - Employee Query Scoping:
- Update
EmployeeController@index(and other relevant list methods). - Add logic:
elseif (Auth::user()->can('manage-branch-employees')) { $q->whereHas('employee', function($eq) use ($authUser) { $eq->where('branch_id', $authUser->employee->branch_id); }); }
- Update
- Validation/Protection:
- Update
show,edit,update, anddestroymethods inEmployeeControllerto strictly verify that if the user only hasmanage-branch-employees, they cannot access an employee whosebranch_iddoes not match their own.
- Update
- Attendance Records Scoping: Apply the same branch-level isolation to
AttendanceRecordControllerso branch managers only see attendance logs for their own branch.
3. Execution Steps
- Edit
LocationPicker.tsxto hide lat/lng inputs. - Add draggable edge marker logic to
LocationPicker.tsxfor visual radius adjustment. - Create a Laravel migration to insert the
manage-branch-employeespermission. - Update
EmployeeController.phpqueries and authorization checks to restrict by branch. - Update
AttendanceRecordController.phpqueries to scope by branch.
4. Open Questions (Socratic Gate)
- For the
manage-branch-employeespermission, do you want me to create a dedicated Database Seeder/Migration for this new permission, or just adjust the logic so that anyone withmanage-employeesbut withoutmanage-any-employeesis automatically restricted to their branch? - Do you want this branch restriction to apply strictly to Employees and Attendance, or should it also extend to Leaves, Payroll, and other HR features?