Skip to content

Instantly share code, notes, and snippets.

@wernerkrauss
Last active August 29, 2015 14:10
Show Gist options
  • Save wernerkrauss/99c1565a4b16e08145e6 to your computer and use it in GitHub Desktop.
Save wernerkrauss/99c1565a4b16e08145e6 to your computer and use it in GitHub Desktop.
Permission check for a DataObject.
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