Authorizes an action. This method can be overriden by the mixer. This method
will call can[Action Name].

@param AnCommandContext $context The CommandChain Context

@return bool
353017
public function canExecute($action)
    {
        $ret = true;

        //Check if the action can be executed
        $method = 'can'.ucfirst($action);

        if (in_array($method, $this->_mixer->getMethods())) {
            $ret = $this->_mixer->$method();
        } else {
            //if method doesn't exist then check if the action
            //exists
            $actions = $this->getActions();
            $actions = array_flip($actions);
            $ret = isset($actions[$action]);
        }

        return $ret;
    }
464279
protected function authorize(?string $action = null): bool
    {
        if (empty($action)) {
            return false;
        }

        return $this->foundation->acl()->can($action);
    }
1149876
public function execute($name, AnCommandContext $context)
    {
        $type = '';
        
        if ($context->caller) {
            $identifier = $context->caller->getIdentifier();
            
            if ($identifier->path) {
                $type = AnInflector::implode($identifier->path);
            } else {
                $type = $identifier->name;
            }
        }
        
        $parts = explode('.', $name);
        $name = 'on'.ucfirst(array_shift($parts)).ucfirst($type).AnInflector::implode($parts);
        
        $event = new AnEvent(clone($context));
        $event->setPublisher($context->caller);
        
        $this->_event_dispatcher->dispatchEvent($name, $event);
        
        return true;
    }
663562
protected function _actionSetPrivacy(AnCommandContext $context)
    {
        if ($this->hasBehavior('privatable')) {
            $this->getBehavior('privatable')->execute('action.setprivacy', $context);
        }

        $data = $context->data;

        if ($data->access != 'followers') {
            $data->allowFollowRequest = false;
        }

        $this->getItem()->allowFollowRequest = (bool) $data->allowFollowRequest;
    }
361371
protected function _authorizeAddComment($context)
    {
        if (isset($this->_entity->object)) {
            if (is_array($this->_entity->object)) {
                return false;
            }

            if (!$this->_entity->object->isAuthorizer()) {
                return false;
            }

            return $this->_entity->object->authorize('add.comment');
        } else {
            return false;
        }
    }
589565
protected function _actionException(AnCommandContext $context)
    {
        if (
            $context->data instanceof LibBaseControllerExceptionUnauthorized &&
            $this->getController() instanceof ComPeopleControllerSession
        ) {
            $context->response->send();
            exit(0);
        } else {
            parent::_actionException($context);
        }
    }
18739
protected function _actionAddapp(AnCommandContext $context)
    {
        $data = $context->data;
        $this->getItem()->components->insert($data->app);
        $this->commit();
    }
911885
protected function _actionEdit(AnCommandContext $context)
    {
        $data = $context->data;

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

        //dont' set the usertype yet, until we find the conditions are met
        $usertype = null;

        if ($data->usertype) {
            $usertype = $data->usertype;
            unset($context->data->usertype);
        }

        if ($data->password) {
            $_SESSION['reset_password_prompt'] = 0;
        }

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

        //add the validations here
        $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);
        }

        //now check to see if usertype can be set, otherwise the value is unchanged
        if (in_array($usertype, $this->_allowed_user_types) && $person->authorize('changeUsertype')) {
            $person->usertype = $usertype;
        }

        $person->timestamp();

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

        $this->setMessage('LIB-AN-PROMPT-UPDATE-SUCCESS', 'success');

        $edit = ($data->password && $data->username) ? 'account' : $this->_request->edit;
        $url = sprintf($person->getURL(false)."&get=settings&edit=%s", $edit);
        $context->response->setRedirect(route($url));

        return $person;
    }
60861
public function execute($name, AnCommandContext $context)
    {
        $result    = true;

        if (isset($this->_callbacks[$name])) {
            $callbacks = $this->_callbacks[$name];
            $params = $this->_params[$name];

            foreach ($callbacks as $key => $callback) {
                $param = $params[$key];

                if (is_array($param) && is_numeric(key($param))) {
                    $result = call_user_func_array($callback, $params);
                } else {
                    $result = call_user_func($callback, $context->append($param));
                }

                //Call the callback
                if ($result === false) {
                    break;
                }
            }
        }

        return $result === false ? false : true;
    }
110658
protected function _authorizeEdit($context)
    {
        if ($this->_viewer->guest()) {
            return false;
        }

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

        return false;
    }
1132909
protected function _actionRoute(AnCommandContext $context)
    {
        //route the application
        $url = clone AnRequest::url();
        $url = $this->_application->getRouter()->parse($url);

        AnRequest::set('get', $url->query);

        $url->query = AnRequest::get('get', 'raw');

        //set the request
        $this->getRequest()->append($url->query);

        $component = substr($this->_request->option, 4);

        if (empty($component)) {
            $context->request->set('option', 'com_application');
            $component = 'application';
        }

        $this->setComponent($component)->dispatch();

        // trigger the onAfterRoute events
        dispatch_plugin('system.onAfterRoute');
    }
1354040
protected function _actionAddrequest(AnCommandContext $context)
    {
        if ($this->getItem()->eql($this->actor)) {
            throw new LibBaseControllerExceptionForbidden('Forbidden');
        }

        $this->getResponse()->status = AnHttpResponse::RESET_CONTENT;
        $this->getItem()->addRequester($this->actor);
        $this->createNotification(array(
            'subject' => $this->actor,
            'target' => $this->getItem(),
            'name' => 'actor_request',
          ));

        return $this->getItem();
    }
438297
public function redirect(AnCommandContext $context)
    {
        $url = null;

        if ($context->action == 'delete') {
            $url = 'option=com_'.$this->getIdentifier()->package.'&view='.AnInflector::pluralize($this->getIdentifier()->name);
        } elseif ($context->action == 'add') {
            $url = $context->result->getURL().'&get=settings';
        }

        if ($url) {
            $context->response->setRedirect(route($url));
        }
    }
664859
public function authorize()
    {
        $crude = CrudeInstance::get($this->crudeName);

        if ($crude == null)
            return false;

        if ($crude->cannotView())
            return false;

        $model = $crude->getById($this->id);

        $permission = $this->action . 'CustomActionPermission';
        if (method_exists($crude, $permission) && ! $crude->$permission($model))
            return false;

        $method = $this->action . 'CustomAction';
        if (! method_exists($crude, $method))
            return false;

        $this->crude = $crude;
        $this->model = $model;

        return true;
    }
1082354
protected function _authorizeAdministration(AnCommandContext $context)
    {
        //if viewer is the same as the person
        if ($this->_viewer->eql($this->_entity)) {
            return true;
        }

        //if viewer is super admin
        if ($this->_viewer->superadmin()) {
            return true;
        }

        //if viewer is admin and the person is not a super admin
        if ($this->_viewer->admin() && !$this->_entity->superadmin()) {
            return true;
        }

        return false;
    }
1135683
public function execute($command, $context)
    {
        if (!$context instanceof  AnCommandContext) {
            $context = new AnCommandContext($context);
        }

        $parts = explode('.', $command);
        $method = '_'.$parts[0].'Entity'.ucfirst($parts[1]);
        $result = null;

        if (method_exists($this, $method)) {
            $result = $this->$method($context);
        }

        return $result;
    }
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;
    }