1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating Permissions

Discussion in 'XenForo Development Discussions' started by Kirk, Feb 29, 2016.

  1. Kirk

    Kirk Well-Known Member

    Hi folks,

    So when creating permissions should I create multiple classes for ControllerPublic or just tie them all into one class ?

    Pretty much I want to have the following permissions:

    Can View XYZ
    Can Create XYZ
     
  2. Lawrence

    Lawrence Well-Known Member

    Most likely a different class, as viewing and creating probably have different classes (ie: index and add). The actual permission check should be contained within the appropriate model. Examples:

    PHP:
        public function actionIndex()
        {
           if (!
    $this->_getYourCustomModel()->canViewXYZ())
            {
                throw 
    $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
            }
        }

        public function 
    actionAdd()
        {
            
    $this->_assertCanCreateXYZ();
        }

        protected function 
    _assertCanCreateXYZ()
        {
            if (!
    $this->_getYourCustomModel()->canCreateXYZ($errorPhraseKey))
            {
                throw 
    $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
            }
        }
     

Share This Page