Upgrade to 4.0.0

This commit is contained in:
Bastian Allgeier
2023-11-28 09:33:56 +01:00
parent f96b96af76
commit 3b0b6546ca
480 changed files with 21371 additions and 13327 deletions

View File

@@ -17,15 +17,9 @@ use Kirby\Exception\InvalidArgumentException;
*/
class Permissions
{
/**
* @var array
*/
public static $extendedActions = [];
public static array $extendedActions = [];
/**
* @var array
*/
protected $actions = [
protected array $actions = [
'access' => [
'account' => true,
'languages' => true,
@@ -35,18 +29,22 @@ class Permissions
'users' => true,
],
'files' => [
'changeName' => true,
'create' => true,
'delete' => true,
'read' => true,
'replace' => true,
'update' => true
'access' => true,
'changeName' => true,
'changeTemplate' => true,
'create' => true,
'delete' => true,
'list' => true,
'read' => true,
'replace' => true,
'update' => true
],
'languages' => [
'create' => true,
'delete' => true
],
'pages' => [
'access' => true,
'changeSlug' => true,
'changeStatus' => true,
'changeTemplate' => true,
@@ -54,6 +52,8 @@ class Permissions
'create' => true,
'delete' => true,
'duplicate' => true,
'list' => true,
'move' => true,
'preview' => true,
'read' => true,
'sort' => true,
@@ -87,10 +87,9 @@ class Permissions
/**
* Permissions constructor
*
* @param array $settings
* @throws \Kirby\Exception\InvalidArgumentException
*/
public function __construct($settings = [])
public function __construct(array|bool|null $settings = [])
{
// dynamically register the extended actions
foreach (static::$extendedActions as $key => $actions) {
@@ -110,11 +109,6 @@ class Permissions
}
}
/**
* @param string|null $category
* @param string|null $action
* @return bool
*/
public function for(string $category = null, string $action = null): bool
{
if ($action === null) {
@@ -132,33 +126,26 @@ class Permissions
return $this->actions[$category][$action];
}
/**
* @param string $category
* @param string $action
* @return bool
*/
protected function hasAction(string $category, string $action): bool
{
return $this->hasCategory($category) === true && array_key_exists($action, $this->actions[$category]) === true;
return
$this->hasCategory($category) === true &&
array_key_exists($action, $this->actions[$category]) === true;
}
/**
* @param string $category
* @return bool
*/
protected function hasCategory(string $category): bool
{
return array_key_exists($category, $this->actions) === true;
}
/**
* @param string $category
* @param string $action
* @param $setting
* @return $this
*/
protected function setAction(string $category, string $action, $setting)
{
protected function setAction(
string $category,
string $action,
$setting
): static {
// wildcard to overwrite the entire category
if ($action === '*') {
return $this->setCategory($category, $setting);
@@ -170,10 +157,9 @@ class Permissions
}
/**
* @param bool $setting
* @return $this
*/
protected function setAll(bool $setting)
protected function setAll(bool $setting): static
{
foreach ($this->actions as $categoryName => $actions) {
$this->setCategory($categoryName, $setting);
@@ -183,10 +169,9 @@ class Permissions
}
/**
* @param array $settings
* @return $this
*/
protected function setCategories(array $settings)
protected function setCategories(array $settings): static
{
foreach ($settings as $categoryName => $categoryActions) {
if (is_bool($categoryActions) === true) {
@@ -204,12 +189,10 @@ class Permissions
}
/**
* @param string $category
* @param bool $setting
* @return $this
* @throws \Kirby\Exception\InvalidArgumentException
*/
protected function setCategory(string $category, bool $setting)
protected function setCategory(string $category, bool $setting): static
{
if ($this->hasCategory($category) === false) {
throw new InvalidArgumentException('Invalid permissions category');
@@ -222,9 +205,6 @@ class Permissions
return $this;
}
/**
* @return array
*/
public function toArray(): array
{
return $this->actions;