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

@@ -1,6 +1,6 @@
<?php
use Kirby\Exception\PermissionException;
use Kirby\Exception\AuthException;
return function () {
$auth = $this->kirby()->auth();
@@ -11,17 +11,17 @@ return function () {
$auth->type($allowImpersonation) === 'session' &&
$auth->csrf() === false
) {
throw new PermissionException('Unauthenticated');
throw new AuthException('Unauthenticated');
}
// get user from session or basic auth
if ($user = $auth->user(null, $allowImpersonation)) {
if ($user->role()->permissions()->for('access', 'panel') === false) {
throw new PermissionException(['key' => 'access.panel']);
throw new AuthException(['key' => 'access.panel']);
}
return $user;
}
throw new PermissionException('Unauthenticated');
throw new AuthException('Unauthenticated');
};

View File

@@ -3,6 +3,14 @@
/**
* Api Collection Definitions
*/
use Kirby\Cms\Files;
use Kirby\Cms\Languages;
use Kirby\Cms\Pages;
use Kirby\Cms\Roles;
use Kirby\Cms\Translations;
use Kirby\Cms\Users;
return [
/**
@@ -10,7 +18,7 @@ return [
*/
'children' => [
'model' => 'page',
'type' => 'Kirby\Cms\Pages',
'type' => Pages::class,
'view' => 'compact'
],
@@ -19,7 +27,7 @@ return [
*/
'files' => [
'model' => 'file',
'type' => 'Kirby\Cms\Files'
'type' => Files::class,
],
/**
@@ -27,7 +35,7 @@ return [
*/
'languages' => [
'model' => 'language',
'type' => 'Kirby\Cms\Languages'
'type' => Languages::class,
],
/**
@@ -35,7 +43,7 @@ return [
*/
'pages' => [
'model' => 'page',
'type' => 'Kirby\Cms\Pages',
'type' => Pages::class,
'view' => 'compact'
],
@@ -44,7 +52,7 @@ return [
*/
'roles' => [
'model' => 'role',
'type' => 'Kirby\Cms\Roles',
'type' => Roles::class,
'view' => 'compact'
],
@@ -53,7 +61,7 @@ return [
*/
'translations' => [
'model' => 'translation',
'type' => 'Kirby\Cms\Translations',
'type' => Translations::class,
'view' => 'compact'
],
@@ -63,7 +71,7 @@ return [
'users' => [
'default' => fn () => $this->users(),
'model' => 'user',
'type' => 'Kirby\Cms\Users',
'type' => Users::class,
'view' => 'compact'
]

View File

@@ -8,6 +8,7 @@ return [
'FileBlueprint' => include __DIR__ . '/models/FileBlueprint.php',
'FileVersion' => include __DIR__ . '/models/FileVersion.php',
'Language' => include __DIR__ . '/models/Language.php',
'License' => include __DIR__ . '/models/License.php',
'Page' => include __DIR__ . '/models/Page.php',
'PageBlueprint' => include __DIR__ . '/models/PageBlueprint.php',
'Role' => include __DIR__ . '/models/Role.php',

View File

@@ -59,7 +59,7 @@ return [
'url' => fn (File $file) => $file->url(),
'uuid' => fn (File $file) => $file->uuid()?->toString()
],
'type' => 'Kirby\Cms\File',
'type' => File::class,
'views' => [
'default' => [
'content',

View File

@@ -12,7 +12,6 @@ return [
'tabs' => fn (FileBlueprint $blueprint) => $blueprint->tabs(),
'title' => fn (FileBlueprint $blueprint) => $blueprint->title(),
],
'type' => 'Kirby\Cms\FileBlueprint',
'views' => [
],
'type' => FileBlueprint::class,
'views' => [],
];

View File

@@ -20,7 +20,7 @@ return [
'type' => fn (FileVersion $file) => $file->type(),
'url' => fn (FileVersion $file) => $file->url(),
],
'type' => 'Kirby\Cms\FileVersion',
'type' => FileVersion::class,
'views' => [
'default' => [
'dimensions',

View File

@@ -15,7 +15,7 @@ return [
'rules' => fn (Language $language) => $language->rules(),
'url' => fn (Language $language) => $language->url(),
],
'type' => 'Kirby\Cms\Language',
'type' => Language::class,
'views' => [
'default' => [
'code',

View File

@@ -0,0 +1,17 @@
<?php
use Kirby\Cms\License;
/**
* Page
*/
return [
'fields' => [
'status' => fn (License $license) => $license->status()->value(),
'code' => function (License $license) {
return $this->kirby()->user()->isAdmin() ? $license->code() : $license->code(true);
},
'type' => fn (License $license) => $license->type()->label(),
],
'type' => License::class,
];

View File

@@ -40,7 +40,7 @@ return [
'url' => fn (Page $page) => $page->url(),
'uuid' => fn (Page $page) => $page->uuid()?->toString()
],
'type' => 'Kirby\Cms\Page',
'type' => Page::class,
'views' => [
'compact' => [
'id',

View File

@@ -15,7 +15,6 @@ return [
'tabs' => fn (PageBlueprint $blueprint) => $blueprint->tabs(),
'title' => fn (PageBlueprint $blueprint) => $blueprint->title(),
],
'type' => 'Kirby\Cms\PageBlueprint',
'views' => [
],
'type' => PageBlueprint::class,
'views' => [],
];

View File

@@ -12,7 +12,7 @@ return [
'permissions' => fn (Role $role) => $role->permissions()->toArray(),
'title' => fn (Role $role) => $role->title(),
],
'type' => 'Kirby\Cms\Role',
'type' => Role::class,
'views' => [
'compact' => [
'description',

View File

@@ -19,7 +19,7 @@ return [
'title' => fn (Site $site) => $site->title()->value(),
'url' => fn (Site $site) => $site->url(),
],
'type' => 'Kirby\Cms\Site',
'type' => Site::class,
'views' => [
'compact' => [
'title',

View File

@@ -12,6 +12,6 @@ return [
'tabs' => fn (SiteBlueprint $blueprint) => $blueprint->tabs(),
'title' => fn (SiteBlueprint $blueprint) => $blueprint->title(),
],
'type' => 'Kirby\Cms\SiteBlueprint',
'type' => SiteBlueprint::class,
'views' => [],
];

View File

@@ -49,7 +49,7 @@ return [
return null;
}
],
'type' => 'Kirby\Cms\System',
'type' => System::class,
'views' => [
'login' => [
'authStatus',

View File

@@ -13,7 +13,7 @@ return [
'id' => fn (Translation $translation) => $translation->id(),
'name' => fn (Translation $translation) => $translation->name(),
],
'type' => 'Kirby\Cms\Translation',
'type' => Translation::class,
'views' => [
'compact' => [
'direction',

View File

@@ -27,7 +27,7 @@ return [
'username' => fn (User $user) => $user->username(),
'uuid' => fn (User $user) => $user->uuid()?->toString()
],
'type' => 'Kirby\Cms\User',
'type' => User::class,
'views' => [
'default' => [
'avatar',

View File

@@ -12,7 +12,6 @@ return [
'tabs' => fn (UserBlueprint $blueprint) => $blueprint->tabs(),
'title' => fn (UserBlueprint $blueprint) => $blueprint->title(),
],
'type' => 'Kirby\Cms\UserBlueprint',
'views' => [
],
'type' => UserBlueprint::class,
'views' => [],
];

View File

@@ -19,7 +19,10 @@ return function ($kirby) {
// only add the language routes if the
// multi language setup is activated
if ($kirby->option('languages', false) !== false) {
$routes = array_merge($routes, include __DIR__ . '/routes/languages.php');
$routes = array_merge(
$routes,
include __DIR__ . '/routes/languages.php'
);
}
return $routes;

View File

@@ -1,7 +1,8 @@
<?php
// routing pattern to match all models with files
$pattern = '(account|pages/[^/]+|site|users/[^/]+)';
$filePattern = '(account/|pages/[^/]+/|site/|users/[^/]+/|)files/(:any)';
$parentPattern = '(account|pages/[^/]+|site|users/[^/]+)/files';
/**
* Files Routes
@@ -9,14 +10,14 @@ $pattern = '(account|pages/[^/]+|site|users/[^/]+)';
return [
[
'pattern' => $pattern . '/files/(:any)/sections/(:any)',
'pattern' => $filePattern . '/sections/(:any)',
'method' => 'GET',
'action' => function (string $path, string $filename, string $sectionName) {
return $this->file($path, $filename)->blueprint()->section($sectionName)?->toResponse();
}
],
[
'pattern' => $pattern . '/files/(:any)/fields/(:any)/(:all?)',
'pattern' => $filePattern . '/fields/(:any)/(:all?)',
'method' => 'ALL',
'action' => function (string $parent, string $filename, string $fieldName, string $path = null) {
if ($file = $this->file($parent, $filename)) {
@@ -25,14 +26,14 @@ return [
}
],
[
'pattern' => $pattern . '/files',
'pattern' => $parentPattern,
'method' => 'GET',
'action' => function (string $path) {
return $this->parent($path)->files()->sorted();
return $this->files($path)->sorted();
}
],
[
'pattern' => $pattern . '/files',
'pattern' => $parentPattern,
'method' => 'POST',
'action' => function (string $path) {
// move_uploaded_file() not working with unit test
@@ -54,10 +55,10 @@ return [
}
],
[
'pattern' => $pattern . '/files/search',
'pattern' => $parentPattern . '/search',
'method' => 'GET|POST',
'action' => function (string $path) {
$files = $this->parent($path)->files();
$files = $this->files($path);
if ($this->requestMethod() === 'GET') {
return $files->search($this->requestQuery('q'));
@@ -67,24 +68,24 @@ return [
}
],
[
'pattern' => $pattern . '/files/sort',
'pattern' => $parentPattern . '/sort',
'method' => 'PATCH',
'action' => function (string $path) {
return $this->parent($path)->files()->changeSort(
return $this->files($path)->changeSort(
$this->requestBody('files'),
$this->requestBody('index')
);
}
],
[
'pattern' => $pattern . '/files/(:any)',
'pattern' => $filePattern,
'method' => 'GET',
'action' => function (string $path, string $filename) {
return $this->file($path, $filename);
}
],
[
'pattern' => $pattern . '/files/(:any)',
'pattern' => $filePattern,
'method' => 'PATCH',
'action' => function (string $path, string $filename) {
return $this->file($path, $filename)->update(
@@ -95,7 +96,7 @@ return [
}
],
[
'pattern' => $pattern . '/files/(:any)',
'pattern' => $filePattern,
'method' => 'POST',
'action' => function (string $path, string $filename) {
// move the source file from the temp dir
@@ -105,28 +106,29 @@ return [
}
],
[
'pattern' => $pattern . '/files/(:any)',
'pattern' => $filePattern,
'method' => 'DELETE',
'action' => function (string $path, string $filename) {
return $this->file($path, $filename)->delete();
}
],
[
'pattern' => $pattern . '/files/(:any)/name',
'pattern' => $filePattern . '/name',
'method' => 'PATCH',
'action' => function (string $path, string $filename) {
return $this->file($path, $filename)->changeName($this->requestBody('name'));
}
],
[
'pattern' => 'files/search',
'pattern' => $parentPattern . '/search',
'method' => 'GET|POST',
'action' => function () {
$files = $this
->site()
->index(true)
->filter('isReadable', true)
->files();
->filter('isListable', true)
->files()
->filter('isListable', true);
if ($this->requestMethod() === 'GET') {
return $files->search($this->requestQuery('q'));

View File

@@ -0,0 +1,35 @@
<?php
// @codeCoverageIgnoreStart
return [
'routes' => function ($kirby) {
return [
[
'pattern' => 'query',
'method' => 'POST|GET',
'auth' => $kirby->option('kql.auth') !== false,
'action' => function () use ($kirby) {
$kql = '\Kirby\Kql\Kql';
if (class_exists($kql) === false) {
return [
'code' => 500,
'status' => 'error',
'message' => 'KQL plugin is not installed',
];
}
$input = $kirby->request()->get();
$result = $kql::run($input);
return [
'code' => 200,
'result' => $result,
'status' => 'ok',
];
}
]
];
}
];
// @codeCoverageIgnoreEnd

View File

@@ -4,8 +4,9 @@
/**
* Page Routes
*/
return [
return [
[
'pattern' => 'pages/(:any)',
'method' => 'GET',

View File

@@ -75,7 +75,7 @@ return [
$pages = $this
->site()
->index(true)
->filter('isReadable', true);
->filter('isListable', true);
if ($this->requestMethod() === 'GET') {
return $pages->search($this->requestQuery('q'));