Authorizes an action on resources owned by the actor.

@param AnCommandContext $context Context parameter

@return bool
338430
protected function _authorizeAction(AnCommandContext $context)
    {
        //if entity is not privatable then it doesn't have access to allow method
        if (!$this->_entity->isPrivatable()) {
            return true;
        }

        //if viewer is admin then return true on the action
        if ($this->_viewer->admin()) {
            return true;
        }

        $action = $context->action;

        //any action on the actor requires being a follower by default
        $context->append(array(
            'default' => LibBaseDomainBehaviorPrivatable::FOLLOWER,
        ));

        //not access to the entiy
        if (! $this->_entity->authorize('access')) {
            return false;
        }

        $parts = explode(':', $action);

        $component = array_shift($parts);
        //check if it's a social app then if it's enabled

        if ($component) {

            $component = $this->getService('repos:components.component')->find(array('component' => $component));

            if (
                $component &&
                $component->authorize('action', array(
                                                    'actor' => $this->_entity,
                                                    'action' => $parts[1],
                                                    'resource' => $parts[0],
                                                    )) === false
            ) {
                return false;
            }
        }

        return $this->_entity->allows($this->_viewer, $action, $context->default);
    }
1189915
protected function _authorizeSubscribe($context)
    {
        $entity = $this->_entity;

        if (is_guest($this->_viewer)) {
            return false;
        }

        if (! $entity->isSubscribable()) {
            return false;
        }

        return $this->_viewer->following($entity);
    }
1332986
protected function _authorizeBlock(AnCommandContext $context)
    {
        if (is_guest($this->_viewer)) {
            return false;
        }

        //viewer can only block actor from following them if and only if actor is leadable (can follow ) and viewer is followable
        if (!$this->_entity->isLeadable()) {
            return false;
        }

        if ($this->_viewer->eql($this->_entity)) {
            return false;
        }

        //you can't block an admin
        if ($this->_entity->admin()) {
            return false;
        }

         //if entity is administrable and the viewer is one of the admins then it can not be blocked
        if (
            $this->_entity->isAdministrable() &&
            $this->_entity->administratorIds->offsetExists($this->_viewer->id)
        ) {
            return false;
        }

        return true;
    }
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;
    }
322048
protected function _authorizeDelete($context)
    {
        $owneids = $this->_entity->getIds('owner');

        if (count($owneids) > 1) {
            return false;
        } elseif ($this->_viewer->admin()) {
            return true;
        } elseif ($this->_entity->owner->authorize('administration')) {
            return true;
        }

        return false;
    }
110658
protected function _authorizeEdit($context)
    {
        if ($this->_viewer->guest()) {
            return false;
        }

        if ($this->_viewer->admin()) {
            return true;
        }

        return false;
    }
306003
protected function _authorizeVote($context)
    {
        if ($this->_viewer->guest()) {
            return false;
        }

        //if the owner has blocked the viewer or the other way around, return false

        if ($this->_entity instanceof ComBaseDomainEntityComment) {
            $owner = $this->_entity->parent->owner;
        } elseif ($this->_entity->isOwnable()) {
            $owner = $this->_entity->owner;
        } elseif (is_person($this->_entity)) {
            $owner = $this->_entity;
        }

        if ($owner && ($owner->blocking($this->_viewer) || $this->_viewer->blocking($owner))) {
            return false;
        }

        return $this->_entity->isVotable();
    }
508321
protected function _actionAdd(AnCommandContext $context)
    {
        $data = $context->data;

        return $this->getRepository()->create($data->toArray());
    }
