Update Kirby and dependencies

This commit is contained in:
Paul Nicoué 2022-08-31 15:02:43 +02:00
parent 503b339974
commit 399fa20902
439 changed files with 66915 additions and 64442 deletions

View file

@ -15,102 +15,102 @@ use Kirby\Toolkit\A;
*/
abstract class ModelPermissions
{
protected $category;
protected $model;
protected $options;
protected $permissions;
protected $user;
protected $category;
protected $model;
protected $options;
protected $permissions;
protected $user;
/**
* @param string $method
* @param array $arguments
* @return bool
*/
public function __call(string $method, array $arguments = []): bool
{
return $this->can($method);
}
/**
* @param string $method
* @param array $arguments
* @return bool
*/
public function __call(string $method, array $arguments = []): bool
{
return $this->can($method);
}
/**
* ModelPermissions constructor
*
* @param \Kirby\Cms\Model $model
*/
public function __construct(Model $model)
{
$this->model = $model;
$this->options = $model->blueprint()->options();
$this->user = $model->kirby()->user() ?? User::nobody();
$this->permissions = $this->user->role()->permissions();
}
/**
* ModelPermissions constructor
*
* @param \Kirby\Cms\Model $model
*/
public function __construct(Model $model)
{
$this->model = $model;
$this->options = $model->blueprint()->options();
$this->user = $model->kirby()->user() ?? User::nobody();
$this->permissions = $this->user->role()->permissions();
}
/**
* Improved `var_dump` output
*
* @return array
*/
public function __debugInfo(): array
{
return $this->toArray();
}
/**
* Improved `var_dump` output
*
* @return array
*/
public function __debugInfo(): array
{
return $this->toArray();
}
/**
* @param string $action
* @return bool
*/
public function can(string $action): bool
{
$role = $this->user->role()->id();
/**
* @param string $action
* @return bool
*/
public function can(string $action): bool
{
$role = $this->user->role()->id();
if ($role === 'nobody') {
return false;
}
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;
}
// check for a custom overall can method
if (method_exists($this, 'can' . $action) === true && $this->{'can' . $action}() === false) {
return false;
}
// evaluate the blueprint options block
if (isset($this->options[$action]) === true) {
$options = $this->options[$action];
// evaluate the blueprint options block
if (isset($this->options[$action]) === true) {
$options = $this->options[$action];
if ($options === false) {
return false;
}
if ($options === false) {
return false;
}
if ($options === true) {
return true;
}
if ($options === true) {
return true;
}
if (is_array($options) === true && A::isAssociative($options) === true) {
return $options[$role] ?? $options['*'] ?? false;
}
}
if (is_array($options) === true && A::isAssociative($options) === true) {
return $options[$role] ?? $options['*'] ?? false;
}
}
return $this->permissions->for($this->category, $action);
}
return $this->permissions->for($this->category, $action);
}
/**
* @param string $action
* @return bool
*/
public function cannot(string $action): bool
{
return $this->can($action) === false;
}
/**
* @param string $action
* @return bool
*/
public function cannot(string $action): bool
{
return $this->can($action) === false;
}
/**
* @return array
*/
public function toArray(): array
{
$array = [];
/**
* @return array
*/
public function toArray(): array
{
$array = [];
foreach ($this->options as $key => $value) {
$array[$key] = $this->can($key);
}
foreach ($this->options as $key => $value) {
$array[$key] = $this->can($key);
}
return $array;
}
return $array;
}
}