canDo('case.cases.view') && $user->is('admin')) { return true; } if ($user->canDo('blocks.block.view') && $user->is('manager') && $block->user->parent_id == $user->id) { return true; } return $user->id === $cases->user_id; } /** * Determine if the given user can create a cases. * * @param UserPolicy $user * @param Cases $cases * * @return bool */ public function create(UserPolicy $user) { return $user->canDo('case.cases.create'); } /** * Determine if the given user can update the given cases. * * @param UserPolicy $user * @param Cases $cases * * @return bool */ public function update(UserPolicy $user, Cases $cases) { if ($user->canDo('case.cases.update') && $user->is('admin')) { return true; } if ($user->canDo('blocks.block.update') && $user->is('manager') && $block->user->parent_id == $user->id) { return true; } return $user->id === $cases->user_id; } /** * Determine if the given user can delete the given cases. * * @param UserPolicy $user * @param Cases $cases * * @return bool */ public function destroy(UserPolicy $user, Cases $cases) { if ($user->canDo('case.cases.delete') && $user->is('admin')) { return true; } if ($user->canDo('blocks.block.delete') && $user->is('manager') && $block->user->parent_id == $user->id) { return true; } return $user->id === $cases->user_id; } /** * Determine if the given user can verify the given cases. * * @param UserPolicy $user * @param Cases $cases * * @return bool */ public function verify(UserPolicy $user, Cases $cases) { if ($user->canDo('case.cases.verify') && $user->is('admin')) { return true; } if ($user->canDo('case.cases.verify') && $user->is('manager') && $cases->user->parent_id == $user->id) { return true; } return false; } /** * Determine if the given user can approve the given cases. * * @param UserPolicy $user * @param Cases $cases * * @return bool */ public function approve(UserPolicy $user, Cases $cases) { if ($user->canDo('case.cases.approve') && $user->is('admin')) { return true; } return false; } /** * Determine if the user can perform a given action ve. * * @param [type] $user [description] * @param [type] $ability [description] * * @return [type] [description] */ public function before($user, $ability) { if ($user->isSuperUser()) { return true; } } }