Allow User with selected context on Team

@param User $user Currently authenticated User
@param MemberTag $memberTag MemberTag to list Members
@return boolean
514410
public function index(User $user, MemberTag $memberTag)
    {
        return $this->allowOnTeam($user, $memberTag->team_id);
    }
379227
public function attachMember(User $user,
        /** @noinspection PhpUnusedParameterInspection */
                                   MemberTag $memberTag,
                                   $memberId)
    {
        return $user->selected_context->id === $memberId;
    }
1068672
public function addUser(User $user)
    {
        if (!$this->users->contains($user)) {
            $this->users->add($user);
        }

        return $this;
    }
1204677
public function managerRegisterManagerToTeamAction(
        Team $team,
        User $user,
        User $manager
    )
    {
        $workspace = $team->getWorkspace();
        $this->checkWorkspaceManager($workspace, $manager);
        $this->teamManager->registerManagerToTeam($team, $user);

        return new Response('success', 200);
    }
1191193
public function view(User $user, Member $member)
    {
        return $this->allowOnTeam($user, $member->team_id);
    }
819118
public function setUserPushTag($userTag) {
    	try{
			if (empty($userTag))
				throw new Exception('Paramer "userTag" is required');


    		$params = json_decode($userTag,TRUE);

    		$ret = $this->SendRequest->curl('/user/tag/set.json',$params,'json','im','POST');
    		if(empty($ret))
    			throw new Exception('bad request');
    		return $ret;

    	}catch (Exception $e) {
    		print_r($e->getMessage());
    	}
   }
83883
public function scopeForUserContext($query, Context $context)
    {
        if ($context->hasRole('Coach')) {
            return $query->whereHas('member', function ($query) use ($context) {
                /** @noinspection PhpUndefinedMethodInspection */
                $query->where('team_id', $context->team_id);
            });
        }
        return $query->where('inviter_id', $context->id);
    }
122900
public function hasAccess(MenuAction $action, common_user_User $user, array $node){

        $resolvedAction = $this->getResolvedAction($action);
        if(!is_null($resolvedAction) && !is_null($user)){
            if($node['type'] = $resolvedAction['context'] || $resolvedAction['context'] == 'resource') {
                foreach($resolvedAction['required'] as $key){
                    if(!array_key_exists($key, $node)){
                        //missing required key
                        return self::ACCESS_UNDEFINED;
                    }
                }
                try {
                    if(AclProxy::hasAccess($user, $resolvedAction['controller'], $resolvedAction['action'], $node)){
                        return self::ACCESS_GRANTED;
                    }
                    return self::ACCESS_DENIED;
                } catch(\Exception $e){

                    \common_Logger::w('Unable to resolve permission for action ' . $action->getId() . ' : ' . $e->getMessage() );
                }
            }
        }
        return self::ACCESS_UNDEFINED;
    }
923679
public boolean associateUserWithGroup(String user, String group)
	{
		if (!isUserExist(user))
		{
			throw new SystemException(String.format("User '%s' does not exist.", user));
		}

		if (!isGroupExist(group))
		{
			throw new SystemException(String.format("Group '%s' does not exist.", group));
		}

		List<String> userGroups = allAssociations.get(user);

		if (userGroups == null)
		{
			userGroups = new ArrayList<String>();
		}
		else if (userGroups.contains(group))
		{
			return false;
		}

		userGroups.add(group);

		allAssociations.put(user, userGroups);

		return true;
	}
271206
protected function getImpersonatingUserFromRole($token, $user = null)
    {
        foreach ($token->getRoles() as $role) {
            if ($role instanceof SwitchUserRole) {
                $user = $role->getSource()->getUser();
                break;
            }
        }

        return $user;
    }
772207
public function sendWelcomeMessage(User $user, Token $token = null)
    {
        $mailVars = [
            '{token}' => $token->url,
            '{legal_link}' => Url::toRoute([
                '/legal/default/view',
                'legalId' => Legal::findOne(['key' => 'buyers'])->id,
                'langId' => Language::getCurrent()->id
            ], true)
        ];

        /**
         * @var $mailTemplate Template
         */
        $mailTemplate = \Yii::$app->get('emailTemplates')
            ->getTemplate('welcome', Language::getCurrent()->id);
        $mailTemplate->parseSubject($mailVars);
        $mailTemplate->parseBody($mailVars);

        return \Yii::$app->shopMailer->compose('mail-body', ['bodyContent' => $mailTemplate->getBody()])
            ->setFrom([\Yii::$app->shopMailer->transport->getUsername() => \Yii::$app->name ?? Url::to(['/'], true)])
            ->setTo($user->email)
            ->setSubject($mailTemplate->getSubject())
            ->send();
    }
536456
public function can_subscribe_to_forum(stdClass $user) : bool {
        if ($this->forum->get_type() == 'single') {
            return false;
        }

        return !is_guest($this->get_context(), $user) &&
            subscriptions::is_subscribable($this->get_forum_record());
    }
728960
public function view(User $user, Location $location)
    {
        return $this->allowOnTeam($user, $location->team_id);
    }
251963
public function before(User $user, $ability, MemberTag $memberTag)
    {
        if ($this->fallThroughBefore($ability)) {
            return null;
        }
        return $this->allowForRoleOnTeam($user, 'Coach', $memberTag->team_id, null);
    }
1238953
private function getPermissionTable(User $user) {
		$userId = $user->getId();
		if ($this->permissionTable->has($userId)) {
			return $this->permissionTable->get($userId);
		}

		// always allow what guests can do
		$guestGroup = GroupQuery::create()->findOneByIsGuest(true);

		// collect groups from user
		$groups = GroupQuery::create()->filterByUser($user)->find();
		$userGroup = GroupQuery::create()->filterByOwnerId(($userId))->findOne();
		if ($userGroup) {
			$groups[] = $userGroup;
		}
		$groups[] = $guestGroup;

		// ... structure them
		$permissionTable = new Set();
		foreach ($groups as $group) {
			foreach ($group->getActions() as $action) {
				$permissionTable->add($action->getId());
			}
		}

		$this->permissionTable->set($userId, $permissionTable);

		return $this->permissionTable->get($userId);
	}
630666
private function checkView(TokenInterface $token, User $user)
    {
        return $this->isOrganizationManager($token, $user) ?
              VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED;
    }
48843
public function getTags(
        User $user = null,
        $search = '',
        $withPlatform = false,
        $orderedBy = 'name',
        $order = 'ASC',
        $withPager = false,
        $page = 1,
        $max = 50,
        $strictSearch = false
    )
    {
        $tags = is_null($user) ?
            $this->getPlatformTags(
                $search,
                $orderedBy,
                $order,
                $withPager,
                $page,
                $max,
                $strictSearch
            ) :
            $this->getUserTags(
                $user,
                $search,
                $withPlatform,
                $orderedBy,
                $order,
                $withPager,
                $page,
                $max,
                $strictSearch
            );

        return $tags;
    }