Merge branch '0.4' into 1

This commit is contained in:
Steve Boyd 2022-09-14 10:07:04 +12:00
commit 59d7240b88
3 changed files with 65 additions and 1 deletions

View File

@ -13,6 +13,8 @@ use SilverStripe\Versioned\RecursivePublishable;
use SilverStripe\Versioned\Versioned;
use RelationFieldsTestPage;
use GridFieldTestPage;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
/**
*
@ -31,7 +33,7 @@ use GridFieldTestPage;
* @mixin Versioned
* @mixin RecursivePublishable
*/
class Company extends DataObject
class Company extends DataObject implements PermissionProvider
{
private static $table_name = 'Company';
@ -370,4 +372,41 @@ class Company extends DataObject
{
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);
}
}

View File

@ -14,4 +14,7 @@ class ElementalBehatTestAdmin extends ModelAdmin
private static $managed_models = [
ElementalBehatTestObject::class,
];
private static $required_permission_codes = 'CMS_ACCESS_CMSMain';
}

View File

@ -5,6 +5,7 @@ namespace SilverStripe\FrameworkTest\Elemental\Model;
use SilverStripe\FrameworkTest\Elemental\Admin\ElementalBehatTestAdmin;
use SilverStripe\Control\Controller;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;
class ElementalBehatTestObject extends DataObject
{
@ -23,4 +24,25 @@ class ElementalBehatTestObject extends DataObject
$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);
}
}