Check if the viewer can set certain privacy value.

@param AnCommandContext $context Context parameter

@return bool
550636
protected function _authorizeSetPrivacyValue(AnCommandContext $context)
    {
        $value = $context->value;

        if ($this->_entity->authorize('administration')) {
            return true;
        }

        switch ($value) {
            case LibBaseDomainBehaviorPrivatable::GUEST :
            case LibBaseDomainBehaviorPrivatable::REG :
                $ret = true;
            break;

            case LibBaseDomainBehaviorPrivatable::FOLLOWER :
                $ret = $this->_entity->isFollowable() && $this->_entity->leading($this->_viewer);
            break;

            default :
                $ret = $this->_entity->authorize('administration');
        }

        return (bool) $ret;
    }
863060
protected function _actionGetaccesstoken($context)
    {
        $this->getBehavior('oauthorizable')->execute('action.getaccesstoken', $context);
        
        if ($token = $this->getAPI()->getToken()) {
            $context->response->setRedirect('view=login');
            return true;
        }
        
        $context->response->setRedirect(route('option=com_people&view=session'));
    }
862216
protected function _authorizeUnfollow(AnCommandContext $context)
    {
        //if the viewer is not following then return false;
        //Riddle : How can you unfollow an actor that you are not following
        if (!$this->_viewer->following($this->_entity)) {
            return false;
        }

        //if entity is adminitrable and the viewer is an admin and there are only one admin. then the viewer can't unfollow
        if (
            $this->_entity->isAdministrable() &&
            $this->_entity->administratorIds->offsetExists($this->_viewer->id)
        ) {
            return ($this->_entity->administratorIds->count() >= 2);
        }

        return true;
    }
94762
private function atLeastOneConditionHolds(Context $context)
    {
        foreach ($this->conditions as $condition) {
            if ($condition->holdsFor($context)) {
                return true;
            }
        }

        return false;
    }
418475
protected function _actionDelete(AnCommandContext $context)
    {
        $viewer = $this->_state->viewer;
        $person_id = $viewer->id;
        dispatch_plugin('user.onBeforeLogoutPerson', array('person' => $viewer));
        $this->getService('com:people.helper.person')->logout($viewer);
        dispatch_plugin('user.onAfterLogoutPerson', array('id' => $person_id));
        $context->response->setRedirect(route('index.php?'));
    }
839699
protected function _beforeControllerGet(AnCommandContext $context)
    {
        if ($this->cid) {
            $context->response->content = $this->getCommentController()->id($this->cid)->display();

            return false;
        } elseif ($this->permalink && !$context->request->isAjax()) {
            $cid = (int) preg_replace_callback('/[^\d]+/', function($matches) { return ''; }, $this->permalink);
            $offset = $this->getItem()->getCommentOffset($cid);
            $start = (int) ($offset / $this->limit) * $this->limit;
            $url = AnRequest::url();
            $query = $url->getQuery(true);

            if ($this->start != $start) {
                $query = array_merge($query, array('start' => $start));
            }

            unset($query['permalink']);

            $url->setQuery($query);

            $context->response->setRedirect($url.'#scroll='.$this->permalink);

            return false;
        }
    }
885272
public function isRoleScopePresentOnce(ExecutionContextInterface $context) 
    {
        $roleScopesId = array_map(function(RoleScope $roleScope) {
                    return $roleScope->getId();
                }, 
                $this->getRoleScopes()->toArray());
        $countedIds = array_count_values($roleScopesId);
        
        foreach ($countedIds as $id => $nb) {
            if ($nb > 1) {
                $context->buildViolation("A permission is already present "
                        . "for the same role and scope")
                        ->addViolation();
            }
        }
    }
974463
protected function is_needed( $context = null ) {

		$is_needed = $this->hasConfigKey( 'is_needed' )
			? $this->getConfigKey( 'is_needed' )
			: true;

		if ( is_callable( $is_needed ) ) {
			return $is_needed( $context );
		}

		return (bool) $is_needed;
	}
