Allow HR to view company shifts but protect from edit/delete
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user