Upgrade to 3.2.0
This commit is contained in:
@@ -2,6 +2,17 @@
|
||||
|
||||
namespace Kirby\Cms;
|
||||
|
||||
use Kirby\Toolkit\A;
|
||||
|
||||
/**
|
||||
* ModelPermissions
|
||||
*
|
||||
* @package Kirby Cms
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://getkirby.com/license
|
||||
*/
|
||||
abstract class ModelPermissions
|
||||
{
|
||||
protected $category;
|
||||
@@ -10,7 +21,7 @@ abstract class ModelPermissions
|
||||
protected $permissions;
|
||||
protected $user;
|
||||
|
||||
public function __call(string $method, array $arguments = [])
|
||||
public function __call(string $method, array $arguments = []): bool
|
||||
{
|
||||
return $this->can($method);
|
||||
}
|
||||
@@ -24,7 +35,7 @@ abstract class ModelPermissions
|
||||
}
|
||||
|
||||
/**
|
||||
* Improved var_dump output
|
||||
* Improved `var_dump` output
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -35,16 +46,32 @@ abstract class ModelPermissions
|
||||
|
||||
public function can(string $action): bool
|
||||
{
|
||||
if ($this->user->role()->id() === 'nobody') {
|
||||
$role = $this->user->role()->id();
|
||||
|
||||
if ($role === 'nobody') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check for a custom overall can method
|
||||
if (method_exists($this, 'can' . $action) === true && $this->{'can' . $action}() === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->options[$action]) === true && $this->options[$action] === false) {
|
||||
return false;
|
||||
// evaluate the blueprint options block
|
||||
if (isset($this->options[$action]) === true) {
|
||||
$options = $this->options[$action];
|
||||
|
||||
if ($options === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($options === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_array($options) === true && A::isAssociative($options) === true) {
|
||||
return $options[$role] ?? $options['*'] ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->permissions->for($this->category, $action);
|
||||
|
||||
Reference in New Issue
Block a user