update: latest changes to multi-tenant branch
This commit is contained in:
@@ -11,19 +11,20 @@ class ShiftController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (Auth::user()->can('manage-shifts')) {
|
||||
$query = Shift::with(['creator'])->where(function ($q) {
|
||||
if (Auth::user()->can('manage-any-shifts')) {
|
||||
$q->whereIn('created_by', getCompanyAndUsersId());
|
||||
$user = Auth::user();
|
||||
if ($user->type === 'company' || $user->can('manage-shifts') || $user->can('view-shifts') || $user->can('create-shifts')) {
|
||||
$query = Shift::with(['creator'])->where(function ($q) use ($user) {
|
||||
if ($user->type === 'company' || $user->can('manage-any-shifts') || $user->can('manage-shifts') || $user->can('view-shifts')) {
|
||||
$q->whereIn('created_by', getCompanyAndUsersId());
|
||||
} else {
|
||||
$branchId = Auth::user()->branch_id ?? Auth::user()->employee->branch_id ?? null;
|
||||
$branchId = $user->branch_id ?? $user->employee->branch_id ?? null;
|
||||
if ($branchId) {
|
||||
$q->where(function($q2) use ($branchId) {
|
||||
$q2->where('branch_id', $branchId)
|
||||
->orWhereNull('branch_id'); // company wide shifts
|
||||
})->whereIn('created_by', getCompanyAndUsersId());
|
||||
} else {
|
||||
$q->whereIn('created_by', getCompanyAndUsersId());
|
||||
$q->whereIn('created_by', getCompanyAndUsersId());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user