Skip to content

Commit

Permalink
Merge pull request #120 from creative-commoners/pulls/4/review-behat-…
Browse files Browse the repository at this point in the history
…tests

ENH Add permissions for Content Editor
  • Loading branch information
GuySartorelli authored Sep 6, 2022
2 parents cd4c310 + 69fcc2f commit dbf6dfe
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
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' => [
'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);
}

}

0 comments on commit dbf6dfe

Please sign in to comment.