Skip to content

Commit 3f9d152

Browse files
author
Andrew Mc Cormack
committed
add content block permissions
1 parent 975eee7 commit 3f9d152

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/Model/ContentBlock.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
use SilverStripe\Forms\TabSet;
1818
use SilverStripe\ORM\DataObject;
1919
use SilverStripe\ORM\FieldType\DBField;
20+
use SilverStripe\Security\Permission;
21+
use SilverStripe\Security\PermissionProvider;
2022
use SilverStripe\Versioned\Versioned;
2123
use SilverStripe\Versioned\VersionedGridFieldItemRequest;
2224

23-
class ContentBlock extends DataObject
25+
class ContentBlock extends DataObject implements PermissionProvider
2426
{
2527
private static $table_name = 'ContentBlock';
2628

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

128130
return $fields;
129131
}
132+
133+
public function providePermissions()
134+
{
135+
return [
136+
'VIEW_CONTENT_BLOCKS' => [
137+
'name' => 'View content blocks',
138+
'help' => 'Allow viewing page content blocks',
139+
'category' => 'Page - Content Blocks',
140+
'sort' => 100
141+
],
142+
'CREATE_CONTENT_BLOCKS' => [
143+
'name' => 'Create content blocks',
144+
'help' => 'Allow creating page content blocks',
145+
'category' => 'Page - Content Blocks',
146+
'sort' => 100
147+
],
148+
'EDIT_CONTENT_BLOCKS' => [
149+
'name' => 'Edit content blocks',
150+
'help' => 'Allow editing page content blocks',
151+
'category' => 'Page - Content Blocks',
152+
'sort' => 100
153+
],
154+
'DELETE_CONTENT_BLOCKS' => [
155+
'name' => 'Delete content blocks',
156+
'help' => 'Allow deleting page content blocks',
157+
'category' => 'Page - Content Blocks',
158+
'sort' => 100
159+
]
160+
];
161+
}
162+
163+
public function canView($member = null, $context = [])
164+
{
165+
return Permission::check('VIEW_CONTENT_BLOCKS', 'any', $member);
166+
}
167+
168+
public function canCreate($member = null, $context = [])
169+
{
170+
return Permission::check('CREATE_CONTENT_BLOCKS', 'any', $member);
171+
}
172+
173+
public function canEdit($member = null, $context = [])
174+
{
175+
return Permission::check('EDIT_CONTENT_BLOCKS', 'any', $member);
176+
}
177+
178+
public function canDelete($member = null, $context = [])
179+
{
180+
return Permission::check('DELETE_CONTENT_BLOCKS', 'any', $member);
181+
}
130182
}

0 commit comments

Comments
 (0)