diff --git a/kirby/composer.json b/kirby/composer.json index e07bdeb..f722f9c 100755 --- a/kirby/composer.json +++ b/kirby/composer.json @@ -1,7 +1,7 @@ { "name": "getkirby/cms", "description": "The Kirby 3 core", - "version": "3.2.1", + "version": "3.2.2", "license": "proprietary", "keywords": ["kirby", "cms", "core"], "homepage": "https://getkirby.com", diff --git a/kirby/src/Cms/Api.php b/kirby/src/Cms/Api.php index 9f4caee..f1489b6 100755 --- a/kirby/src/Cms/Api.php +++ b/kirby/src/Cms/Api.php @@ -118,35 +118,43 @@ class Api extends BaseApi */ public function parent(string $path) { - $modelType = $path === 'site' ? 'site' : trim(dirname($path), '/'); - $modelTypes = ['site' => 'site', 'users' => 'user', 'pages' => 'page']; - $modelName = $modelTypes[$modelType] ?? null; + $modelType = in_array($path, ['site', 'account']) ? $path : trim(dirname($path), '/'); + $modelTypes = [ + 'site' => 'site', + 'users' => 'user', + 'pages' => 'page', + 'account' => 'account' + ]; + $modelName = $modelTypes[$modelType] ?? null; if (Str::endsWith($modelType, '/files') === true) { $modelName = 'file'; } - if ($modelName === null) { - throw new InvalidArgumentException('Invalid file model type'); + $kirby = $this->kirby(); + + switch ($modelName) { + case 'site': + $model = $kirby->site(); + break; + case 'account': + $model = $kirby->user(); + break; + case 'page': + $id = str_replace(['+', ' '], '/', basename($path)); + $model = $kirby->page($id); + break; + case 'file': + $model = $this->file(...explode('/files/', $path)); + break; + case 'user': + $model = $kirby->user(basename($path)); + break; + default: + throw new InvalidArgumentException('Invalid file model type: ' . $modelType); } - if ($modelName === 'site') { - $modelId = null; - } else { - $modelId = basename($path); - - if ($modelName === 'page') { - $modelId = str_replace(['+', ' '], '/', $modelId); - } - - if ($modelName === 'file') { - if ($model = $this->file(...explode('/files/', $path))) { - return $model; - } - } - } - - if ($model = $this->kirby()->$modelName($modelId)) { + if ($model) { return $model; } diff --git a/kirby/src/Cms/UserRules.php b/kirby/src/Cms/UserRules.php index d62f09a..d142176 100755 --- a/kirby/src/Cms/UserRules.php +++ b/kirby/src/Cms/UserRules.php @@ -105,7 +105,10 @@ class UserRules // only admins are allowed to add admins $role = $props['role'] ?? null; - if ($role === 'admin' && $user->kirby()->user()->isAdmin() === false) { + // get the current user if it exists + $currentUser = $user->kirby()->user(); + + if ($role === 'admin' && $currentUser && $currentUser->isAdmin() === false) { throw new PermissionException([ 'key' => 'user.create.permission' ]);