mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
ENH Extracting logic for canX from Company and Employee into DataObject Extension
This commit is contained in:
parent
69fcc2f1bf
commit
8b9a80ecbb
@ -8,6 +8,13 @@ SilverStripe\Assets\File:
|
||||
extensions:
|
||||
- BasicFieldsTestFileExtension
|
||||
|
||||
SilverStripe\FrameworkTest\Model\Company:
|
||||
extensions:
|
||||
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension
|
||||
SilverStripe\FrameworkTest\Model\Employee:
|
||||
extensions:
|
||||
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension
|
||||
|
||||
---
|
||||
Only:
|
||||
moduleexists: 'dnadesign/silverstripe-elemental'
|
||||
|
@ -13,8 +13,6 @@ use SilverStripe\Versioned\RecursivePublishable;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use RelationFieldsTestPage;
|
||||
use GridFieldTestPage;
|
||||
use SilverStripe\Security\Permission;
|
||||
use SilverStripe\Security\PermissionProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -33,7 +31,7 @@ use SilverStripe\Security\PermissionProvider;
|
||||
* @mixin Versioned
|
||||
* @mixin RecursivePublishable
|
||||
*/
|
||||
class Company extends DataObject implements PermissionProvider
|
||||
class Company extends DataObject
|
||||
{
|
||||
private static $table_name = 'Company';
|
||||
|
||||
@ -373,40 +371,4 @@ class Company extends DataObject implements PermissionProvider
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
46
code/TestDataObjectExtension.php
Normal file
46
code/TestDataObjectExtension.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\FrameworkTest\Extension;
|
||||
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
use SilverStripe\Security\Permission;
|
||||
use SilverStripe\Security\PermissionProvider;
|
||||
|
||||
class TestDataObjectExtension extends DataExtension implements PermissionProvider
|
||||
{
|
||||
public function providePermissions()
|
||||
{
|
||||
return [
|
||||
'TEST_DATAOBJECT_EDIT' => [
|
||||
'name' => _t(
|
||||
__CLASS__ . '.EditPermissionLabel',
|
||||
'Manage a test object'
|
||||
),
|
||||
'category' => _t(
|
||||
__CLASS__ . '.Category',
|
||||
'Test Data Object'
|
||||
),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function canView($member = null)
|
||||
{
|
||||
return Permission::check('TEST_DATAOBJECT_EDIT', 'any', $member);
|
||||
}
|
||||
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
return Permission::check('TEST_DATAOBJECT_EDIT', 'any', $member);
|
||||
}
|
||||
|
||||
public function canDelete($member = null)
|
||||
{
|
||||
return Permission::check('TEST_DATAOBJECT_EDIT', 'any', $member);
|
||||
}
|
||||
|
||||
public function canCreate($member = null, $context = [])
|
||||
{
|
||||
return Permission::check('TEST_DATAOBJECT_EDIT', 'any', $member);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user