Allow User with selected context on Team

@param User $user Currently authenticated User
@param Job $job Job to view
@return boolean
559283
public function view(User $user, Job $job)
    {
        return $this->allowOnTeam($user, $job->team_id);
    }
505680
public function teamParamsEditFormAction(
        WorkspaceTeamParameters $params,
        User $user
    )
    {
        $workspace = $params->getWorkspace();
        $this->checkWorkspaceManager($workspace, $user);
        $form = $this->formFactory->create(new TeamParamsType(), $params);

        return array(
            'form' => $form->createView(),
            'params' => $params,
            'workspace' => $workspace
        );
    }
999470
public function detachMemberTagMember(User $user, Member $member)
    {
        return $user->selected_context->id === $member->id;
    }
742759
public function activate(User $user)
    {
        $this->authorize(UsersPolicy::PERMISSION_UPDATE);

        try {
            ($active = $user->isActive()) ? $user->deactivate() : $user->activate();

            $message = $this->transNotification(
                $active ? 'disabled' : 'enabled',
                ['name' => $user->full_name],
                $user->toArray()
            );

            return $this->jsonResponseSuccess(compact('message'));
        }
        catch (\Exception $e) {
            return $this->jsonResponseError(['message' => $e->getMessage()], 500);
        }
    }
590359
private function userAttemptBruteForceLock(User $user)
    {
        if ($this->userAttemptBruteForceLockHasExceeded($user)) {
            return true;
        }
        
        $this->attempts = $user->login_attempt + 1;
        
        if ($this->attempts >= $this->allowedAttempts) {
            $user->updateAttributes(['login_attempt_lock_expiration' => time() + $this->lockoutTime]);
        }
        
        $user->updateAttributes(['login_attempt' => $this->attempts]);
    }
436744
protected function hasValidCredentials($user, $credentials)
    {
        return ! is_null($user) && $this->provider->validateCredentials($user, $credentials);
    }
960815
public function verify(UserPolicy $user, Task $task)
    {
        if ($user->canDo('task.task.verify') && $user->isAdmin()) {
            return true;
        }


        return false;
    }
294435
public function removeUserRole($user, $role)
    {
        $user   =   $this->findUserById($user);
        $role   =   $this->findRoleByKey($role);

        if ($user->not($role->key)) {
            return true;
        }

        return $user->leave($role);
    }
203713
private function getJobRunner(Job $job) {
        if (!$this->runner_pool->has($job->runner_class)) {
            $runner = new $job->runner_class();
            $this->runner_pool->add($runner);
        }
        $runner = $this->runner_pool->get($job->runner_class);

        return $runner;
    }
514079
protected function validateJobParams(Job $job)
    {
        if (empty($job->getSender())) {
            throw new ResultException(ResultException::ERROR_PARAM_SENDER);
        }

        if (empty($job->getRecipient())) {
            throw new ResultException(ResultException::ERROR_PARAM_RECIPIENT);
        }

        if (empty($job->getText())) {
            throw new ResultException(ResultException::ERROR_PARAM_TEXT);
        }
    }
805803
public function view(UserPolicy $user, Job $job)
    {
        if ($user->canDo('career.job.view') && $user->isAdmin()) {
            return true;
        }

        return $job->user_id == user_id() && $job->user_type == user_type();
    }
511843
public function canIfAs(Authorizable $user, string $action): bool
    {
        $this->setUser($user);

        $permission = $this->canIf($action);

        $this->revokeUser();

        return $permission;
    }
511848
public function teamEditFormAction(Team $team, User $user)
    {
        $workspace = $team->getWorkspace();
        $isWorkspaceManager = $this->isWorkspaceManager($workspace, $user);
        $isTeamManager = $this->isTeamManager($team, $user);

        if (!$isWorkspaceManager && !$isTeamManager) {

            throw new AccessDeniedException();
        }
        $form = $this->formFactory->create(new TeamEditType(), $team);

        return array(
            'form' => $form->createView(),
            'team' => $team,
            'workspace' => $workspace
        );
    }
1312515
public function selfRegisterUserToTeamAction(Team $team, User $user)
    {
        $workspace = $team->getWorkspace();
        $this->checkToolAccess($workspace);
        $params = $this->teamManager->getParametersByWorkspace($workspace);
        $maxUsers = $team->getMaxUsers();
        $full = !is_null($maxUsers) && (count($team->getUsers()) >= $maxUsers);
        $nbAllowedTeams = $params->getMaxTeams();
        $userTeams = $this->teamManager
            ->getTeamsByUserAndWorkspace($user, $workspace);
        $nbTeams = count($userTeams);
        $nbAllowed = is_null($nbAllowedTeams) || ($nbTeams < $nbAllowedTeams);

        if ($team->getSelfRegistration() && !$full && $nbAllowed) {
            $this->teamManager->registerUserToTeam($team, $user);
        }

        return new Response('success', 200);
    }
251963
public function before(User $user, $ability, MemberTag $memberTag)
    {
        if ($this->fallThroughBefore($ability)) {
            return null;
        }
        return $this->allowForRoleOnTeam($user, 'Coach', $memberTag->team_id, null);
    }
351311
public function before(User $user, $ability, Member $member)
    {
        if ($this->fallThroughBefore($ability)) {
            return null;
        }
        return $this->allowForRoleOnTeam($user, 'Coach', $member->team_id, null);
    }
1191193
public function view(User $user, Member $member)
    {
        return $this->allowOnTeam($user, $member->team_id);
    }