2017-05-11 11:07:27 +02:00
|
|
|
<?php
|
|
|
|
|
2017-09-27 17:43:01 +02:00
|
|
|
namespace SilverStripe\Security\Tests\InheritedPermissionsTest;
|
2017-05-11 11:07:27 +02:00
|
|
|
|
|
|
|
use SilverStripe\Core\Injector\Injector;
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
use SilverStripe\Security\InheritedPermissions;
|
|
|
|
use SilverStripe\Security\InheritedPermissionsExtension;
|
|
|
|
use SilverStripe\Security\PermissionChecker;
|
2017-05-20 06:32:25 +02:00
|
|
|
use SilverStripe\Security\Security;
|
2017-05-11 11:07:27 +02:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @method TestPermissionNode Parent()
|
|
|
|
* @mixin Versioned
|
|
|
|
* @mixin InheritedPermissionsExtension
|
|
|
|
*/
|
|
|
|
class TestPermissionNode extends DataObject implements TestOnly
|
|
|
|
{
|
|
|
|
private static $db = [
|
|
|
|
"Title" => "Varchar(255)",
|
|
|
|
];
|
|
|
|
|
|
|
|
private static $has_one = [
|
|
|
|
"Parent" => self::class,
|
|
|
|
];
|
|
|
|
|
|
|
|
private static $table_name = 'InheritedPermissionsTest_TestPermissionNode';
|
|
|
|
|
|
|
|
private static $extensions = [
|
|
|
|
Versioned::class,
|
|
|
|
InheritedPermissionsExtension::class,
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return InheritedPermissions
|
|
|
|
*/
|
|
|
|
public static function getInheritedPermissions()
|
|
|
|
{
|
|
|
|
/** @var InheritedPermissions $permissions */
|
2018-01-16 19:39:30 +01:00
|
|
|
return Injector::inst()->get(PermissionChecker::class . '.testpermissions');
|
2017-05-11 11:07:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function canEdit($member = null)
|
|
|
|
{
|
|
|
|
if (!$member) {
|
2017-05-20 06:32:25 +02:00
|
|
|
$member = Security::getCurrentUser();
|
2017-05-11 11:07:27 +02:00
|
|
|
}
|
|
|
|
return static::getInheritedPermissions()->canEdit($this->ID, $member);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function canView($member = null)
|
|
|
|
{
|
|
|
|
if (!$member) {
|
2017-05-20 06:32:25 +02:00
|
|
|
$member = Security::getCurrentUser();
|
2017-05-11 11:07:27 +02:00
|
|
|
}
|
|
|
|
return static::getInheritedPermissions()->canView($this->ID, $member);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function canDelete($member = null)
|
|
|
|
{
|
|
|
|
if (!$member) {
|
2017-05-20 06:32:25 +02:00
|
|
|
$member = Security::getCurrentUser();
|
2017-05-11 11:07:27 +02:00
|
|
|
}
|
|
|
|
return static::getInheritedPermissions()->canDelete($this->ID, $member);
|
|
|
|
}
|
|
|
|
}
|