Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Add permissions for Content Editor #120

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion code/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use SilverStripe\Versioned\Versioned;
use RelationFieldsTestPage;
use GridFieldTestPage;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;

/**
*
Expand All @@ -31,7 +33,7 @@
* @mixin Versioned
* @mixin RecursivePublishable
*/
class Company extends DataObject
class Company extends DataObject implements PermissionProvider
{
private static $table_name = 'Company';

Expand Down Expand Up @@ -370,4 +372,41 @@ public function scaffoldSearchField()
{
return DropdownField::create('CompanyID', 'Company', self::get()->map())->setEmptyString('');
}

public function providePermissions()
{
return [
'COMPANY_EDIT' => [
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
'name' => _t(
__CLASS__ . '.EditPermissionLabel',
'Edit a company'
),
'category' => _t(
__CLASS__ . '.Category',
'Company'
),
],
];
}

public function canView($member = null)
{
return Permission::check('COMPANY_EDIT', 'any', $member);
}

public function canEdit($member = null)
{
return Permission::check('COMPANY_EDIT', 'any', $member);
}

public function canDelete($member = null)
{
return Permission::check('COMPANY_EDIT', 'any', $member);
}

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

}
3 changes: 3 additions & 0 deletions code/elemental/ElementalBehatTestAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ class ElementalBehatTestAdmin extends ModelAdmin
private static $managed_models = [
ElementalBehatTestObject::class,
];

private static $required_permission_codes = 'CMS_ACCESS_CMSMain';

}
22 changes: 22 additions & 0 deletions code/elemental/ElementalBehatTestObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\FrameworkTest\Elemental\Admin\ElementalBehatTestAdmin;
use SilverStripe\Control\Controller;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;

class ElementalBehatTestObject extends DataObject
{
Expand All @@ -23,4 +24,25 @@ public function CMSEditLink()
$this->ID,
);
}

public function canView($member = null)
{
return Permission::check(ElementalBehatTestAdmin::getRequiredPermissions() , 'any', $member);
}

public function canEdit($member = null)
{
return Permission::check(ElementalBehatTestAdmin::getRequiredPermissions(), 'any', $member);
}

public function canDelete($member = null)
{
return Permission::check(ElementalBehatTestAdmin::getRequiredPermissions(), 'any', $member);
}

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

}