Upgrade to 3.2.2

This commit is contained in:
Bastian Allgeier
2019-07-10 16:19:10 +02:00
parent 2744985432
commit 40f095f5de
3 changed files with 35 additions and 24 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "getkirby/cms", "name": "getkirby/cms",
"description": "The Kirby 3 core", "description": "The Kirby 3 core",
"version": "3.2.1", "version": "3.2.2",
"license": "proprietary", "license": "proprietary",
"keywords": ["kirby", "cms", "core"], "keywords": ["kirby", "cms", "core"],
"homepage": "https://getkirby.com", "homepage": "https://getkirby.com",

View File

@@ -118,35 +118,43 @@ class Api extends BaseApi
*/ */
public function parent(string $path) public function parent(string $path)
{ {
$modelType = $path === 'site' ? 'site' : trim(dirname($path), '/'); $modelType = in_array($path, ['site', 'account']) ? $path : trim(dirname($path), '/');
$modelTypes = ['site' => 'site', 'users' => 'user', 'pages' => 'page']; $modelTypes = [
$modelName = $modelTypes[$modelType] ?? null; 'site' => 'site',
'users' => 'user',
'pages' => 'page',
'account' => 'account'
];
$modelName = $modelTypes[$modelType] ?? null;
if (Str::endsWith($modelType, '/files') === true) { if (Str::endsWith($modelType, '/files') === true) {
$modelName = 'file'; $modelName = 'file';
} }
if ($modelName === null) { $kirby = $this->kirby();
throw new InvalidArgumentException('Invalid file model type');
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') { if ($model) {
$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)) {
return $model; return $model;
} }

View File

@@ -105,7 +105,10 @@ class UserRules
// only admins are allowed to add admins // only admins are allowed to add admins
$role = $props['role'] ?? null; $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([ throw new PermissionException([
'key' => 'user.create.permission' 'key' => 'user.create.permission'
]); ]);