Allow HR to view company shifts but protect from edit/delete

This commit is contained in:
2026-07-14 10:55:18 +08:00
parent 94c1ea050f
commit 778bf0f52b

View File

@@ -16,7 +16,7 @@ class ShiftController extends Controller
if (Auth::user()->can('manage-any-shifts')) {
$q->whereIn('created_by', getCompanyAndUsersId());
} else {
$q->where('created_by', Auth::id());
$q->whereIn('created_by', getCompanyAndUsersId()); // Show all company shift templates
}
});
@@ -122,7 +122,13 @@ class ShiftController extends Controller
public function update(Request $request, $shiftId)
{
$shift = Shift::where('id', $shiftId)
->whereIn('created_by', getCompanyAndUsersId())
->where(function($q) {
if (Auth::user()->can('manage-any-shifts')) {
$q->whereIn('created_by', getCompanyAndUsersId());
} else {
$q->where('created_by', Auth::id());
}
})
->first();
if ($shift) {
@@ -164,7 +170,13 @@ class ShiftController extends Controller
public function destroy($shiftId)
{
$shift = Shift::where('id', $shiftId)
->whereIn('created_by', getCompanyAndUsersId())
->where(function($q) {
if (Auth::user()->can('manage-any-shifts')) {
$q->whereIn('created_by', getCompanyAndUsersId());
} else {
$q->where('created_by', Auth::id());
}
})
->first();
if ($shift) {