Creating Permissions

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
 
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);
        }
    }
 
Back
Top Bottom