Erlaube Seiten unter mehrteiligen Adressen und reserviere die Pfade fester Routen
- Auffangroute und Pfadprüfung nehmen beliebig tiefe Adressen (/kurse/kinder) an; die Elternseite muss nicht existieren. - ReservedPaths sperrt jeden ersten Pfadteil fester Routen und des Ordners public/ (zur Laufzeit aus dem Router); frei bleiben nur /, /shop und /angebote. Eine bestehende Seite mit unverändertem Pfad bleibt speicherbar. - Menü: Eintrag im aktiven Pfad, wenn die aktuelle Seite unter seinem Ziel liegt. - Verwaltung: Hilfetext und Hinweis am Adressfeld, Sortierung nach Pfadteilen in Webpräsenz und Seitenauswahlen, Chip "Unterseite von ...". - ShopSwitchTest: Ein POST auf die entfernte Kaufadresse ergibt nun 405 statt 404, weil die Auffangroute die mehrteilige Adresse trifft (bei einteiligen Adressen schon bisher so). Keine Bestellung entsteht weiterhin; Begründung in ADR-72. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb9b203ecf
commit
6fcd3e39e9
11 files changed
+612
-30
No files matched your search
@@ -7,10 +7,11 @@
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class PageService
|
||||
{
|
||||
public function __construct(private readonly PageSections $sections) {}
|
||||
public function __construct(private readonly PageSections $sections, private readonly ReservedPaths $reserved) {}
|
||||
|
||||
/**
|
||||
* Speichert einen Entwurf als neue Revision. Veröffentlicht nichts.
|
||||
@@ -88,12 +89,20 @@ public function duplicate(Page $source, string $path, ?User $author): Page
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalisiert den Pfad und prüft, dass keine andere Seite ihn verwendet.
|
||||
* Normalisiert den Pfad und prüft, dass er keiner festen Funktion der Anwendung gehört und keine andere Seite ihn verwendet.
|
||||
*/
|
||||
public function availablePath(string $path, ?Page $except = null): string
|
||||
{
|
||||
$path = $this->normalizePath($path);
|
||||
|
||||
// Eine bestehende Seite mit unverändertem Pfad bleibt speicherbar, auch wenn ihr Pfad später reserviert wurde
|
||||
// (sie ist dann nur nicht erreichbar); geprüft wird, wenn der Pfad neu vergeben oder geändert wird.
|
||||
if ($except?->path !== $path && $this->reserved->blocks($path)) {
|
||||
throw ValidationException::withMessages([
|
||||
'path' => 'Diese Adresse gehört zu einer festen Funktion der Anwendung ('.PagePath::segments($path)[0].') und kann keine Seite sein.',
|
||||
]);
|
||||
}
|
||||
|
||||
$taken = Page::query()
|
||||
->where('path', $path)
|
||||
->when($except !== null, fn ($query) => $query->whereKeyNot($except->getKey()))
|
||||
@@ -110,21 +119,26 @@ public function availablePath(string $path, ?Page $except = null): string
|
||||
|
||||
public function normalizePath(string $path): string
|
||||
{
|
||||
$path = '/'.trim($path, '/');
|
||||
try {
|
||||
return PagePath::normalize($path);
|
||||
} catch (InvalidArgumentException $exception) {
|
||||
throw ValidationException::withMessages(['path' => $exception->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($path === '/') {
|
||||
return '/';
|
||||
/**
|
||||
* Adresse der übergeordneten Stufe, an der keine Seite liegt (für einen Hinweis am Adressfeld); null, wenn dort eine
|
||||
* Seite liegt oder es keine Zwischenstufe gibt. Die Zwischenstufe muss keine Seite sein, sie ergibt dann 404.
|
||||
*/
|
||||
public function missingParent(string $path): ?string
|
||||
{
|
||||
$parent = PagePath::parent($path);
|
||||
|
||||
if ($parent === null || $parent === '/') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$path = mb_strtolower($path);
|
||||
|
||||
if (preg_match('#^/[a-z0-9]+(?:-[a-z0-9]+)*$#', $path) !== 1) {
|
||||
throw ValidationException::withMessages([
|
||||
'path' => 'Der Pfad darf nur Kleinbuchstaben, Ziffern und Bindestriche enthalten.',
|
||||
]);
|
||||
}
|
||||
|
||||
return $path;
|
||||
return Page::query()->where('path', $parent)->exists() ? null : $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user