canDo('advancedcrm.opportunity.view') && $user->isAdmin()) { return true; } return $opportunity->user_id == user_id() && $opportunity->user_type == user_type(); } /** * Determine if the given user can create a opportunity. * * @param UserPolicy $user * @param Opportunity $opportunity * * @return bool */ public function create(UserPolicy $user) { return $user->canDo('advancedcrm.opportunity.create'); } /** * Determine if the given user can update the given opportunity. * * @param UserPolicy $user * @param Opportunity $opportunity * * @return bool */ public function update(UserPolicy $user, Opportunity $opportunity) { if ($user->canDo('advancedcrm.opportunity.edit') && $user->isAdmin()) { return true; } return $opportunity->user_id == user_id() && $opportunity->user_type == user_type(); } /** * Determine if the given user can delete the given opportunity. * * @param UserPolicy $user * @param Opportunity $opportunity * * @return bool */ public function destroy(UserPolicy $user, Opportunity $opportunity) { return $opportunity->user_id == user_id() && $opportunity->user_type == user_type(); } /** * Determine if the given user can verify the given opportunity. * * @param UserPolicy $user * @param Opportunity $opportunity * * @return bool */ public function verify(UserPolicy $user, Opportunity $opportunity) { if ($user->canDo('advancedcrm.opportunity.verify')) { return true; } return false; } /** * Determine if the given user can approve the given opportunity. * * @param UserPolicy $user * @param Opportunity $opportunity * * @return bool */ public function approve(UserPolicy $user, Opportunity $opportunity) { if ($user->canDo('advancedcrm.opportunity.approve')) { 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; } } }