mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 03:01:43 +09:00
Implement admin scopes
This commit is contained in:
parent
ec6ac82ebd
commit
b17c58f17f
11 changed files with 163 additions and 12 deletions
64
modules/module/models/Permission.php
Normal file
64
modules/module/models/Permission.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Modules\Module\Models;
|
||||
|
||||
#[\AllowDynamicProperties]
|
||||
class Permission
|
||||
{
|
||||
/**
|
||||
* Default properties.
|
||||
*
|
||||
* Note that $is_admin is an alias to $root,
|
||||
* and $is_site_admin is an alias to $manager.
|
||||
*/
|
||||
public $access;
|
||||
public $root;
|
||||
public $manager;
|
||||
public $scopes;
|
||||
|
||||
/**
|
||||
* Alias to $root, kept for backward compatibility only.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public $is_admin;
|
||||
|
||||
/**
|
||||
* Alias to $manager, kept for backward compatibility only.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public $is_site_admin;
|
||||
|
||||
/**
|
||||
* Primary method to determine whether a user is allowed to do something.
|
||||
*
|
||||
* @param string $scope
|
||||
* @return bool
|
||||
*/
|
||||
public function can(string $scope): bool
|
||||
{
|
||||
if (isset($this->{$scope}) && $scope !== 'scopes')
|
||||
{
|
||||
return boolval($this->{$scope});
|
||||
}
|
||||
|
||||
if ($this->manager && $this->scopes && preg_match('/^(\w+):(.+)$/', $scope, $matches))
|
||||
{
|
||||
if ($this->scopes === true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (is_array($this->scopes) && in_array($scope, $this->scopes))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (is_array($this->scopes) && in_array($matches[1] . ':*', $this->scopes))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue