Skip to content

Commit 05cf98d

Browse files
committed
Add {filterKey} on all web routes, fix tests
1 parent f53ecd7 commit 05cf98d

22 files changed

Lines changed: 139 additions & 100 deletions

demo/app/Providers/DemoSharpServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Sharp\AppSearchEngine;
88
use App\Sharp\Demo2faNotificationHandler;
99
use App\Sharp\DummyGlobalFilter;
10+
use App\Sharp\DummyGlobalFilter2;
1011
use App\Sharp\SharpMenu;
1112
use Code16\Sharp\Config\SharpConfigBuilder;
1213
use Code16\Sharp\SharpAppServiceProvider;
@@ -19,6 +20,7 @@ protected function configureSharp(SharpConfigBuilder $config): void
1920
->setName('Demo project')
2021
->discoverEntities()
2122
->addGlobalFilter(DummyGlobalFilter::class)
23+
->addGlobalFilter(DummyGlobalFilter2::class)
2224
->configureUploadsThumbnailCreation(uploadModelClass: Media::class)
2325
->setSharpMenu(SharpMenu::class)
2426
->setThemeColor('#004c9b')
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Sharp;
4+
5+
use Code16\Sharp\Filters\GlobalRequiredFilter;
6+
7+
class DummyGlobalFilter2 extends GlobalRequiredFilter
8+
{
9+
public function values(): array
10+
{
11+
return [
12+
'fr' => 'Français',
13+
'de' => 'Allemand',
14+
];
15+
}
16+
17+
public function defaultValue(): mixed
18+
{
19+
return 'de';
20+
}
21+
22+
public function authorize(): bool
23+
{
24+
return auth()->id() === 1;
25+
}
26+
}

src/Http/Context/SharpBreadcrumb.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,8 @@ protected function getSegmentsFromRequest(): Collection
319319
->values();
320320
}
321321

322-
if (request()->isMethod('GET')) {
323-
// Have to skip /sharp/{filterKey}
324-
return collect(request()->segments())->skip(2)->values();
325-
}
326-
327-
// Have to skip /sharp
328-
return collect(request()->segments())->skip(1)->values();
322+
// Have to skip /sharp/{filterKey}
323+
return collect(request()->segments())->skip(2)->values();
329324
}
330325

331326
public function forceRequestSegments(array|Collection $segments): void

src/Http/Controllers/Api/DownloadController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class DownloadController extends ApiController
88
{
9-
public function show(string $entityKey, ?string $instanceId = null)
9+
public function show(string $filterKey, string $entityKey, ?string $instanceId = null)
1010
{
1111
$this->authorizationManager->check('view', $entityKey, $instanceId);
1212

src/Http/Controllers/DashboardFiltersController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class DashboardFiltersController extends SharpProtectedController
66
{
7-
public function store(string $dashboardKey)
7+
public function store(string $filterKey, string $dashboardKey)
88
{
99
$this->authorizationManager->check('entity', $dashboardKey);
1010

src/Http/Controllers/EntityListFiltersController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class EntityListFiltersController extends SharpProtectedController
66
{
7-
public function store(string $entityKey)
7+
public function store(string $filterKey, string $entityKey)
88
{
99
$this->authorizationManager->check('entity', $entityKey);
1010

@@ -13,7 +13,7 @@ public function store(string $entityKey)
1313
// in case it is built in the functional code (buildListConfig() for instance)
1414
sharp()->context()->breadcrumb()->forceRequestSegments(
1515
collect(request()->segments())
16-
->slice(1, -1)
16+
->slice(2, -1)
1717
->values()
1818
);
1919

src/Http/Controllers/FormController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function edit(string $filterKey, string $parentUri, EntityKey $entityKey,
114114
]);
115115
}
116116

117-
public function update(string $parentUri, EntityKey $entityKey, ?string $instanceId = null)
117+
public function update(string $filterKey, string $parentUri, EntityKey $entityKey, ?string $instanceId = null)
118118
{
119119
$this->authorizationManager->check('update', $entityKey, $instanceId);
120120

@@ -142,15 +142,15 @@ public function update(string $parentUri, EntityKey $entityKey, ?string $instanc
142142
return redirect()->to($this->previousUrlWithHighlightedQuery($previousUrl, $entityKey, $instanceId));
143143
}
144144

145-
public function store(string $parentUri, EntityKey $entityKey)
145+
public function store(string $filterKey, string $parentUri, EntityKey $entityKey)
146146
{
147147
$form = $this->entityManager
148148
->entityFor($entityKey)
149149
->getFormOrFail($entityKey->multiformKey());
150150

151151
if ($form instanceof SharpSingleForm) {
152152
// There is no creation in SingleForms
153-
return $this->update($parentUri, $entityKey);
153+
return $this->update($filterKey, $parentUri, $entityKey);
154154
}
155155

156156
$this->authorizationManager->check('create', $entityKey);

src/Http/Controllers/GlobalFilterController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
class GlobalFilterController extends SharpProtectedController
1010
{
11-
public function update(string $filterKey, GlobalFilters $globalFilters): RedirectResponse
11+
public function update(string $filterKey, string $key, GlobalFilters $globalFilters): RedirectResponse
1212
{
13-
$handler = $globalFilters->findFilter($filterKey);
13+
$handler = $globalFilters->findFilter($key);
1414

1515
abort_if(! $handler instanceof GlobalRequiredFilter, 404);
1616

src/Http/Controllers/ShowController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function show(string $filterKey, string $parentUri, EntityKey $entityKey,
6666
]);
6767
}
6868

69-
public function delete(string $parentUri, string $entityKey, string $instanceId)
69+
public function delete(string $filterKey, string $parentUri, string $entityKey, string $instanceId)
7070
{
7171
$this->authorizationManager->check('delete', $entityKey, $instanceId);
7272

src/Http/Middleware/HandleGlobalFilters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function __construct(private GlobalFilters $globalFiltersHandler) {}
1414

1515
public function handle(Request $request, Closure $next)
1616
{
17-
if ($request->isMethod('GET') && ($filterKey = $request->route('filterKey'))) {
17+
if ($filterKey = $request->route('filterKey')) {
1818
$filterKeys = explode(GlobalFilters::$valuesUrlSeparator, $filterKey);
1919

2020
if ($this->globalFiltersHandler->isEnabled()

0 commit comments

Comments
 (0)