2009-10-16 00:27:56 +02:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2016-06-23 01:37:22 +02:00
|
|
|
namespace SilverStripe\Security;
|
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2017-02-04 20:41:31 +01:00
|
|
|
use SilverStripe\Security\PermissionRole;
|
2016-06-23 01:37:22 +02:00
|
|
|
|
2009-10-16 00:27:56 +02:00
|
|
|
/**
|
|
|
|
* A PermissionRoleCode represents a single permission code assigned to a {@link PermissionRole}.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2014-01-26 04:17:17 +01:00
|
|
|
* @property string Code
|
|
|
|
* @property int RoleID
|
|
|
|
* @method PermissionRole Role()
|
2009-10-16 00:27:56 +02:00
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
class PermissionRoleCode extends DataObject
|
|
|
|
{
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $db = [
|
2016-11-23 06:09:10 +01:00
|
|
|
"Code" => "Varchar",
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $has_one = [
|
2017-02-04 20:41:31 +01:00
|
|
|
"Role" => PermissionRole::class,
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2016-11-23 06:09:10 +01:00
|
|
|
private static $table_name = "PermissionRoleCode";
|
2022-01-04 21:40:12 +01:00
|
|
|
|
|
|
|
private static $indexes = [
|
|
|
|
"Code" => true,
|
|
|
|
];
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
public function validate()
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
$result = parent::validate();
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2016-11-23 06:09:10 +01:00
|
|
|
// Check that new code doesn't increase privileges, unless an admin is editing.
|
|
|
|
$privilegedCodes = Permission::config()->privileged_permissions;
|
2016-11-29 00:31:16 +01:00
|
|
|
if ($this->Code
|
2016-11-23 06:09:10 +01:00
|
|
|
&& in_array($this->Code, $privilegedCodes)
|
|
|
|
&& !Permission::check('ADMIN')
|
|
|
|
) {
|
2017-02-04 20:41:31 +01:00
|
|
|
$result->addError(
|
2016-11-23 06:09:10 +01:00
|
|
|
_t(
|
2017-02-04 20:41:31 +01:00
|
|
|
__CLASS__ . '.PermsError',
|
|
|
|
'Can\'t assign code "{code}" with privileged permissions (requires ADMIN access)',
|
|
|
|
['code' => $this->Code]
|
|
|
|
)
|
|
|
|
);
|
2016-11-23 06:09:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
public function canCreate($member = null, $context = [])
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
return Permission::check('APPLY_ROLES', 'any', $member);
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
public function canEdit($member = null)
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
return Permission::check('APPLY_ROLES', 'any', $member);
|
|
|
|
}
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
public function canDelete($member = null)
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
return Permission::check('APPLY_ROLES', 'any', $member);
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|