152369
protected function _authorizeAdministration(AnCommandContext $context)
    {
        $ret = false;

        if ($this->_entity->authorize('access', $context)) {

            if ($this->_viewer->isAdministrator()) {
                $ret = $this->_viewer->administrator($this->_entity);
            }

            if ($context->strict !== true) {
                $ret = $ret || $this->_viewer->admin();
            }
        }

        return (bool) $ret;
    }
689320
protected function _afterEntityInstantiate(AnCommandContext $context)
    {
        $data = $context->data;

        if ($data->portrait) {
            $this->setPortrait($data->portrait);
        }
    }
1077592
protected function _actionRead(AnCommandContext $context)
    {
        if (!$this->getAPI()) {
            $context->response->setRedirect(route('option=com_people&view=session'));
            return false;
        }
        
        $service = $this->getAPI()->getName();
        $profileId = $this->getAPI()->getUser()->id;
        $token = $this->getService('repos:connect.session')
                      ->find(array(
                          'profileId' => $profileId, 
                          'api' => $service
                      ));
                      
        $return_url = AnRequest::get('session.return', 'raw');

        if ($token) {
            $person = $token->owner;
            AnRequest::set('session.oauth', null);

            $credentials = array(
                'username' => $person->username,
                'password' => get_hash('COM_CONNECT_PASSWORD')
            );

            if ($this->getService('com:people.helper.person')->login($credentials)) {
                $context->response->setRedirect(base64_decode($return_url));
            }

            return false;
        }

        $this->return_url = base64_encode($return_url);
    }
122202
public function canEvaluate($context)
    {
        if (count($context) === 0) {
            return true;
        }

        foreach ($context as $contextNode) {
            if (!$contextNode instanceof NodeInterface) {
                return false;
            }
        }
        return true;
    }
659090
public function evaluate( Context $context ) {
		/**
		 * Extracts variables.
		 *
		 * @var \Ruler\Variable $left
		 * @var \Ruler\Variable $right
		 */
		list( $left, $right ) = $this->getOperands();

		$left  = $left->prepareValue( $context )->getValue();
		$right = $right->prepareValue( $context )->getValue();

		if ( 2 !== count( $right ) ) {
			return false;
		}

		// Make sure we have a valid range.
		if ( $right[0] > $right[1] ) {
			$temp     = $right[0];
			$right[0] = $right[1];
			$right[1] = $temp;
		}

		return ( $left >= $right[0] && $left <= $right[1] );
	}
913934
protected function _authorizeAdd(AnCommandContext $context)
    {
        $can_publish = get_config_value($this->_entity->component, 'can_publish', self::CAN_ADD_ADMIN);

        switch ($can_publish) {
            case self::CAN_ADD_ADMIN :
                return $this->_viewer->admin();
            case self::CAN_ADD_SPECIAL :
                return $this->_viewer->usertype != 'Registered' && !$this->_viewer->guest();
            case self::CAN_ADD_ALL :
                return !$this->_viewer->guest();
            default :
                return false;
        }
    }
1329299
protected static function hasScope(ContextInterface $context, string $scope): bool
    {
        $result = false;

        if (static::ctxHasCurrentAccount($context) === true) {
            /** @var PassportAccountInterface $account */
            $account = self::ctxGetCurrentAccount($context);
            $result  = $account->hasScope($scope);
        }

        return $result;
    }
533471
public function appliesToContext(ContextInterface $context): bool
    {
        if (!$context instanceof PropertyContext) {
            return false;
        }

        $property = $context->getProperty();
        if (!preg_match($this->regex, $property->getName())) {
            return false;
        }

        return $this->subRule->appliesToContext($context);
    }
1247869
public function setUser(SecurityContext $context)
    {
        $this->user = $context->getToken() ? $context->getToken()->getUser() : null;
    }