Add blueprints and fake content

This commit is contained in:
Paul Nicoué 2021-11-18 17:44:47 +01:00
parent 1ff19bf38f
commit 8235816462
592 changed files with 22385 additions and 31535 deletions

View file

@ -7,7 +7,10 @@ return function () {
$allowImpersonation = $this->kirby()->option('api.allowImpersonation') ?? false;
// csrf token check
if ($auth->type($allowImpersonation) === 'session' && $auth->csrf() === false) {
if (
$auth->type($allowImpersonation) === 'session' &&
$auth->csrf() === false
) {
throw new PermissionException('Unauthenticated');
}

View file

@ -1,7 +1,7 @@
<?php
use Kirby\Cms\File;
use Kirby\Cms\Form;
use Kirby\Form\Form;
/**
* File
@ -18,7 +18,7 @@ return [
return $file->dimensions()->toArray();
},
'dragText' => function (File $file) {
return $file->dragText();
return $file->panel()->dragText();
},
'exists' => function (File $file) {
return $file->exists();
@ -33,7 +33,7 @@ return [
return $file->id();
},
'link' => function (File $file) {
return $file->panelUrl(true);
return $file->panel()->url(true);
},
'mime' => function (File $file) {
return $file->mime();
@ -48,7 +48,7 @@ return [
return $file->next();
},
'nextWithTemplate' => function (File $file) {
$files = $file->templateSiblings()->sort('sort', 'asc', 'filename', 'asc');
$files = $file->templateSiblings()->sorted();
$index = $files->indexOf($file);
return $files->nth($index + 1);
@ -57,22 +57,26 @@ return [
return $file->niceSize();
},
'options' => function (File $file) {
return $file->panelOptions();
return $file->panel()->options();
},
'panelIcon' => function (File $file) {
return $file->panelIcon();
// TODO: remove in 3.7.0
// @codeCoverageIgnoreStart
deprecated('The API field file.panelIcon has been deprecated and will be removed in 3.7.0. Use file.panelImage instead');
return $file->panel()->image();
// @codeCoverageIgnoreEnd
},
'panelImage' => function (File $file) {
return $file->panelImage();
return $file->panel()->image();
},
'panelUrl' => function (File $file) {
return $file->panelUrl(true);
return $file->panel()->url(true);
},
'prev' => function (File $file) {
return $file->prev();
},
'prevWithTemplate' => function (File $file) {
$files = $file->templateSiblings()->sort('sort', 'asc', 'filename', 'asc');
$files = $file->templateSiblings()->sorted();
$index = $files->indexOf($file);
return $files->nth($index - 1);
@ -106,7 +110,7 @@ return [
return $file->type();
},
'url' => function (File $file) {
return $file->url(true);
return $file->url();
},
],
'type' => 'Kirby\Cms\File',

View file

@ -41,7 +41,7 @@ return [
return $file->type();
},
'url' => function (FileVersion $file) {
return $file->url(true);
return $file->url();
},
],
'type' => 'Kirby\Cms\FileVersion',

View file

@ -1,7 +1,7 @@
<?php
use Kirby\Cms\Form;
use Kirby\Cms\Page;
use Kirby\Form\Form;
/**
* Page
@ -27,7 +27,7 @@ return [
return $page->errors();
},
'files' => function (Page $page) {
return $page->files()->sort('sort', 'asc', 'filename', 'asc');
return $page->files()->sorted();
},
'hasChildren' => function (Page $page) {
return $page->hasChildren();
@ -44,6 +44,12 @@ return [
'isSortable' => function (Page $page) {
return $page->isSortable();
},
/**
* @deprecated 3.6.0
* @todo Throw deprecated warning in 3.7.0
* @todo Remove in 3.8.0
* @codeCoverageIgnore
*/
'next' => function (Page $page) {
return $page
->nextAll()
@ -56,13 +62,18 @@ return [
return $page->num();
},
'options' => function (Page $page) {
return $page->panelOptions(['preview']);
return $page->panel()->options(['preview']);
},
/**
* @todo Remove in 3.7.0
* @codeCoverageIgnore
*/
'panelIcon' => function (Page $page) {
return $page->panelIcon();
deprecated('The API field page.panelIcon has been deprecated and will be removed in 3.7.0. Use page.panelImage instead');
return $page->panel()->image();
},
'panelImage' => function (Page $page) {
return $page->panelImage();
return $page->panel()->image();
},
'parent' => function (Page $page) {
return $page->parent();
@ -70,6 +81,12 @@ return [
'parents' => function (Page $page) {
return $page->parents()->flip();
},
/**
* @deprecated 3.6.0
* @todo Throw deprecated warning in 3.7.0
* @todo Remove in 3.8.0
* @codeCoverageIgnore
*/
'prev' => function (Page $page) {
return $page
->prevAll()

View file

@ -1,7 +1,7 @@
<?php
use Kirby\Cms\Form;
use Kirby\Cms\Site;
use Kirby\Form\Form;
/**
* Site
@ -24,7 +24,7 @@ return [
return $site->drafts();
},
'files' => function (Site $site) {
return $site->files()->sort('sort', 'asc', 'filename', 'asc');
return $site->files()->sorted();
},
'options' => function (Site $site) {
return $site->permissions()->toArray();

View file

@ -52,12 +52,8 @@ return [
'requirements' => function (System $system) {
return $system->toArray();
},
'site' => function () {
try {
return $this->site()->blueprint()->title();
} catch (Throwable $e) {
return $this->site()->title()->value();
}
'site' => function (System $system) {
return $system->title();
},
'slugs' => function () {
return Str::$language;
@ -87,7 +83,7 @@ return [
'version' => function () {
$user = $this->user();
if ($user && $user->role()->permissions()->for('access', 'settings') === true) {
if ($user && $user->role()->permissions()->for('access', 'system') === true) {
return $this->kirby()->version();
} else {
return null;

View file

@ -1,7 +1,7 @@
<?php
use Kirby\Cms\Form;
use Kirby\Cms\User;
use Kirby\Form\Form;
/**
* User
@ -24,7 +24,7 @@ return [
return $user->email();
},
'files' => function (User $user) {
return $user->files()->sort('sort', 'asc', 'filename', 'asc');
return $user->files()->sorted();
},
'id' => function (User $user) {
return $user->id();
@ -39,7 +39,10 @@ return [
return $user->next();
},
'options' => function (User $user) {
return $user->panelOptions();
return $user->panel()->options();
},
'panelImage' => function (User $user) {
return $user->panel()->image();
},
'permissions' => function (User $user) {
return $user->role()->permissions()->toArray();

View file

@ -1,12 +1,15 @@
<?php
// routing pattern to match all models with files
$pattern = '(account|pages/[^/]+|site|users/[^/]+)';
/**
* Files Routes
*/
return [
[
'pattern' => '(:all)/files/(:any)/sections/(:any)',
'pattern' => $pattern . '/files/(:any)/sections/(:any)',
'method' => 'GET',
'action' => function (string $path, string $filename, string $sectionName) {
if ($section = $this->file($path, $filename)->blueprint()->section($sectionName)) {
@ -15,7 +18,7 @@ return [
}
],
[
'pattern' => '(:all)/files/(:any)/fields/(:any)/(:all?)',
'pattern' => $pattern . '/files/(:any)/fields/(:any)/(:all?)',
'method' => 'ALL',
'action' => function (string $parent, string $filename, string $fieldName, string $path = null) {
if ($file = $this->file($parent, $filename)) {
@ -24,27 +27,33 @@ return [
}
],
[
'pattern' => '(:all)/files',
'pattern' => $pattern . '/files',
'method' => 'GET',
'action' => function (string $path) {
return $this->parent($path)->files()->sort('sort', 'asc', 'filename', 'asc');
return $this->parent($path)->files()->sorted();
}
],
[
'pattern' => '(:all)/files',
'pattern' => $pattern . '/files',
'method' => 'POST',
'action' => function (string $path) {
// move_uploaded_file() not working with unit test
// @codeCoverageIgnoreStart
return $this->upload(function ($source, $filename) use ($path) {
return $this->parent($path)->createFile([
'content' => [
'sort' => $this->requestBody('sort')
],
'source' => $source,
'template' => $this->requestBody('template'),
'filename' => $filename
]);
});
// @codeCoverageIgnoreEnd
}
],
[
'pattern' => '(:all)/files/search',
'pattern' => $pattern . '/files/search',
'method' => 'GET|POST',
'action' => function (string $path) {
$files = $this->parent($path)->files();
@ -57,7 +66,7 @@ return [
}
],
[
'pattern' => '(:all)/files/sort',
'pattern' => $pattern . '/files/sort',
'method' => 'PATCH',
'action' => function (string $path) {
return $this->parent($path)->files()->changeSort(
@ -67,21 +76,21 @@ return [
}
],
[
'pattern' => '(:all)/files/(:any)',
'pattern' => $pattern . '/files/(:any)',
'method' => 'GET',
'action' => function (string $path, string $filename) {
return $this->file($path, $filename);
}
],
[
'pattern' => '(:all)/files/(:any)',
'pattern' => $pattern . '/files/(:any)',
'method' => 'PATCH',
'action' => function (string $path, string $filename) {
return $this->file($path, $filename)->update($this->requestBody(), $this->language(), true);
}
],
[
'pattern' => '(:all)/files/(:any)',
'pattern' => $pattern . '/files/(:any)',
'method' => 'POST',
'action' => function (string $path, string $filename) {
return $this->upload(function ($source) use ($path, $filename) {
@ -90,14 +99,14 @@ return [
}
],
[
'pattern' => '(:all)/files/(:any)',
'pattern' => $pattern . '/files/(:any)',
'method' => 'DELETE',
'action' => function (string $path, string $filename) {
return $this->file($path, $filename)->delete();
}
],
[
'pattern' => '(:all)/files/(:any)/name',
'pattern' => $pattern . '/files/(:any)/name',
'method' => 'PATCH',
'action' => function (string $path, string $filename) {
return $this->file($path, $filename)->changeName($this->requestBody('name'));

View file

@ -1,6 +1,5 @@
<?php
use Kirby\Exception\Exception;
/**
* Content Lock Routes
@ -9,7 +8,13 @@ return [
[
'pattern' => '(:all)/lock',
'method' => 'GET',
/**
* @deprecated 3.6.0
* @todo Remove in 3.7.0
*/
'action' => function (string $path) {
deprecated('The `GET (:all)/lock` API endpoint has been deprecated and will be removed in 3.7.0');
if ($lock = $this->parent($path)->lock()) {
return [
'supported' => true,
@ -30,11 +35,6 @@ return [
if ($lock = $this->parent($path)->lock()) {
return $lock->create();
}
throw new Exception([
'key' => 'lock.notImplemented',
'httpCode' => 501
]);
}
],
[
@ -44,17 +44,19 @@ return [
if ($lock = $this->parent($path)->lock()) {
return $lock->remove();
}
throw new Exception([
'key' => 'lock.notImplemented',
'httpCode' => 501
]);
}
],
[
'pattern' => '(:all)/unlock',
'method' => 'GET',
/**
* @deprecated 3.6.0
* @todo Remove in 3.7.0
*/
'action' => function (string $path) {
deprecated('The `GET (:all)/unlock` API endpoint has been deprecated and will be removed in 3.7.0');
if ($lock = $this->parent($path)->lock()) {
return [
'supported' => true,
@ -75,11 +77,6 @@ return [
if ($lock = $this->parent($path)->lock()) {
return $lock->unlock();
}
throw new Exception([
'key' => 'lock.notImplemented',
'httpCode' => 501
]);
}
],
[
@ -89,11 +86,6 @@ return [
if ($lock = $this->parent($path)->lock()) {
return $lock->resolve();
}
throw new Exception([
'key' => 'lock.notImplemented',
'httpCode' => 501
]);
}
],
];

View file

@ -38,12 +38,17 @@ return [
'pages/(:any)/blueprints',
/**
* @deprecated
* @todo remove in 3.6.0
* @todo remove in 3.7.0
*/
'pages/(:any)/children/blueprints',
],
'method' => 'GET',
'action' => function (string $id) {
// @codeCoverageIgnoreStart
if ($this->route->pattern() === 'pages/([a-zA-Z0-9\.\-_%= \+\@\(\)]+)/children/blueprints') {
deprecated('`GET pages/(:any)/children/blueprints` API endpoint has been deprecated and will be removed in 3.7.0. Use `GET pages/(:any)/blueprints` instead');
}
// @codeCoverageIgnoreEnd
return $this->page($id)->blueprints($this->requestQuery('section'));
}
],

View file

@ -51,12 +51,17 @@ return [
'site/blueprints',
/**
* @deprecated
* @todo remove in 3.6.0
* @todo remove in 3.7.0
*/
'site/children/blueprints',
],
'method' => 'GET',
'action' => function () {
// @codeCoverageIgnoreStart
if ($this->route->pattern() === 'site/children/blueprints') {
deprecated('`GET site/children/blueprints` API endpoint has been deprecated and will be removed in 3.7.0. Use `GET site/blueprints` instead.');
}
// @codeCoverageIgnoreEnd
return $this->site()->blueprints($this->requestQuery('section'));
}
],

View file

@ -1,12 +1,11 @@
<?php
use Kirby\Toolkit\F;
use Kirby\Filesystem\F;
/**
* User Routes
*/
return [
[
'pattern' => 'users',
'method' => 'GET',
@ -33,35 +32,51 @@ return [
}
],
[
'pattern' => 'users/(:any)',
'pattern' => [
'(account)',
'users/(:any)',
],
'method' => 'GET',
'action' => function (string $id) {
return $this->user($id);
}
],
[
'pattern' => 'users/(:any)',
'pattern' => [
'(account)',
'users/(:any)',
],
'method' => 'PATCH',
'action' => function (string $id) {
return $this->user($id)->update($this->requestBody(), $this->language(), true);
}
],
[
'pattern' => 'users/(:any)',
'pattern' => [
'(account)',
'users/(:any)',
],
'method' => 'DELETE',
'action' => function (string $id) {
return $this->user($id)->delete();
}
],
[
'pattern' => 'users/(:any)/avatar',
'pattern' => [
'(account)/avatar',
'users/(:any)/avatar',
],
'method' => 'GET',
'action' => function (string $id) {
return $this->user($id)->avatar();
}
],
// @codeCoverageIgnoreStart
[
'pattern' => 'users/(:any)/avatar',
'pattern' => [
'(account)/avatar',
'users/(:any)/avatar',
],
'method' => 'POST',
'action' => function (string $id) {
if ($avatar = $this->user($id)->avatar()) {
@ -77,79 +92,101 @@ return [
}, $single = true);
}
],
// @codeCoverageIgnoreEnd
[
'pattern' => 'users/(:any)/avatar',
'pattern' => [
'(account)/avatar',
'users/(:any)/avatar',
],
'method' => 'DELETE',
'action' => function (string $id) {
return $this->user($id)->avatar()->delete();
}
],
[
'pattern' => 'users/(:any)/blueprint',
'pattern' => [
'(account)/blueprint',
'users/(:any)/blueprint',
],
'method' => 'GET',
'action' => function (string $id) {
return $this->user($id)->blueprint();
}
],
[
'pattern' => 'users/(:any)/blueprints',
'pattern' => [
'(account)/blueprints',
'users/(:any)/blueprints',
],
'method' => 'GET',
'action' => function (string $id) {
return $this->user($id)->blueprints($this->requestQuery('section'));
}
],
[
'pattern' => 'users/(:any)/email',
'pattern' => [
'(account)/email',
'users/(:any)/email',
],
'method' => 'PATCH',
'action' => function (string $id) {
return $this->user($id)->changeEmail($this->requestBody('email'));
}
],
[
'pattern' => 'users/(:any)/fields/(:any)/(:all?)',
'method' => 'ALL',
'action' => function (string $id, string $fieldName, string $path = null) {
if ($user = $this->user($id)) {
return $this->fieldApi($user, $fieldName, $path);
}
}
],
[
'pattern' => 'users/(:any)/language',
'pattern' => [
'(account)/language',
'users/(:any)/language',
],
'method' => 'PATCH',
'action' => function (string $id) {
return $this->user($id)->changeLanguage($this->requestBody('language'));
}
],
[
'pattern' => 'users/(:any)/name',
'pattern' => [
'(account)/name',
'users/(:any)/name',
],
'method' => 'PATCH',
'action' => function (string $id) {
return $this->user($id)->changeName($this->requestBody('name'));
}
],
[
'pattern' => 'users/(:any)/password',
'pattern' => [
'(account)/password',
'users/(:any)/password',
],
'method' => 'PATCH',
'action' => function (string $id) {
return $this->user($id)->changePassword($this->requestBody('password'));
}
],
[
'pattern' => 'users/(:any)/role',
'pattern' => [
'(account)/role',
'users/(:any)/role',
],
'method' => 'PATCH',
'action' => function (string $id) {
return $this->user($id)->changeRole($this->requestBody('role'));
}
],
[
'pattern' => 'users/(:any)/roles',
'pattern' => [
'(account)/roles',
'users/(:any)/roles',
],
'action' => function (string $id) {
return $this->user($id)->roles();
}
],
[
'pattern' => 'users/(:any)/sections/(:any)',
'pattern' => [
'(account)/sections/(:any)',
'users/(:any)/sections/(:any)',
],
'method' => 'GET',
'action' => function (string $id, string $sectionName) {
if ($section = $this->user($id)->blueprint()->section($sectionName)) {
@ -157,4 +194,14 @@ return [
}
}
],
[
'pattern' => [
'(account)/fields/(:any)/(:all?)',
'users/(:any)/fields/(:any)/(:all?)',
],
'method' => 'ALL',
'action' => function (string $id, string $fieldName, string $path = null) {
return $this->fieldApi($this->user($id), $fieldName, $path);
}
],
];