Merge pull request #122 from creative-commoners/pulls/4/review-behat-tests

ENH Extracting logic for canX from Company and Employee
This commit is contained in:
Guy Sartorelli 2022-09-14 12:57:22 +12:00 committed by GitHub
commit da63f28e71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 39 deletions

View File

@ -7,6 +7,13 @@ SilverStripe\ORM\DataObject:
SilverStripe\Assets\File:
extensions:
- BasicFieldsTestFileExtension
SilverStripe\FrameworkTest\Model\Company:
extensions:
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension
SilverStripe\FrameworkTest\Model\Employee:
extensions:
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension
---
Only:

View File

@ -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);
}
}

View 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);
}
}