Skip to content

Commit

Permalink
add content block permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Mc Cormack committed Mar 12, 2018
1 parent 975eee7 commit 3f9d152
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/Model/ContentBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
use SilverStripe\Forms\TabSet;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Versioned\VersionedGridFieldItemRequest;

class ContentBlock extends DataObject
class ContentBlock extends DataObject implements PermissionProvider
{
private static $table_name = 'ContentBlock';

Expand Down Expand Up @@ -127,4 +129,54 @@ private function getCMSSelectionFields(FieldList $fields)

return $fields;
}

public function providePermissions()
{
return [
'VIEW_CONTENT_BLOCKS' => [
'name' => 'View content blocks',
'help' => 'Allow viewing page content blocks',
'category' => 'Page - Content Blocks',
'sort' => 100
],
'CREATE_CONTENT_BLOCKS' => [
'name' => 'Create content blocks',
'help' => 'Allow creating page content blocks',
'category' => 'Page - Content Blocks',
'sort' => 100
],
'EDIT_CONTENT_BLOCKS' => [
'name' => 'Edit content blocks',
'help' => 'Allow editing page content blocks',
'category' => 'Page - Content Blocks',
'sort' => 100
],
'DELETE_CONTENT_BLOCKS' => [
'name' => 'Delete content blocks',
'help' => 'Allow deleting page content blocks',
'category' => 'Page - Content Blocks',
'sort' => 100
]
];
}

public function canView($member = null, $context = [])
{
return Permission::check('VIEW_CONTENT_BLOCKS', 'any', $member);
}

public function canCreate($member = null, $context = [])
{
return Permission::check('CREATE_CONTENT_BLOCKS', 'any', $member);
}

public function canEdit($member = null, $context = [])
{
return Permission::check('EDIT_CONTENT_BLOCKS', 'any', $member);
}

public function canDelete($member = null, $context = [])
{
return Permission::check('DELETE_CONTENT_BLOCKS', 'any', $member);
}
}

0 comments on commit 3f9d152

Please sign in to comment.