diff --git a/composer.json b/composer.json index 6601f365f..88f784e35 100644 --- a/composer.json +++ b/composer.json @@ -62,7 +62,7 @@ }, "scripts": { "test": "vendor/bin/pest --parallel", - "typescript:generate": "php demo/artisan ziggy:generate --types-only; php demo/artisan typescript:transform", + "typescript:generate": "php demo/artisan sharp:typescript-generate", "post-autoload-dump": [ "git config core.hooksPath scripts/hooks" ] diff --git a/resources/js/filters/components/filters/AutocompleteRemoteFilter.vue b/resources/js/filters/components/filters/AutocompleteRemoteFilter.vue index 8722d14eb..8e21b0a0a 100644 --- a/resources/js/filters/components/filters/AutocompleteRemoteFilter.vue +++ b/resources/js/filters/components/filters/AutocompleteRemoteFilter.vue @@ -34,7 +34,7 @@ api.post( route('code16.sharp.api.filters.autocomplete.index', { entityKey: props.entityKey, - filterKey: props.filter.key, + filterHandlerKey: props.filter.key, query, }), {}, diff --git a/resources/js/types/routes.d.ts b/resources/js/types/routes.d.ts index 6f331755c..8df621c42 100644 --- a/resources/js/types/routes.d.ts +++ b/resources/js/types/routes.d.ts @@ -1,11 +1,14 @@ /* This file is generated by Ziggy. */ declare module 'ziggy-js' { interface RouteList { - "code16.sharp.home": [], + "code16.sharp.home": [ + { + "name": "filterKey" + } + ], "code16.sharp.dashboard": [ { - "name": "filterKey", - "required": true + "name": "filterKey" }, { "name": "dashboardKey", @@ -14,6 +17,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.dashboard.filters.store": [ + { + "name": "filterKey" + }, { "name": "dashboardKey", "required": true @@ -21,8 +27,7 @@ declare module 'ziggy-js' { ], "code16.sharp.list": [ { - "name": "filterKey", - "required": true + "name": "filterKey" }, { "name": "entityKey", @@ -31,6 +36,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.list.filters.store": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -38,8 +46,7 @@ declare module 'ziggy-js' { ], "code16.sharp.single-show": [ { - "name": "filterKey", - "required": true + "name": "filterKey" }, { "name": "entityKey", @@ -48,6 +55,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.download.show": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -59,8 +69,7 @@ declare module 'ziggy-js' { ], "code16.sharp.show.show": [ { - "name": "filterKey", - "required": true + "name": "filterKey" }, { "name": "parentUri", @@ -77,6 +86,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.show.delete": [ + { + "name": "filterKey" + }, { "name": "parentUri", "required": true @@ -92,8 +104,7 @@ declare module 'ziggy-js' { ], "code16.sharp.form.create": [ { - "name": "filterKey", - "required": true + "name": "filterKey" }, { "name": "parentUri", @@ -106,6 +117,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.form.store": [ + { + "name": "filterKey" + }, { "name": "parentUri", "required": true @@ -118,8 +132,7 @@ declare module 'ziggy-js' { ], "code16.sharp.form.edit": [ { - "name": "filterKey", - "required": true + "name": "filterKey" }, { "name": "parentUri", @@ -136,6 +149,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.form.update": [ + { + "name": "filterKey" + }, { "name": "parentUri", "required": true @@ -152,12 +168,14 @@ declare module 'ziggy-js' { ], "code16.sharp.filters.update": [ { - "name": "filterKey", - "required": true + "name": "filterKey" } ], "code16.sharp.update-assets": [], "code16.sharp.api.dashboard.command.form": [ + { + "name": "filterKey" + }, { "name": "dashboardKey", "required": true @@ -168,6 +186,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.dashboard.command": [ + { + "name": "filterKey" + }, { "name": "dashboardKey", "required": true @@ -178,6 +199,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.list.command.quick-creation-form.create": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true, @@ -190,6 +214,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.list.command.quick-creation-form.store": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true, @@ -203,8 +230,7 @@ declare module 'ziggy-js' { ], "code16.sharp.api.list": [ { - "name": "filterKey", - "required": true + "name": "filterKey" }, { "name": "entityKey", @@ -213,18 +239,27 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.list.filters.store": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true } ], "code16.sharp.api.list.reorder": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true } ], "code16.sharp.api.list.delete": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -235,6 +270,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.list.state": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -245,6 +283,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.list.command.entity": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -255,6 +296,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.list.command.entity.form": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -265,6 +309,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.list.command.instance": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -279,6 +326,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.list.command.instance.form": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -294,8 +344,7 @@ declare module 'ziggy-js' { ], "code16.sharp.api.dashboard": [ { - "name": "filterKey", - "required": true + "name": "filterKey" }, { "name": "dashboardKey", @@ -304,12 +353,18 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.dashboard.filters.store": [ + { + "name": "filterKey" + }, { "name": "dashboardKey", "required": true } ], "code16.sharp.api.show.command.instance": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -324,6 +379,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.show.command.instance.form": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -338,6 +396,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.show.command.singleInstance.form": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -348,6 +409,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.show.state": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -357,8 +421,15 @@ declare module 'ziggy-js' { "required": false } ], - "code16.sharp.api.search.index": [], + "code16.sharp.api.search.index": [ + { + "name": "filterKey" + } + ], "code16.sharp.api.embed.form.show": [ + { + "name": "filterKey" + }, { "name": "embedKey", "required": true @@ -369,6 +440,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.embed.form.update": [ + { + "name": "filterKey" + }, { "name": "embedKey", "required": true @@ -379,6 +453,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.embed.instance.form.show": [ + { + "name": "filterKey" + }, { "name": "embedKey", "required": true @@ -393,6 +470,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.embed.instance.form.update": [ + { + "name": "filterKey" + }, { "name": "embedKey", "required": true @@ -407,6 +487,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.form.editor.upload.form.update": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -417,6 +500,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.form.upload.thumbnail.show": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true @@ -428,6 +514,9 @@ declare module 'ziggy-js' { ], "code16.sharp.api.form.upload": [], "code16.sharp.api.form.autocomplete.index": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true, @@ -439,6 +528,9 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.form.refresh.update": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true, @@ -446,13 +538,16 @@ declare module 'ziggy-js' { } ], "code16.sharp.api.filters.autocomplete.index": [ + { + "name": "filterKey" + }, { "name": "entityKey", "required": true, "binding": "key" }, { - "name": "filterKey", + "name": "filterHandlerKey", "required": true } ], diff --git a/src/Dev/Commands/TypescriptGenerateCommand.php b/src/Dev/Commands/TypescriptGenerateCommand.php new file mode 100644 index 000000000..8551379b1 --- /dev/null +++ b/src/Dev/Commands/TypescriptGenerateCommand.php @@ -0,0 +1,41 @@ + true, + ], $this->output); + + file_put_contents( + $ziggyOutput = base_path(config('ziggy.output.path')), + str(file_get_contents($ziggyOutput)) + ->replaceMatches('/("name": "filterKey"),\s+"required": true/', '$1') + ); + + Artisan::call('typescript:transform', [], $this->output); + } +} diff --git a/src/Dev/SharpDevServiceProvider.php b/src/Dev/SharpDevServiceProvider.php index f76f64557..2a231e6d0 100644 --- a/src/Dev/SharpDevServiceProvider.php +++ b/src/Dev/SharpDevServiceProvider.php @@ -2,6 +2,7 @@ namespace Code16\Sharp\Dev; +use Code16\Sharp\Dev\Commands\TypescriptGenerateCommand; use Code16\Sharp\Dev\Commands\UpdateIdeJsonCommand; use Illuminate\Support\ServiceProvider; @@ -15,6 +16,7 @@ public function register() $this->commands([ UpdateIdeJsonCommand::class, + TypescriptGenerateCommand::class, ]); } } diff --git a/src/Http/Controllers/Api/ApiDashboardFiltersController.php b/src/Http/Controllers/Api/ApiDashboardFiltersController.php index 4886fcaab..89dfbf033 100644 --- a/src/Http/Controllers/Api/ApiDashboardFiltersController.php +++ b/src/Http/Controllers/Api/ApiDashboardFiltersController.php @@ -4,7 +4,7 @@ class ApiDashboardFiltersController extends ApiController { - public function store(string $dashboardKey) + public function store(string $filterKey, string $dashboardKey) { $this->authorizationManager->check('entity', $dashboardKey); diff --git a/src/Http/Controllers/Api/ApiEntityListController.php b/src/Http/Controllers/Api/ApiEntityListController.php index 231064446..f24d36f45 100644 --- a/src/Http/Controllers/Api/ApiEntityListController.php +++ b/src/Http/Controllers/Api/ApiEntityListController.php @@ -11,7 +11,7 @@ class ApiEntityListController extends ApiController /** * Reorder instances. */ - public function update(string $entityKey) + public function update(string $filterKey, string $entityKey) { $this->authorizationManager->check('entity', $entityKey); @@ -28,7 +28,7 @@ public function update(string $entityKey) /** * Delete an instance. */ - public function delete(string $entityKey, string $instanceId) + public function delete(string $filterKey, string $entityKey, string $instanceId) { $this->authorizationManager->check('delete', $entityKey, $instanceId); diff --git a/src/Http/Controllers/Api/ApiEntityListFiltersController.php b/src/Http/Controllers/Api/ApiEntityListFiltersController.php index 7c9828a06..f063928fb 100644 --- a/src/Http/Controllers/Api/ApiEntityListFiltersController.php +++ b/src/Http/Controllers/Api/ApiEntityListFiltersController.php @@ -4,7 +4,7 @@ class ApiEntityListFiltersController extends ApiController { - public function store(string $entityKey) + public function store(string $filterKey, string $entityKey) { $this->authorizationManager->check('entity', $entityKey); diff --git a/src/Http/Controllers/Api/ApiFilterAutocompleteController.php b/src/Http/Controllers/Api/ApiFilterAutocompleteController.php index c0b37a0e1..aeccaea54 100644 --- a/src/Http/Controllers/Api/ApiFilterAutocompleteController.php +++ b/src/Http/Controllers/Api/ApiFilterAutocompleteController.php @@ -8,14 +8,14 @@ class ApiFilterAutocompleteController extends ApiController { - public function index(EntityKey $entityKey, string $filterKey): array + public function index(string $filterKey, EntityKey $entityKey, string $filterHandlerKey): array { $entity = $this->entityManager->entityFor($entityKey); if ($entity instanceof SharpDashboardEntity) { - $filter = $entity->getViewOrFail()->filterContainer()->findFilterHandler($filterKey); + $filter = $entity->getViewOrFail()->filterContainer()->findFilterHandler($filterHandlerKey); } else { - $filter = $entity->getListOrFail()->filterContainer()->findFilterHandler($filterKey); + $filter = $entity->getListOrFail()->filterContainer()->findFilterHandler($filterHandlerKey); } if (! $filter instanceof AutocompleteRemoteFilter) { diff --git a/src/Http/Controllers/Api/ApiFormAutocompleteController.php b/src/Http/Controllers/Api/ApiFormAutocompleteController.php index c9ba736b6..5bd18c0f0 100644 --- a/src/Http/Controllers/Api/ApiFormAutocompleteController.php +++ b/src/Http/Controllers/Api/ApiFormAutocompleteController.php @@ -13,7 +13,7 @@ class ApiFormAutocompleteController extends ApiController { use HandlesFieldContainer; - public function index(EntityKey $entityKey, string $autocompleteFieldKey) + public function index(string $filterKey, EntityKey $entityKey, string $autocompleteFieldKey) { $fieldContainer = $this->getFieldContainer($entityKey); $field = $fieldContainer->findFieldByKey($autocompleteFieldKey); diff --git a/src/Http/Controllers/Api/ApiFormEditorUploadFormController.php b/src/Http/Controllers/Api/ApiFormEditorUploadFormController.php index 0c00f4f78..04b1d310d 100644 --- a/src/Http/Controllers/Api/ApiFormEditorUploadFormController.php +++ b/src/Http/Controllers/Api/ApiFormEditorUploadFormController.php @@ -7,7 +7,7 @@ class ApiFormEditorUploadFormController extends Controller { - public function update(EditorUploadFormRequest $request, string $entityKey, ?string $instanceId = null) + public function update(string $filterKey, EditorUploadFormRequest $request, string $entityKey, ?string $instanceId = null) { return response()->json($request->input('data')); } diff --git a/src/Http/Controllers/Api/ApiFormRefreshController.php b/src/Http/Controllers/Api/ApiFormRefreshController.php index 380b30d2c..4598546cc 100644 --- a/src/Http/Controllers/Api/ApiFormRefreshController.php +++ b/src/Http/Controllers/Api/ApiFormRefreshController.php @@ -8,7 +8,7 @@ class ApiFormRefreshController extends ApiController { use HandlesFieldContainer; - public function update(EntityKey $entityKey) + public function update(string $filterKey, EntityKey $entityKey) { $fieldContainer = $this->getFieldContainer($entityKey); diff --git a/src/Http/Controllers/Api/ApiFormUploadThumbnailController.php b/src/Http/Controllers/Api/ApiFormUploadThumbnailController.php index 9e40b6da1..0eadf9c84 100644 --- a/src/Http/Controllers/Api/ApiFormUploadThumbnailController.php +++ b/src/Http/Controllers/Api/ApiFormUploadThumbnailController.php @@ -13,7 +13,7 @@ class ApiFormUploadThumbnailController extends Controller public function __construct(private readonly SharpAuthorizationManager $authorizationManager) {} // Used to generate large thumbnail for upload crop modal - public function show(string $entityKey, ?string $instanceId = null) + public function show(string $filterKey, string $entityKey, ?string $instanceId = null) { $this->authorizationManager->check('view', $entityKey, $instanceId); diff --git a/src/Http/Controllers/Api/ApiSearchController.php b/src/Http/Controllers/Api/ApiSearchController.php index b1226de1e..31334f848 100644 --- a/src/Http/Controllers/Api/ApiSearchController.php +++ b/src/Http/Controllers/Api/ApiSearchController.php @@ -8,7 +8,7 @@ class ApiSearchController extends ApiController { - public function index() + public function index(string $filterKey) { $searchEngine = sharp()->config()->get('search.engine'); diff --git a/src/Http/Controllers/Api/Commands/ApiDashboardCommandController.php b/src/Http/Controllers/Api/Commands/ApiDashboardCommandController.php index 360cf5d38..d4a8b567d 100644 --- a/src/Http/Controllers/Api/Commands/ApiDashboardCommandController.php +++ b/src/Http/Controllers/Api/Commands/ApiDashboardCommandController.php @@ -19,7 +19,7 @@ public function __construct( parent::__construct(); } - public function show(string $entityKey, string $commandKey) + public function show(string $filterKey, string $entityKey, string $commandKey) { $dashboard = $this->getDashboardInstance($entityKey); $dashboard->buildDashboardConfig(); @@ -35,7 +35,7 @@ public function show(string $entityKey, string $commandKey) ); } - public function update(string $entityKey, string $commandKey) + public function update(string $filterKey, string $entityKey, string $commandKey) { $dashboard = $this->getDashboardInstance($entityKey); $dashboard->buildDashboardConfig(); diff --git a/src/Http/Controllers/Api/Commands/ApiEntityListEntityCommandController.php b/src/Http/Controllers/Api/Commands/ApiEntityListEntityCommandController.php index c1e416bfb..7bd6f1204 100644 --- a/src/Http/Controllers/Api/Commands/ApiEntityListEntityCommandController.php +++ b/src/Http/Controllers/Api/Commands/ApiEntityListEntityCommandController.php @@ -18,7 +18,7 @@ public function __construct( parent::__construct(); } - public function show(string $entityKey, string $commandKey) + public function show(string $filterKey, string $entityKey, string $commandKey) { $list = $this->getListInstance($entityKey); $list->buildListConfig(); @@ -33,7 +33,7 @@ public function show(string $entityKey, string $commandKey) ); } - public function update(string $entityKey, string $commandKey) + public function update(string $filterKey, string $entityKey, string $commandKey) { $list = $this->getListInstance($entityKey); $list->buildListConfig(); diff --git a/src/Http/Controllers/Api/Commands/ApiEntityListEntityStateController.php b/src/Http/Controllers/Api/Commands/ApiEntityListEntityStateController.php index e15728a00..ed5ed0873 100644 --- a/src/Http/Controllers/Api/Commands/ApiEntityListEntityStateController.php +++ b/src/Http/Controllers/Api/Commands/ApiEntityListEntityStateController.php @@ -10,7 +10,7 @@ class ApiEntityListEntityStateController extends ApiController use HandlesCommandResult; use HandlesInstanceCommand; - public function update(string $entityKey, mixed $instanceId) + public function update(string $filterKey, string $entityKey, mixed $instanceId) { $list = $this->getListInstance($entityKey); $list->buildListConfig(); diff --git a/src/Http/Controllers/Api/Commands/ApiEntityListInstanceCommandController.php b/src/Http/Controllers/Api/Commands/ApiEntityListInstanceCommandController.php index 15bd9b603..870b6b886 100644 --- a/src/Http/Controllers/Api/Commands/ApiEntityListInstanceCommandController.php +++ b/src/Http/Controllers/Api/Commands/ApiEntityListInstanceCommandController.php @@ -18,7 +18,7 @@ public function __construct( parent::__construct(); } - public function show(string $entityKey, string $commandKey, mixed $instanceId) + public function show(string $filterKey, string $entityKey, string $commandKey, mixed $instanceId) { $list = $this->getListInstance($entityKey); $list->buildListConfig(); @@ -36,7 +36,7 @@ public function show(string $entityKey, string $commandKey, mixed $instanceId) /** * Execute the Command. */ - public function update(string $entityKey, string $commandKey, mixed $instanceId) + public function update(string $filterKey, string $entityKey, string $commandKey, mixed $instanceId) { $list = $this->getListInstance($entityKey); $list->buildListConfig(); diff --git a/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php b/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php index 76150765e..e24358466 100644 --- a/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php +++ b/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php @@ -17,7 +17,7 @@ public function __construct(private readonly SharpUploadManager $uploadManager) parent::__construct(); } - public function create(EntityKey $entityKey, EntityKey $formEntityKey) + public function create(string $filterKey, EntityKey $entityKey, EntityKey $formEntityKey) { $entity = $this->entityManager->entityFor($entityKey); @@ -48,7 +48,7 @@ public function create(EntityKey $entityKey, EntityKey $formEntityKey) ); } - public function store(EntityKey $entityKey, EntityKey $formEntityKey) + public function store(string $filterKey, EntityKey $entityKey, EntityKey $formEntityKey) { $list = $this->entityManager->entityFor($entityKey)->getListOrFail(); $list->buildListConfig(); diff --git a/src/Http/Controllers/Api/Commands/ApiShowEntityStateController.php b/src/Http/Controllers/Api/Commands/ApiShowEntityStateController.php index 343816331..882b11339 100644 --- a/src/Http/Controllers/Api/Commands/ApiShowEntityStateController.php +++ b/src/Http/Controllers/Api/Commands/ApiShowEntityStateController.php @@ -11,7 +11,7 @@ class ApiShowEntityStateController extends ApiController use HandlesCommandResult; use HandlesInstanceCommand; - public function update(string $entityKey, mixed $instanceId = null) + public function update(string $filterKey, string $entityKey, mixed $instanceId = null) { $showPage = $this->getShowPage($entityKey, $instanceId); $stateHandler = $showPage->entityStateHandler(); diff --git a/src/Http/Controllers/Api/Commands/ApiShowInstanceCommandController.php b/src/Http/Controllers/Api/Commands/ApiShowInstanceCommandController.php index 0cfbc6edf..8a4cd6e72 100644 --- a/src/Http/Controllers/Api/Commands/ApiShowInstanceCommandController.php +++ b/src/Http/Controllers/Api/Commands/ApiShowInstanceCommandController.php @@ -19,7 +19,7 @@ public function __construct( parent::__construct(); } - public function show(string $entityKey, string $commandKey, mixed $instanceId = null) + public function show(string $filterKey, string $entityKey, string $commandKey, mixed $instanceId = null) { $showPage = $this->getShowPage($entityKey, $instanceId); $commandHandler = $this->getInstanceCommandHandler($showPage, $commandKey, $instanceId); @@ -31,7 +31,7 @@ public function show(string $entityKey, string $commandKey, mixed $instanceId = ); } - public function update(string $entityKey, string $commandKey, mixed $instanceId = null) + public function update(string $filterKey, string $entityKey, string $commandKey, mixed $instanceId = null) { $showPage = $this->getShowPage($entityKey, $instanceId); $commandHandler = $this->getInstanceCommandHandler($showPage, $commandKey, $instanceId); diff --git a/src/Http/Controllers/Api/Embeds/ApiEmbedsFormController.php b/src/Http/Controllers/Api/Embeds/ApiEmbedsFormController.php index 42c916a0f..741790966 100644 --- a/src/Http/Controllers/Api/Embeds/ApiEmbedsFormController.php +++ b/src/Http/Controllers/Api/Embeds/ApiEmbedsFormController.php @@ -12,7 +12,7 @@ class ApiEmbedsFormController extends Controller public function __construct(private readonly SharpAuthorizationManager $authorizationManager) {} - public function show(string $embedKey, string $entityKey, ?string $instanceId = null) + public function show(string $filterKey, string $embedKey, string $entityKey, ?string $instanceId = null) { if ($instanceId) { $this->authorizationManager->check('view', $entityKey, $instanceId); @@ -31,7 +31,7 @@ public function show(string $embedKey, string $entityKey, ?string $instanceId = ]); } - public function update(string $embedKey, string $entityKey, ?string $instanceId = null) + public function update(string $filterKey, string $embedKey, string $entityKey, ?string $instanceId = null) { if ($instanceId) { $this->authorizationManager->check('update', $entityKey, $instanceId); diff --git a/src/Http/Middleware/HandleGlobalFilters.php b/src/Http/Middleware/HandleGlobalFilters.php index 450006d38..6d7995d48 100644 --- a/src/Http/Middleware/HandleGlobalFilters.php +++ b/src/Http/Middleware/HandleGlobalFilters.php @@ -30,9 +30,9 @@ public function handle(Request $request, Closure $next) ->setCurrentValue($filterKeys[$index]) ); - if (! $request->wantsJson() + if (sharp()->context()->globalFilterUrlSegmentValue() !== $filterKey + && ! $request->wantsJson() && $request->isMethod('GET') - && sharp()->context()->globalFilterUrlSegmentValue() !== $filterKey ) { return redirect()->route('code16.sharp.home', [ 'filterKey' => sharp()->context()->globalFilterUrlSegmentValue(), diff --git a/src/routes/api.php b/src/routes/api.php index 584a953e8..4a8df9d82 100644 --- a/src/routes/api.php +++ b/src/routes/api.php @@ -26,16 +26,16 @@ 'prefix' => '/'.sharp()->config()->get('custom_url_segment').'/api', 'middleware' => ['sharp_common', 'sharp_api'], ], function () { - Route::get('/dashboard/{dashboardKey}/command/{commandKey}/form', [ApiDashboardCommandController::class, 'show']) + Route::get('/{filterKey}/dashboard/{dashboardKey}/command/{commandKey}/form', [ApiDashboardCommandController::class, 'show']) ->name('code16.sharp.api.dashboard.command.form'); - Route::post('/dashboard/{dashboardKey}/command/{commandKey}', [ApiDashboardCommandController::class, 'update']) + Route::post('/{filterKey}/dashboard/{dashboardKey}/command/{commandKey}', [ApiDashboardCommandController::class, 'update']) ->name('code16.sharp.api.dashboard.command'); - Route::get('/list/{entityKey}/form/{formEntityKey}/create', [ApiEntityListQuickCreationCommandController::class, 'create']) + Route::get('/{filterKey}/list/{entityKey}/form/{formEntityKey}/create', [ApiEntityListQuickCreationCommandController::class, 'create']) ->name('code16.sharp.api.list.command.quick-creation-form.create'); - Route::post('/list/{entityKey}/form/{formEntityKey}/create', [ApiEntityListQuickCreationCommandController::class, 'store']) + Route::post('/{filterKey}/list/{entityKey}/form/{formEntityKey}/create', [ApiEntityListQuickCreationCommandController::class, 'store']) ->name('code16.sharp.api.list.command.quick-creation-form.store'); // EmbeddedEntityLists @@ -43,28 +43,28 @@ ->name('code16.sharp.api.list') ->middleware('cache.headers:no_store'); - Route::post('/list/{entityKey}/filters', [ApiEntityListFiltersController::class, 'store']) + Route::post('/{filterKey}/list/{entityKey}/filters', [ApiEntityListFiltersController::class, 'store']) ->name('code16.sharp.api.list.filters.store'); - Route::post('/list/{entityKey}/reorder', [ApiEntityListController::class, 'update']) + Route::post('/{filterKey}/list/{entityKey}/reorder', [ApiEntityListController::class, 'update']) ->name('code16.sharp.api.list.reorder'); - Route::delete('/list/{entityKey}/{instanceId}', [ApiEntityListController::class, 'delete']) + Route::delete('/{filterKey}/list/{entityKey}/{instanceId}', [ApiEntityListController::class, 'delete']) ->name('code16.sharp.api.list.delete'); - Route::post('/list/{entityKey}/state/{instanceId}', [ApiEntityListEntityStateController::class, 'update']) + Route::post('/{filterKey}/list/{entityKey}/state/{instanceId}', [ApiEntityListEntityStateController::class, 'update']) ->name('code16.sharp.api.list.state'); - Route::post('/list/{entityKey}/command/{commandKey}', [ApiEntityListEntityCommandController::class, 'update']) + Route::post('/{filterKey}/list/{entityKey}/command/{commandKey}', [ApiEntityListEntityCommandController::class, 'update']) ->name('code16.sharp.api.list.command.entity'); - Route::get('/list/{entityKey}/command/{commandKey}/form', [ApiEntityListEntityCommandController::class, 'show']) + Route::get('/{filterKey}/list/{entityKey}/command/{commandKey}/form', [ApiEntityListEntityCommandController::class, 'show']) ->name('code16.sharp.api.list.command.entity.form'); - Route::post('/list/{entityKey}/command/{commandKey}/{instanceId}', [ApiEntityListInstanceCommandController::class, 'update']) + Route::post('/{filterKey}/list/{entityKey}/command/{commandKey}/{instanceId}', [ApiEntityListInstanceCommandController::class, 'update']) ->name('code16.sharp.api.list.command.instance'); - Route::get('/list/{entityKey}/command/{commandKey}/{instanceId}/form', [ApiEntityListInstanceCommandController::class, 'show']) + Route::get('/{filterKey}/list/{entityKey}/command/{commandKey}/{instanceId}/form', [ApiEntityListInstanceCommandController::class, 'show']) ->name('code16.sharp.api.list.command.instance.form'); // EmbeddedDashboards @@ -72,53 +72,53 @@ ->name('code16.sharp.api.dashboard') ->middleware('cache.headers:no_store'); - Route::post('/dashboard/{dashboardKey}/filters', [ApiDashboardFiltersController::class, 'store']) + Route::post('/{filterKey}/dashboard/{dashboardKey}/filters', [ApiDashboardFiltersController::class, 'store']) ->name('code16.sharp.api.dashboard.filters.store'); - Route::post('/show/{entityKey}/command/{commandKey}/{instanceId?}', [ApiShowInstanceCommandController::class, 'update']) + Route::post('/{filterKey}/show/{entityKey}/command/{commandKey}/{instanceId?}', [ApiShowInstanceCommandController::class, 'update']) ->name('code16.sharp.api.show.command.instance'); - Route::get('/show/{entityKey}/command/{commandKey}/{instanceId}/form', [ApiShowInstanceCommandController::class, 'show']) + Route::get('/{filterKey}/show/{entityKey}/command/{commandKey}/{instanceId}/form', [ApiShowInstanceCommandController::class, 'show']) ->name('code16.sharp.api.show.command.instance.form'); // Specific route for single shows, because /show/{entityKey}/command/{commandKey}/{instanceId?}/data // does not work since instanceId is optional but not the last segment. - Route::get('/show/{entityKey}/command/{commandKey}/form', [ApiShowInstanceCommandController::class, 'show']) + Route::get('/{filterKey}/show/{entityKey}/command/{commandKey}/form', [ApiShowInstanceCommandController::class, 'show']) ->name('code16.sharp.api.show.command.singleInstance.form'); - Route::post('/show/{entityKey}/state/{instanceId?}', [ApiShowEntityStateController::class, 'update']) + Route::post('/{filterKey}/show/{entityKey}/state/{instanceId?}', [ApiShowEntityStateController::class, 'update']) ->name('code16.sharp.api.show.state'); - Route::get('/search', [ApiSearchController::class, 'index']) + Route::get('/{filterKey}/search', [ApiSearchController::class, 'index']) ->name('code16.sharp.api.search.index'); - Route::post('/embeds/{embedKey}/{entityKey}/form/init', [ApiEmbedsFormController::class, 'show']) + Route::post('/{filterKey}/embeds/{embedKey}/{entityKey}/form/init', [ApiEmbedsFormController::class, 'show']) ->name('code16.sharp.api.embed.form.show'); - Route::post('/embeds/{embedKey}/{entityKey}/form', [ApiEmbedsFormController::class, 'update']) + Route::post('/{filterKey}/embeds/{embedKey}/{entityKey}/form', [ApiEmbedsFormController::class, 'update']) ->name('code16.sharp.api.embed.form.update'); - Route::post('/embeds/{embedKey}/{entityKey}/{instanceId}/form/init', [ApiEmbedsFormController::class, 'show']) + Route::post('/{filterKey}/embeds/{embedKey}/{entityKey}/{instanceId}/form/init', [ApiEmbedsFormController::class, 'show']) ->name('code16.sharp.api.embed.instance.form.show'); - Route::post('/embeds/{embedKey}/{entityKey}/{instanceId}/form', [ApiEmbedsFormController::class, 'update']) + Route::post('/{filterKey}/embeds/{embedKey}/{entityKey}/{instanceId}/form', [ApiEmbedsFormController::class, 'update']) ->name('code16.sharp.api.embed.instance.form.update'); - Route::post('/form/editors/upload/form/{entityKey}/{instanceId?}', [ApiFormEditorUploadFormController::class, 'update']) + Route::post('/{filterKey}/form/editors/upload/form/{entityKey}/{instanceId?}', [ApiFormEditorUploadFormController::class, 'update']) ->name('code16.sharp.api.form.editor.upload.form.update'); - Route::post('/upload/thumbnail/{entityKey}/{instanceId?}', [ApiFormUploadThumbnailController::class, 'show']) + Route::post('/{filterKey}/upload/thumbnail/{entityKey}/{instanceId?}', [ApiFormUploadThumbnailController::class, 'show']) ->name('code16.sharp.api.form.upload.thumbnail.show'); Route::post('/upload', [ApiFormUploadController::class, 'store']) ->name('code16.sharp.api.form.upload'); - Route::post('/form/autocomplete/{entityKey}/{autocompleteFieldKey}', [ApiFormAutocompleteController::class, 'index']) + Route::post('/{filterKey}/form/autocomplete/{entityKey}/{autocompleteFieldKey}', [ApiFormAutocompleteController::class, 'index']) ->name('code16.sharp.api.form.autocomplete.index'); - Route::post('/form/refresh/{entityKey}', [ApiFormRefreshController::class, 'update']) + Route::post('/{filterKey}/form/refresh/{entityKey}', [ApiFormRefreshController::class, 'update']) ->name('code16.sharp.api.form.refresh.update'); - Route::post('/filters/autocomplete/{entityKey}/{filterKey}', [ApiFilterAutocompleteController::class, 'index']) + Route::post('/{filterKey}/filters/autocomplete/{entityKey}/{filterHandlerKey}', [ApiFilterAutocompleteController::class, 'index']) ->name('code16.sharp.api.filters.autocomplete.index'); }); diff --git a/tests/Http/Api/ApiEntityListControllerTest.php b/tests/Http/Api/ApiEntityListControllerTest.php index cd3ef7bea..644bb4a99 100644 --- a/tests/Http/Api/ApiEntityListControllerTest.php +++ b/tests/Http/Api/ApiEntityListControllerTest.php @@ -46,7 +46,7 @@ public function reorder(array $ids): void $this ->postJson( - route('code16.sharp.api.list.reorder', 'person'), + route('code16.sharp.api.list.reorder', ['root', 'person']), ['instances' => [3, 2, 1]] ) ->assertOk(); @@ -69,7 +69,7 @@ public function delete($id): void $idToDelete = rand(1, 10); - $this->deleteJson(route('code16.sharp.api.list.delete', ['person', $idToDelete])) + $this->deleteJson(route('code16.sharp.api.list.delete', ['root', 'person', $idToDelete])) ->assertOk(); expect($list->deletedInstance)->toEqual($idToDelete); @@ -93,7 +93,7 @@ public function delete($id): void $idToDelete = rand(1, 10); - $this->deleteJson(route('code16.sharp.api.list.delete', ['person', $idToDelete])) + $this->deleteJson(route('code16.sharp.api.list.delete', ['root', 'person', $idToDelete])) ->assertOk(); expect($show->deletedInstance)->toEqual($idToDelete); @@ -116,14 +116,14 @@ public function delete($user, $instanceId): bool } }); - $this->deleteJson(route('code16.sharp.api.list.delete', ['person', 1])) + $this->deleteJson(route('code16.sharp.api.list.delete', ['root', 'person', 1])) ->assertForbidden(); }); it('throws an exception if delete is not implemented and there is no show', function () { fakeShowFor('person', null); - $this->deleteJson(route('code16.sharp.api.list.delete', ['person', 1])) + $this->deleteJson(route('code16.sharp.api.list.delete', ['root', 'person', 1])) ->assertStatus(500); }); diff --git a/tests/Http/Api/ApiFilterAutocompleteTest.php b/tests/Http/Api/ApiFilterAutocompleteTest.php index 68cc26b3c..89669677a 100644 --- a/tests/Http/Api/ApiFilterAutocompleteTest.php +++ b/tests/Http/Api/ApiFilterAutocompleteTest.php @@ -49,8 +49,9 @@ public function valueLabelFor(string $id): string $this ->postJson(route('code16.sharp.api.filters.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', - 'filterKey' => 'test', + 'filterHandlerKey' => 'test', ]), [ 'query' => 'my search', ]) @@ -99,8 +100,9 @@ public function valueLabelFor(string $id): string $this ->postJson(route('code16.sharp.api.filters.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', - 'filterKey' => 'test', + 'filterHandlerKey' => 'test', ]), [ 'query' => '', ]) @@ -150,8 +152,9 @@ public function valueLabelFor(string $id): string $this ->postJson(route('code16.sharp.api.filters.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'dashboard', - 'filterKey' => 'test', + 'filterHandlerKey' => 'test', ]), [ 'query' => 'my search', ]) diff --git a/tests/Http/Api/ApiFormAutocompleteControllerTest.php b/tests/Http/Api/ApiFormAutocompleteControllerTest.php index 9cfd32254..fc07c4497 100644 --- a/tests/Http/Api/ApiFormAutocompleteControllerTest.php +++ b/tests/Http/Api/ApiFormAutocompleteControllerTest.php @@ -44,6 +44,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -78,6 +79,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -118,6 +120,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'list.autocomplete_field', 'formData' => [ @@ -159,6 +162,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -198,6 +202,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -234,6 +239,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -270,6 +276,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -312,6 +319,7 @@ public function getNameAndJob(): string $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -346,6 +354,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -376,6 +385,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ])); @@ -396,6 +406,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'name', ])); @@ -421,6 +432,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -448,6 +460,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -481,6 +494,7 @@ public function buildFormFields(FieldsContainer $formFields): void foreach (['/my/endpoint', url('/my/endpoint')] as $endpoint) { $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -491,6 +505,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_full_field', ]), [ @@ -518,6 +533,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -544,6 +560,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -570,6 +587,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -596,6 +614,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -623,6 +642,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', ]), [ @@ -656,6 +676,7 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', 'embed_key' => (new ApiFormAutocompleteControllerAutocompleteEmbed())->key(), @@ -708,6 +729,7 @@ public function execute(mixed $instanceId, array $data = []): array {} $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', 'instance_id' => 1, @@ -761,6 +783,7 @@ public function execute(array $data = []): array {} $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', 'entity_list_command_key' => 'my-command', @@ -813,6 +836,7 @@ protected function executeSingle(array $data): array {} $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', 'instance_id' => 1, @@ -866,6 +890,7 @@ protected function executeSingle(array $data): array {} $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', 'show_command_key' => 'my-command', @@ -923,6 +948,7 @@ public function execute(mixed $instanceId, array $data = []): array {} $this ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'autocompleteFieldKey' => 'autocomplete_field', 'instance_id' => 1, diff --git a/tests/Http/Api/ApiFormRefreshControllerTest.php b/tests/Http/Api/ApiFormRefreshControllerTest.php index b002a7a06..1b8f34656 100644 --- a/tests/Http/Api/ApiFormRefreshControllerTest.php +++ b/tests/Http/Api/ApiFormRefreshControllerTest.php @@ -46,6 +46,7 @@ public function update(mixed $id, array $data) {} $this->post( route('code16.sharp.api.form.refresh.update', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'instance_id' => 1, ]), @@ -96,6 +97,7 @@ public function execute(array $data = []): array $this->post( route('code16.sharp.api.form.refresh.update', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'entity_list_command_key' => 'cmd', ]), @@ -146,6 +148,7 @@ public function execute(mixed $instanceId, array $data = []): array $this->post( route('code16.sharp.api.form.refresh.update', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'entity_list_command_key' => 'cmd', 'instance_id' => 1, @@ -197,6 +200,7 @@ public function execute(mixed $instanceId, array $data = []): array $this->post( route('code16.sharp.api.form.refresh.update', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'show_command_key' => 'cmd', 'instance_id' => 1, @@ -226,6 +230,7 @@ public function execute(mixed $instanceId, array $data = []): array $this ->postJson( route('code16.sharp.api.form.refresh.update', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'embed_key' => (new ApiFormRefreshControllerEmbed())->key(), ]), diff --git a/tests/Http/Api/ApiFormUploadThumbnailControllerTest.php b/tests/Http/Api/ApiFormUploadThumbnailControllerTest.php index 4745a32b4..ca1a0256b 100644 --- a/tests/Http/Api/ApiFormUploadThumbnailControllerTest.php +++ b/tests/Http/Api/ApiFormUploadThumbnailControllerTest.php @@ -13,6 +13,7 @@ ->storeAs('data/Posts/1', 'image.jpg', ['disk' => 'local']); $this->postJson(route('code16.sharp.api.form.upload.thumbnail.show', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'instanceId' => '1', 'path' => 'data/Posts/1/image.jpg', diff --git a/tests/Http/Api/Commands/ApiDashboardCommandControllerTest.php b/tests/Http/Api/Commands/ApiDashboardCommandControllerTest.php index 92837a159..400e65bf5 100644 --- a/tests/Http/Api/Commands/ApiDashboardCommandControllerTest.php +++ b/tests/Http/Api/Commands/ApiDashboardCommandControllerTest.php @@ -35,7 +35,7 @@ public function execute(array $data = []): array $this->withoutExceptionHandling(); - $this->postJson(route('code16.sharp.api.dashboard.command', ['dashboard', 'info'])) + $this->postJson(route('code16.sharp.api.dashboard.command', ['root', 'dashboard', 'info'])) ->assertOk() ->assertJson([ 'action' => 'info', @@ -84,7 +84,7 @@ public function initialData(): array }); $this - ->getJson(route('code16.sharp.api.dashboard.command.form', ['dashboard', 'command_with_init_data'])) + ->getJson(route('code16.sharp.api.dashboard.command.form', ['root', 'dashboard', 'command_with_init_data'])) ->assertOk() ->assertJsonFragment([ 'data' => [ diff --git a/tests/Http/Api/Commands/ApiEntityListEntityCommandControllerTest.php b/tests/Http/Api/Commands/ApiEntityListEntityCommandControllerTest.php index f58bb0265..e889d4de2 100644 --- a/tests/Http/Api/Commands/ApiEntityListEntityCommandControllerTest.php +++ b/tests/Http/Api/Commands/ApiEntityListEntityCommandControllerTest.php @@ -40,7 +40,11 @@ public function execute(array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd'])) + $this->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJson([ 'action' => 'info', @@ -71,7 +75,11 @@ public function execute(array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd'])) + $this->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJson([ 'action' => 'reload', @@ -100,7 +108,11 @@ public function execute(array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd'])) + $this->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJson([ 'action' => 'info', @@ -131,7 +143,11 @@ public function execute(array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd'])) + $this->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJson([ 'action' => 'view', @@ -160,7 +176,11 @@ public function execute(array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd'])) + $this->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJson([ 'action' => 'view', @@ -200,7 +220,11 @@ public function getListData(): array|\Illuminate\Contracts\Support\Arrayable } }); - $this->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd'])) + $this->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJson([ 'action' => 'refresh', @@ -233,7 +257,11 @@ public function execute(array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd'])) + $this->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJson([ 'action' => 'link', @@ -264,7 +292,11 @@ public function execute(array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd'])) + $this->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJson([ 'action' => 'link', @@ -304,7 +336,11 @@ public function execute(array $data = []): array $this ->postJson( - route('code16.sharp.api.list.command.entity', ['person', 'cmd']), + route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ]), ['data' => ['name' => 'Pierre']] ) ->assertOk() @@ -314,7 +350,11 @@ public function execute(array $data = []): array $this ->postJson( - route('code16.sharp.api.list.command.entity', ['person', 'cmd']), + route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ]), ['data' => ['name' => '']] ) ->assertJsonValidationErrors(['name']); @@ -354,7 +394,11 @@ public function execute(array $data = []): array $this ->postJson( - route('code16.sharp.api.list.command.entity', ['person', 'cmd']), + route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ]), ['data' => ['name' => 'Pierre']] ) ->assertOk() @@ -364,7 +408,11 @@ public function execute(array $data = []): array $this ->postJson( - route('code16.sharp.api.list.command.entity', ['person', 'cmd']), + route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ]), ['data' => ['name' => '']] ) ->assertJsonValidationErrors(['name']); @@ -398,7 +446,11 @@ public function execute(array $data = []): array }); $response = $this - ->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd'])) + ->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk(); expect($response->headers->get('content-disposition')) @@ -428,7 +480,11 @@ public function execute(array $data = []): array }); $response = $this - ->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd'])) + ->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertHeader('content-type', 'text/html; charset=utf-8'); @@ -459,7 +515,11 @@ public function execute(array $data = []): array }); $this - ->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd'])) + ->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertStatus(417) ->assertJson([ 'message' => 'error', @@ -490,7 +550,11 @@ public function execute(array $data = []): array }); $this - ->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd']), + ->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ]), ['query' => ['sort' => 'name', 'dir' => 'desc']] ) ->assertOk() @@ -527,7 +591,11 @@ public function execute(array $data = []): array } }); $this - ->postJson(route('code16.sharp.api.list.command.entity', ['person', 'cmd']), + ->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ]), ['query' => ['ids' => ['1', '2']]] ) ->assertOk() @@ -565,7 +633,7 @@ public function execute(array $data = []): array }); $this - ->postJson(route('code16.sharp.api.list.command.entity', ['person', 'entity_unauthorized'])) + ->postJson(route('code16.sharp.api.list.command.entity', ['root', 'person', 'entity_unauthorized'])) ->assertStatus(403); }); @@ -605,7 +673,11 @@ public function execute(array $data = []): array }); $this - ->getJson(route('code16.sharp.api.list.command.entity.form', ['person', 'cmd'])) + ->getJson(route('code16.sharp.api.list.command.entity.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJsonFragment([ 'layout' => [ @@ -676,7 +748,11 @@ public function execute(array $data = []): array {} } }); - $this->getJson(route('code16.sharp.api.list.command.entity.form', ['person', 'cmd'])); + $this->getJson(route('code16.sharp.api.list.command.entity.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])); })->throws(SharpFormFieldLayoutException::class, SharpFormFieldLayoutException::undeclaredField('title')->getMessage()); it('allows to configure a page alert on an entity command', function () { @@ -716,7 +792,11 @@ public function execute(array $data = []): array $this ->withoutExceptionHandling() - ->getJson(route('code16.sharp.api.list.command.entity.form', ['person', 'cmd'])) + ->getJson(route('code16.sharp.api.list.command.entity.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJsonFragment([ 'pageAlert' => [ @@ -761,7 +841,11 @@ public function getDataLocalizations(): array }); $this - ->getJson(route('code16.sharp.api.list.command.entity.form', ['person', 'cmd'])) + ->getJson(route('code16.sharp.api.list.command.entity.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJsonFragment([ 'fields' => [ @@ -817,7 +901,11 @@ public function initialData(): array }); $this - ->getJson(route('code16.sharp.api.list.command.entity.form', ['person', 'cmd'])) + ->getJson(route('code16.sharp.api.list.command.entity.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJsonFragment([ 'data' => [ diff --git a/tests/Http/Api/Commands/ApiEntityListEntityStateControllerTest.php b/tests/Http/Api/Commands/ApiEntityListEntityStateControllerTest.php index 74ce08a2d..91bfba3b8 100644 --- a/tests/Http/Api/Commands/ApiEntityListEntityStateControllerTest.php +++ b/tests/Http/Api/Commands/ApiEntityListEntityStateControllerTest.php @@ -42,7 +42,7 @@ public function getListData(): array|Arrayable $this ->postJson( - route('code16.sharp.api.list.state', ['person', 1]), + route('code16.sharp.api.list.state', ['root', 'person', 1]), [ 'attribute' => 'state', 'value' => 'ok', @@ -82,7 +82,7 @@ protected function updateState($instanceId, string $stateId): ?array $this ->postJson( - route('code16.sharp.api.list.state', ['person', 1]), + route('code16.sharp.api.list.state', ['root', 'person', 1]), [ 'attribute' => 'state', 'value' => 'ok', @@ -117,7 +117,7 @@ protected function updateState($instanceId, string $stateId): ?array }); $this ->postJson( - route('code16.sharp.api.list.state', ['person', 1]), + route('code16.sharp.api.list.state', ['root', 'person', 1]), [ 'attribute' => 'state', 'value' => 'invalid', @@ -149,7 +149,7 @@ protected function updateState($instanceId, string $stateId): ?array $this ->postJson( - route('code16.sharp.api.list.state', ['person', 1]), + route('code16.sharp.api.list.state', ['root', 'person', 1]), [ 'attribute' => 'state', 'value' => 'ok', @@ -182,7 +182,7 @@ public function authorizeFor(mixed $instanceId): bool $this ->postJson( - route('code16.sharp.api.list.state', ['person', 1]), + route('code16.sharp.api.list.state', ['root', 'person', 1]), [ 'attribute' => 'state', 'value' => 'ok', diff --git a/tests/Http/Api/Commands/ApiEntityListEntityWizardCommandControllerTest.php b/tests/Http/Api/Commands/ApiEntityListEntityWizardCommandControllerTest.php index 65f5915a2..9840c2fe8 100644 --- a/tests/Http/Api/Commands/ApiEntityListEntityWizardCommandControllerTest.php +++ b/tests/Http/Api/Commands/ApiEntityListEntityWizardCommandControllerTest.php @@ -39,7 +39,11 @@ protected function executeFirstStep(array $data): array }); $this - ->getJson(route('code16.sharp.api.list.command.entity.form', ['person', 'wizard'])) + ->getJson(route('code16.sharp.api.list.command.entity.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + ])) ->assertOk() ->assertJsonFragment([ 'fields' => [ @@ -105,12 +109,20 @@ protected function executeFirstStep(array $data): array }); $this - ->postJson(route('code16.sharp.api.list.command.entity', ['person', 'wizard'])) + ->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + ])) ->assertJsonValidationErrors('name'); $this ->postJson( - route('code16.sharp.api.list.command.entity', ['person', 'wizard']), + route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + ]), ['data' => ['name' => 'test']], ) ->assertOk() @@ -174,6 +186,7 @@ protected function executeStepNextStep(array $data): array $this ->getJson( route('code16.sharp.api.list.command.entity.form', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'commandKey' => 'wizard', 'command_step' => 'next-step:test-key', @@ -184,7 +197,11 @@ protected function executeStepNextStep(array $data): array // First post step 1... $this ->postJson( - route('code16.sharp.api.list.command.entity', ['person', 'wizard']), + route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + ]), ) ->assertOk(); @@ -261,7 +278,11 @@ protected function executeStepNextStep(array $data): array // First post step 1... $this ->postJson( - route('code16.sharp.api.list.command.entity', ['person', 'wizard']), + route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + ]), ['data' => ['name' => 'test']], ) ->assertOk(); @@ -330,7 +351,11 @@ public function executeStep(string $step, array $data = []): array // First post step 1... $this - ->postJson(route('code16.sharp.api.list.command.entity', ['person', 'wizard'])) + ->postJson(route('code16.sharp.api.list.command.entity', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + ])) ->assertOk(); // Then get step 2 diff --git a/tests/Http/Api/Commands/ApiEntityListInstanceCommandControllerTest.php b/tests/Http/Api/Commands/ApiEntityListInstanceCommandControllerTest.php index 3566bf329..a7ee37c92 100644 --- a/tests/Http/Api/Commands/ApiEntityListInstanceCommandControllerTest.php +++ b/tests/Http/Api/Commands/ApiEntityListInstanceCommandControllerTest.php @@ -37,7 +37,12 @@ public function execute($instanceId, array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.instance', ['person', 'instance_info', 1])) + $this->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_info', + 'instanceId' => 1, + ])) ->assertOk() ->assertJson([ 'action' => 'info', @@ -68,7 +73,12 @@ public function execute($instanceId, array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.instance', ['person', 'instance_reload', 1])) + $this->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_reload', + 'instanceId' => 1, + ])) ->assertOk() ->assertJson([ 'action' => 'reload', @@ -97,7 +107,12 @@ public function execute($instanceId, array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.instance', ['person', 'instance_info', 1])) + $this->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_info', + 'instanceId' => 1, + ])) ->assertOk() ->assertJson([ 'action' => 'info', @@ -128,7 +143,12 @@ public function execute($instanceId, array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.instance', ['person', 'instance_view', 1])) + $this->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_view', + 'instanceId' => 1, + ])) ->assertOk() ->assertJson([ 'action' => 'view', @@ -157,7 +177,12 @@ public function execute($instanceId, array $data = []): array } }); - $this->postJson(route('code16.sharp.api.list.command.instance', ['person', 'instance_html', 1])) + $this->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_html', + 'instanceId' => 1, + ])) ->assertOk() ->assertJson([ 'action' => 'view', @@ -197,7 +222,12 @@ public function getListData(): array|\Illuminate\Contracts\Support\Arrayable } }); - $this->postJson(route('code16.sharp.api.list.command.instance', ['person', 'instance_refresh', 1])) + $this->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_refresh', + 'instanceId' => 1, + ])) ->assertOk() ->assertJson([ 'action' => 'refresh', @@ -239,7 +269,12 @@ public function execute($instanceId, array $data = []): array $this ->postJson( - route('code16.sharp.api.list.command.instance', ['person', 'instance_form', 1]), + route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_form', + 'instanceId' => 1, + ]), ['data' => ['name' => 'Pierre']] ) ->assertOk() @@ -249,7 +284,12 @@ public function execute($instanceId, array $data = []): array $this ->postJson( - route('code16.sharp.api.list.command.instance', ['person', 'instance_form', 1]), + route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_form', + 'instanceId' => 1, + ]), ['data' => ['name' => '']] ) ->assertJsonValidationErrors(['name']); @@ -283,7 +323,12 @@ public function execute($instanceId, array $data = []): array }); $response = $this - ->postJson(route('code16.sharp.api.list.command.instance', ['person', 'instance_download', 1])) + ->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_download', + 'instanceId' => 1, + ])) ->assertOk(); expect($response->headers->get('content-disposition')) @@ -313,7 +358,12 @@ public function execute($instanceId, array $data = []): array }); $response = $this - ->postJson(route('code16.sharp.api.list.command.instance', ['person', 'instance_streamDownload', 1])) + ->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_streamDownload', + 'instanceId' => 1, + ])) ->assertOk() ->assertHeader('content-type', 'text/html; charset=utf-8'); @@ -344,7 +394,12 @@ public function execute($instanceId, array $data = []): array }); $this - ->postJson(route('code16.sharp.api.list.command.instance', ['person', 'instance_417', 1])) + ->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_417', + 'instanceId' => 1, + ])) ->assertStatus(417) ->assertJson([ 'message' => 'error', @@ -379,11 +434,21 @@ public function execute($instanceId, array $data = []): array }); $this - ->postJson(route('code16.sharp.api.list.command.instance', ['person', 'instance_unauthorized', 1])) + ->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_unauthorized', + 'instanceId' => 1, + ])) ->assertForbidden(); $this - ->postJson(route('code16.sharp.api.list.command.instance', ['person', 'instance_unauthorized', 2])) + ->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_unauthorized', + 'instanceId' => 2, + ])) ->assertOk(); }); @@ -415,7 +480,12 @@ public function execute($instanceId, array $data = []): array }); $this - ->getJson(route('code16.sharp.api.list.command.instance.form', ['person', 'instance_form', 1])) + ->getJson(route('code16.sharp.api.list.command.instance.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_form', + 'instanceId' => 1, + ])) ->assertOk() ->assertJsonFragment([ 'fields' => [ @@ -482,7 +552,12 @@ public function execute($instanceId, array $data = []): array }); $this - ->getJson(route('code16.sharp.api.list.command.instance.form', ['person', 'cmd', 1])) + ->getJson(route('code16.sharp.api.list.command.instance.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + 'instanceId' => 1, + ])) ->assertOk() ->assertJsonFragment([ 'pageAlert' => [ @@ -527,7 +602,12 @@ public function getDataLocalizations(): array }); $this - ->getJson(route('code16.sharp.api.list.command.instance.form', ['person', 'instance_form_localized', 1])) + ->getJson(route('code16.sharp.api.list.command.instance.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_form_localized', + 'instanceId' => 1, + ])) ->assertOk() ->assertJsonFragment([ 'fields' => [ @@ -583,7 +663,12 @@ public function initialData($instanceId): array }); $this - ->getJson(route('code16.sharp.api.list.command.instance.form', ['person', 'instance_with_init_data', 1])) + ->getJson(route('code16.sharp.api.list.command.instance.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'instance_with_init_data', + 'instanceId' => 1, + ])) ->assertOk() ->assertJsonFragment([ 'data' => [ diff --git a/tests/Http/Api/Commands/ApiEntityListInstanceWizardCommandControllerTest.php b/tests/Http/Api/Commands/ApiEntityListInstanceWizardCommandControllerTest.php index 490ba6870..13f2a39e7 100644 --- a/tests/Http/Api/Commands/ApiEntityListInstanceWizardCommandControllerTest.php +++ b/tests/Http/Api/Commands/ApiEntityListInstanceWizardCommandControllerTest.php @@ -39,7 +39,11 @@ protected function executeFirstStep($instanceId, array $data): array }); $this - ->getJson(route('code16.sharp.api.list.command.instance.form', ['person', 'wizard', 1])) + ->getJson(route('code16.sharp.api.list.command.instance.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + 'instanceId' => 1])) ->assertOk() ->assertJsonFragment([ 'fields' => [ @@ -105,12 +109,21 @@ protected function executeFirstStep($instanceId, array $data): array }); $this - ->postJson(route('code16.sharp.api.list.command.instance', ['person', 'wizard', 1])) + ->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + 'instanceId' => 1])) ->assertJsonValidationErrors('name'); $this ->postJson( - route('code16.sharp.api.list.command.instance', ['person', 'wizard', 1]), + route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + 'instanceId' => 1, + ]), ['data' => ['name' => 'test']], ) ->assertOk() @@ -174,6 +187,7 @@ protected function executeStepNextStep($instanceId, array $data): array $this ->getJson( route('code16.sharp.api.list.command.instance.form', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'commandKey' => 'wizard', 'instanceId' => 1, @@ -185,7 +199,12 @@ protected function executeStepNextStep($instanceId, array $data): array // First post step 1... $this ->postJson( - route('code16.sharp.api.list.command.instance', ['person', 'wizard', 1]), + route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + 'instanceId' => 1, + ]), ) ->assertOk(); @@ -193,6 +212,7 @@ protected function executeStepNextStep($instanceId, array $data): array $this ->getJson( route('code16.sharp.api.list.command.instance.form', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'commandKey' => 'wizard', 'instanceId' => 1, @@ -263,7 +283,11 @@ protected function executeStepNextStep($instanceId, array $data): array // First post step 1... $this ->postJson( - route('code16.sharp.api.list.command.instance', ['person', 'wizard', 1]), + route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + 'instanceId' => 1]), ['data' => ['name' => 'test']], ) ->assertOk(); @@ -333,13 +357,18 @@ public function executeStep(string $step, $instanceId, array $data = []): array // First post step 1... $this - ->postJson(route('code16.sharp.api.list.command.instance', ['person', 'wizard', 1])) + ->postJson(route('code16.sharp.api.list.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'wizard', + 'instanceId' => 1])) ->assertOk(); // Then get step 2 $this ->getJson( route('code16.sharp.api.list.command.instance.form', [ + 'filterKey' => 'root', 'entityKey' => 'person', 'commandKey' => 'wizard', 'instanceId' => 1, diff --git a/tests/Http/Api/Commands/ApiEntityListQuickCreationCommandControllerTest.php b/tests/Http/Api/Commands/ApiEntityListQuickCreationCommandControllerTest.php index 73f18f7d9..a520e5184 100644 --- a/tests/Http/Api/Commands/ApiEntityListQuickCreationCommandControllerTest.php +++ b/tests/Http/Api/Commands/ApiEntityListQuickCreationCommandControllerTest.php @@ -34,7 +34,11 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->getJson( - route('code16.sharp.api.list.command.quick-creation-form.create', ['person', 'person']), + route('code16.sharp.api.list.command.quick-creation-form.create', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'formEntityKey' => 'person', + ]), ) ->assertOk() ->assertJson([ @@ -69,7 +73,11 @@ public function buildFormFields(FieldsContainer $formFields): void $this ->getJson( - route('code16.sharp.api.list.command.quick-creation-form.create', ['person', 'person']), + route('code16.sharp.api.list.command.quick-creation-form.create', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'formEntityKey' => 'person', + ]), ) ->assertOk() ->assertJsonCount(1, 'fields'); @@ -83,7 +91,11 @@ public function buildListConfig(): void {} $this ->getJson( - route('code16.sharp.api.list.command.quick-creation-form.create', ['person', 'person']), + route('code16.sharp.api.list.command.quick-creation-form.create', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'formEntityKey' => 'person', + ]), ) ->assertStatus(403); }); @@ -118,7 +130,11 @@ public function update($id, array $data) $this ->postJson( - route('code16.sharp.api.list.command.quick-creation-form.create', ['person', 'person']), + route('code16.sharp.api.list.command.quick-creation-form.create', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'formEntityKey' => 'person', + ]), ['data' => ['name' => 'Marie Curie', 'job' => 'Scientist']], ) ->assertOk() @@ -143,7 +159,11 @@ public function update($id, array $data) {} $this ->postJson( - route('code16.sharp.api.list.command.quick-creation-form.create', ['person', 'person']), + route('code16.sharp.api.list.command.quick-creation-form.create', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'formEntityKey' => 'person', + ]), ['data' => []], ) ->assertOk() @@ -177,7 +197,11 @@ public function update($id, array $data) $this ->postJson( - route('code16.sharp.api.list.command.quick-creation-form.create', ['person', 'person']), + route('code16.sharp.api.list.command.quick-creation-form.create', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'formEntityKey' => 'person', + ]), ['data' => []], [ SharpBreadcrumb::CURRENT_PAGE_URL_HEADER => url('/sharp/root/s-list/person'), @@ -216,7 +240,11 @@ public function update($id, array $data) $this ->postJson( - route('code16.sharp.api.list.command.quick-creation-form.create', ['person', 'person']), + route('code16.sharp.api.list.command.quick-creation-form.create', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'formEntityKey' => 'person', + ]), ['data' => ['name' => '']], ) ->assertStatus(422) @@ -249,7 +277,11 @@ public function update($id, array $data) $this ->postJson( - route('code16.sharp.api.list.command.quick-creation-form.create', ['person', 'person']), + route('code16.sharp.api.list.command.quick-creation-form.create', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'formEntityKey' => 'person', + ]), ['data' => ['name' => 'Marie Curie']], ) ->assertOk() diff --git a/tests/Http/Api/Commands/ApiShowEntityStateControllerTest.php b/tests/Http/Api/Commands/ApiShowEntityStateControllerTest.php index a3f96be13..67d04adce 100644 --- a/tests/Http/Api/Commands/ApiShowEntityStateControllerTest.php +++ b/tests/Http/Api/Commands/ApiShowEntityStateControllerTest.php @@ -35,7 +35,7 @@ protected function updateState($instanceId, string $stateId): ?array $this ->postJson( - route('code16.sharp.api.show.state', ['person', 1]), + route('code16.sharp.api.show.state', ['root', 'person', 1]), [ 'attribute' => 'state', 'value' => 'ok', @@ -73,7 +73,7 @@ protected function updateState($instanceId, string $stateId): ?array $this ->postJson( - route('code16.sharp.api.show.state', ['single-person']), + route('code16.sharp.api.show.state', ['root', 'single-person']), [ 'attribute' => 'state', 'value' => 'ok', diff --git a/tests/Http/Api/Commands/ApiShowInstanceCommandControllerTest.php b/tests/Http/Api/Commands/ApiShowInstanceCommandControllerTest.php index 7ce119290..07cf7999f 100644 --- a/tests/Http/Api/Commands/ApiShowInstanceCommandControllerTest.php +++ b/tests/Http/Api/Commands/ApiShowInstanceCommandControllerTest.php @@ -36,7 +36,12 @@ public function execute($instanceId, array $data = []): array } }); - $this->postJson(route('code16.sharp.api.show.command.instance', ['person', 'cmd', 1])) + $this->postJson(route('code16.sharp.api.show.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + 'instanceId' => 1, + ])) ->assertOk() ->assertJson([ 'action' => 'info', @@ -68,7 +73,12 @@ public function execute($instanceId, array $data = []): array } }); - $this->postJson(route('code16.sharp.api.show.command.instance', ['single-person', 'cmd'])) + $this + ->postJson(route('code16.sharp.api.show.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'single-person', + 'commandKey' => 'cmd', + ])) ->assertOk() ->assertJson([ 'action' => 'info', @@ -121,7 +131,12 @@ public function execute($instanceId, array $data = []): array }); $this - ->getJson(route('code16.sharp.api.show.command.instance.form', ['person', 'cmd', 1])) + ->getJson(route('code16.sharp.api.show.command.instance.form', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + 'instanceId' => 1, + ])) ->assertOk() ->assertJsonFragment([ 'data' => [ @@ -161,7 +176,12 @@ public function execute($instanceId, array $data = []): array $this ->postJson( - route('code16.sharp.api.show.command.instance', ['person', 'cmd', 1]), + route('code16.sharp.api.show.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'person', + 'commandKey' => 'cmd', + 'instanceId' => 1, + ]), ['data' => ['name' => '']] ) ->assertJsonValidationErrors(['name']); @@ -214,6 +234,7 @@ public function execute($instanceId, array $data = []): array $this ->getJson( route('code16.sharp.api.show.command.singleInstance.form', [ + 'filterKey' => 'root', 'entityKey' => 'single-person', 'commandKey' => 'single_cmd', ]) @@ -257,7 +278,11 @@ public function execute($instanceId, array $data = []): array $this ->postJson( - route('code16.sharp.api.show.command.instance', ['single-person', 'single_cmd']), + route('code16.sharp.api.show.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'single-person', + 'commandKey' => 'single_cmd', + ]), ['data' => ['name' => '']] ) ->assertJsonValidationErrors(['name']); diff --git a/tests/Http/Api/Embeds/ApiEmbedsFormControllerTest.php b/tests/Http/Api/Embeds/ApiEmbedsFormControllerTest.php index be1d48904..37be4a049 100644 --- a/tests/Http/Api/Embeds/ApiEmbedsFormControllerTest.php +++ b/tests/Http/Api/Embeds/ApiEmbedsFormControllerTest.php @@ -17,7 +17,12 @@ $this ->postJson( - route('code16.sharp.api.embed.instance.form.show', [ApiEmbedsFormControllerTestEmbed::$key, 'person', 1]), + route('code16.sharp.api.embed.instance.form.show', [ + 'filterKey' => 'root', + 'embedKey' => ApiEmbedsFormControllerTestEmbed::$key, + 'entityKey' => 'person', + 'instanceId' => 1, + ]), [ 'name' => $name, ] @@ -58,7 +63,12 @@ $this ->postJson( - route('code16.sharp.api.embed.instance.form.show', [ApiEmbedsFormControllerTestEmbed::$key, 'person', 1]), + route('code16.sharp.api.embed.instance.form.show', [ + 'filterKey' => 'root', + 'embedKey' => ApiEmbedsFormControllerTestEmbed::$key, + 'entityKey' => 'person', + 'instanceId' => 1, + ]), [ 'name' => $name, 'bio' => $bio, @@ -87,13 +97,22 @@ public function entity($user): bool $this ->postJson( - route('code16.sharp.api.embed.instance.form.show', [ApiEmbedsFormControllerTestEmbed::$key, 'person', 1]), + route('code16.sharp.api.embed.instance.form.show', [ + 'filterKey' => 'root', + 'embedKey' => ApiEmbedsFormControllerTestEmbed::$key, + 'entityKey' => 'person', + 'instanceId' => 1, + ]), ) ->assertStatus(403); $this ->postJson( - route('code16.sharp.api.embed.form.show', [ApiEmbedsFormControllerTestEmbed::$key, 'person']), + route('code16.sharp.api.embed.form.show', [ + 'filterKey' => 'root', + 'embedKey' => ApiEmbedsFormControllerTestEmbed::$key, + 'entityKey' => 'person', + ]), ) ->assertStatus(403); }); @@ -109,19 +128,33 @@ public function view($user, $instanceId): bool $this ->postJson( - route('code16.sharp.api.embed.instance.form.show', [ApiEmbedsFormControllerTestEmbed::$key, 'person', 1]), + route('code16.sharp.api.embed.instance.form.show', [ + 'filterKey' => 'root', + 'embedKey' => ApiEmbedsFormControllerTestEmbed::$key, + 'entityKey' => 'person', + 'instanceId' => 1, + ]), ) ->assertForbidden(); $this ->postJson( - route('code16.sharp.api.embed.instance.form.show', [ApiEmbedsFormControllerTestEmbed::$key, 'person', 2]), + route('code16.sharp.api.embed.instance.form.show', [ + 'filterKey' => 'root', + 'embedKey' => ApiEmbedsFormControllerTestEmbed::$key, + 'entityKey' => 'person', + 'instanceId' => 2, + ]), ) ->assertOk(); $this ->postJson( - route('code16.sharp.api.embed.form.show', [ApiEmbedsFormControllerTestEmbed::$key, 'person']), + route('code16.sharp.api.embed.form.show', [ + 'filterKey' => 'root', + 'embedKey' => ApiEmbedsFormControllerTestEmbed::$key, + 'entityKey' => 'person', + ]), ) ->assertOk(); }); @@ -132,7 +165,12 @@ public function view($user, $instanceId): bool $this ->postJson( - route('code16.sharp.api.embed.instance.form.update', [ApiEmbedsFormControllerTestEmbed::$key, 'person', 1]), + route('code16.sharp.api.embed.instance.form.update', [ + 'filterKey' => 'root', + 'embedKey' => ApiEmbedsFormControllerTestEmbed::$key, + 'entityKey' => 'person', + 'instanceId' => 1, + ]), [ 'name' => $name, 'bio' => ['text' => $bio], @@ -149,7 +187,12 @@ public function view($user, $instanceId): bool it('validates data when updating an embed', function () { $this ->postJson( - route('code16.sharp.api.embed.instance.form.update', [ApiEmbedsFormControllerTestEmbed::$key, 'person', 1]), + route('code16.sharp.api.embed.instance.form.update', [ + 'filterKey' => 'root', + 'embedKey' => ApiEmbedsFormControllerTestEmbed::$key, + 'entityKey' => 'person', + 'instanceId' => 1, + ]), [ 'name' => null, 'bio' => ['text' => 'aaa'], diff --git a/tests/Http/Api/SearchControllerTest.php b/tests/Http/Api/SearchControllerTest.php index 252045229..1459a8cf9 100644 --- a/tests/Http/Api/SearchControllerTest.php +++ b/tests/Http/Api/SearchControllerTest.php @@ -27,7 +27,7 @@ public function searchFor(array $terms): void ); $this - ->getJson('/sharp/api/search?q=some-search') + ->getJson('/sharp/api/root/search?q=some-search') ->assertJson([ [ 'label' => 'People', @@ -59,7 +59,7 @@ public function searchFor(array $terms): void } ); - $this->getJson('/sharp/api/search?q=some-search') + $this->getJson('/sharp/api/root/search?q=some-search') ->assertJson( [ [ @@ -83,7 +83,7 @@ public function searchFor(array $terms): void } ); - $this->getJson('/sharp/api/search?q=some-search') + $this->getJson('/sharp/api/root/search?q=some-search') ->assertJson( [ [ @@ -112,7 +112,7 @@ public function searchFor(array $terms): void } ); - $this->getJson('/sharp/api/search?q=bb') + $this->getJson('/sharp/api/root/search?q=bb') ->assertJson( [ [ @@ -145,7 +145,7 @@ public function searchFor(array $terms): void } ); - $this->getJson('/sharp/api/search?q=some-search') + $this->getJson('/sharp/api/root/search?q=some-search') ->assertJson( [ [ @@ -194,7 +194,7 @@ public function searchFor(array $terms): void } ); - $this->getJson('/sharp/api/search?q=john+%20wayne%20') + $this->getJson('/sharp/api/root/search?q=john+%20wayne%20') ->assertJsonFragment([ 'label' => 'John Wayne', ]); @@ -204,7 +204,7 @@ public function searchFor(array $terms): void sharp()->config()->disableGlobalSearch(); $this - ->getJson('/sharp/api/search?q=some-search') + ->getJson('/sharp/api/root/search?q=some-search') ->assertNotFound(); }); @@ -225,12 +225,12 @@ public function authorize(): bool ); $this - ->getJson('/sharp/api/search?q=some-search') + ->getJson('/sharp/api/root/search?q=some-search') ->assertForbidden(); $this ->actingAs(User::make(['email' => 'authorized-user@test.fr'])) - ->getJson('/sharp/api/search?q=some-search') + ->getJson('/sharp/api/root/search?q=some-search') ->assertOk(); }); diff --git a/tests/Http/Auth/ChangePasswordCommandTraitTest.php b/tests/Http/Auth/ChangePasswordCommandTraitTest.php index 1653bc36b..90ba2d8f0 100644 --- a/tests/Http/Auth/ChangePasswordCommandTraitTest.php +++ b/tests/Http/Auth/ChangePasswordCommandTraitTest.php @@ -41,6 +41,7 @@ protected function executeSingle(array $data): array // Fetch the command form (single show variant) $this ->getJson(route('code16.sharp.api.show.command.singleInstance.form', [ + 'filterKey' => 'root', 'entityKey' => 'single-person', 'commandKey' => 'change_password', ])) @@ -84,6 +85,7 @@ protected function executeSingle(array $data): array // Form contains the confirmation field $this ->getJson(route('code16.sharp.api.show.command.singleInstance.form', [ + 'filterKey' => 'root', 'entityKey' => 'single-person', 'commandKey' => 'change_password_confirm', ])) @@ -98,7 +100,11 @@ protected function executeSingle(array $data): array // Fails when confirmation is missing/mismatch $this - ->postJson(route('code16.sharp.api.show.command.instance', ['single-person', 'change_password_confirm']), [ + ->postJson(route('code16.sharp.api.show.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'single-person', + 'commandKey' => 'change_password_confirm', + ]), [ 'data' => [ 'password' => 'secret', 'new_password' => 'Password1', // missing confirmation @@ -109,7 +115,11 @@ protected function executeSingle(array $data): array // Fails when password rule is not satisfied (requires number) $this - ->postJson(route('code16.sharp.api.show.command.instance', ['single-person', 'change_password_confirm']), [ + ->postJson(route('code16.sharp.api.show.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'single-person', + 'commandKey' => 'change_password_confirm', + ]), [ 'data' => [ 'password' => 'secret', 'new_password' => 'Password!', @@ -121,7 +131,11 @@ protected function executeSingle(array $data): array // Succeeds with valid data $this - ->postJson(route('code16.sharp.api.show.command.instance', ['single-person', 'change_password_confirm']), [ + ->postJson(route('code16.sharp.api.show.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'single-person', + 'commandKey' => 'change_password_confirm', + ]), [ 'data' => [ 'password' => 'secret', 'new_password' => 'Password1!', @@ -158,6 +172,7 @@ protected function executeSingle(array $data): array // Form does not contain the current password field $this ->getJson(route('code16.sharp.api.show.command.singleInstance.form', [ + 'filterKey' => 'root', 'entityKey' => 'single-person', 'commandKey' => 'change_password_confirm', ])) @@ -171,7 +186,11 @@ protected function executeSingle(array $data): array // Succeeds with valid data $this - ->postJson(route('code16.sharp.api.show.command.instance', ['single-person', 'change_password_confirm']), [ + ->postJson(route('code16.sharp.api.show.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'single-person', + 'commandKey' => 'change_password_confirm', + ]), [ 'data' => [ 'new_password' => 'Password1!', ], @@ -201,7 +220,11 @@ protected function executeSingle(array $data): array // Trigger 3 attempts (invalid to keep trying) for ($i = 0; $i < 3; $i++) { $this - ->postJson(route('code16.sharp.api.show.command.instance', ['single-person', 'change_password_rl']), [ + ->postJson(route('code16.sharp.api.show.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'single-person', + 'commandKey' => 'change_password_rl', + ]), [ 'data' => [ // missing fields triggers validation and consumes an attempt ], @@ -211,7 +234,11 @@ protected function executeSingle(array $data): array // 4th attempt should be blocked by rate limiter with SharpApplicativeException (417) $this - ->postJson(route('code16.sharp.api.show.command.instance', ['single-person', 'change_password_rl']), [ + ->postJson(route('code16.sharp.api.show.command.instance', [ + 'filterKey' => 'root', + 'entityKey' => 'single-person', + 'commandKey' => 'change_password_rl', + ]), [ 'data' => [ // still invalid ], diff --git a/tests/Http/GlobalFilterRoutesTest.php b/tests/Http/GlobalFilterRoutesTest.php index 3de5529db..11cbff813 100644 --- a/tests/Http/GlobalFilterRoutesTest.php +++ b/tests/Http/GlobalFilterRoutesTest.php @@ -1,8 +1,12 @@ config()->declareEntity(PersonEntity::class); @@ -49,6 +53,38 @@ expect(sharp()->context()->globalFilterValue('test'))->toEqual('one'); }); +it('sets the current filterKey according to the URL for API routes', function () { + fakeGlobalFilter(); + fakeListFor('person', new class() extends PersonList + { + protected function getEntityCommands(): ?array + { + return [ + 'cmd' => new class() extends EntityCommand + { + public function label(): ?string + { + return 'entity'; + } + + public function buildFormFields(FieldsContainer $formFields): void + { + $formFields->addField(SharpFormTextField::make('name')); + } + + public function execute(array $data = []): array {} + }, + ]; + } + }); + + $this + ->getJson('/sharp/api/one/list/person/command/cmd/form') + ->assertOk(); + + expect(sharp()->context()->globalFilterValue('test'))->toEqual('one'); +}); + it('redirects to the homepage if an invalid filterKey is set in the URL', function () { fakeGlobalFilter();