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

Creating Permissions

Kirk

Well-known member
#1
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
 

Lawrence

Well-known member
#2
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
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);
        }
    }