96856
protected function _actionSignup(AnCommandContext  $context)
    {
        $data = $context->data;

        dispatch_plugin('user.onBeforeAddPerson', array('data' => $context->data));

        $isFirstUser = !(bool) $this->getService('repos:people.person')
                                    ->getQuery(true)
                                    ->fetchValue('id');

        $person = parent::_actionAdd($context);

        $this->getRepository()
        ->getValidator()
        ->addValidation('givenName', 'required')
        ->addValidation('familyName', 'required')
        ->addValidation('username', 'uniqueness')
        ->addValidation('email', 'uniqueness');

        if ($person->validate() === false) {
            throw new AnErrorException($person->getErrors(), AnHttpResponse::BAD_REQUEST);
        }

        $viewer = get_viewer();

        if ($isFirstUser) {
            $person->usertype = ComPeopleDomainEntityPerson::USERTYPE_SUPER_ADMINISTRATOR;
        } else {
            $person->usertype = ComPeopleDomainEntityPerson::USERTYPE_REGISTERED;
        }

        dispatch_plugin('user.onAfterAddPerson', array('person' => $person));

        if ($isFirstUser) {
            $this->registerCallback('after.signup', array($this, 'activateFirstAdmin'));
        } else {
            $context->response->setHeader('X-User-Activation-Required', true);
            $this->setMessage(AnTranslator::sprintf('COM-PEOPLE-PROMPT-ACTIVATION-LINK-SENT', $person->name), 'success');
        }
        
        $this->getResponse()->status = AnHttpResponse::OK;

        return $person;
    }
377139
protected function _authorizeFollower(AnCommandContext $context)
    {
        //viewer can only follow actor if and only if viewer is leadable and actor is followable
        if ($this->_entity->isFollowable() && !$this->_viewer->isLeadable()) {
            return false;
        }

        if ($this->_viewer->eql($this->_entity)) {
            return false;
        }

        if (is_guest($this->_viewer)) {
            return false;
        }

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

            if ($this->_entity->isLeadable() && $this->_entity->following($this->_viewer)) {
                return true;
            } else {
                return false;
            }
        }

        //if the viewer is blocking the entity, then it can not follow the entity
        if ($this->_viewer->isFollowable() && $this->_viewer->blocking($this->_entity)) {
            return false;
        }

        return true;
    }
152106
protected function _beforeControllerAdd(AnCommandContext $context)
    {
        if (!$context->data['owner'] instanceof ComActorsDomainEntityActor) {
            if ($this->getRepository()->hasBehavior('ownable')) {
                $context->data['owner'] = $this->actor;
            }
        }
    }
641728
protected function _actionDelete(AnCommandContext $context)
    {
        $this->getResponse()->status = AnHttpResponse::NO_CONTENT;

        $token = $this->getService('repos:connect.session')->fetchSet(array(
                        'owner' => $this->actor,
                        'api' => $this->getAPI()->getName(),
                    ));

        $token->delete()->save();
    }
652699
protected function _actionGetcount(AnCommandContext $context)
    {
        $count = $this->actor->numOfNewNotifications();
        return $this->getView()->newNotifications($count)->display();
    }
1097919
protected function _actionBrowse(AnCommandContext $context)
    {
        $entities = parent::_actionBrowse($context);

        if ($this->type) {
            $entities->where('folder', '=', $this->type);
        }

        $entities->order($this->sort);

        return $entities;
    }
341971
protected function _actionSetprivacy($context)
    {
        $data = $context->data;

        $names = AnConfig::unbox($data->privacy_name);

        settype($names, 'array');

        foreach ($names as $name) {
            $this->getItem()->setPermission($name, $data->$name);
        }
    }
1334462
protected function _actionUnlead(AnCommandContext $context)
    {
        $this->getResponse()->status = AnHttpResponse::RESET_CONTENT;
        $this->getItem()->removeLeader($this->actor);

        return $this->getItem();
    }
772838
protected function _authorizeDelete(AnCommandContext $context)
    {
        //if viewer same as the person whose profile being vieweed and viewer is a super admin don't allow to delete
        if ($this->_viewer->eql($this->_entity) && $this->_entity->superadmin()) {
            return false;
        }

        return parent::_authorizeDelete($context);
    }