Last active
August 29, 2015 14:10
-
-
Save wernerkrauss/99c1565a4b16e08145e6 to your computer and use it in GitHub Desktop.
Permission check for a DataObject.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyDataObject extends DataObject implements PermissionProvider { | |
/** | |
... | |
*/ | |
/** | |
* Return a map of permission codes to add to the dropdown shown in the Security section of the CMS. | |
* array( | |
* 'VIEW_SITE' => 'View the site', | |
* ); | |
*/ | |
public function providePermissions() | |
{ | |
return array( | |
"MANAGE_XXX" => array( | |
'name' => _t('ManageXXX', 'Manage XXX'), | |
'category' => _t('Permission.XXX_CATEGORY', 'XXX') | |
) | |
); | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function canCreate($member = null){ | |
return Permission::check('MANAGE_XXX') | |
? true | |
: parent::canCreate($member); | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function canView($member = null){ | |
return Permission::check('MANAGE_XXX') | |
? true | |
: parent::canView($member); | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function canEdit($member = null){ | |
return Permission::check('MANAGE_XXX') | |
? true | |
: parent::canEdit($member); | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function canDelete($member = null){ | |
return Permission::check('MANAGE_XXX') | |
? true | |
: parent::canDelete($member); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment