Stelle das U0-Fundament mit CMS, Mitgliedern und Filament bereit.
Deploy Test / test (push) Successful in 2m25s
Deploy Test / deploy (push) Failing after 25s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-15 08:32:14 +01:00
1 parent 89b35ac480
commit 2035c46edd
130 files changed
+18519 -50

No files matched your search

+181
View File
@@ -0,0 +1,181 @@
<?php
namespace App\Domain\Cms\Blocks;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
class BlockRegistry
{
/**
* @return array<string, string>
*/
public function labels(): array
{
return [
'heading' => 'Überschrift und Einleitung',
'prose' => 'Fließtext',
'image_text' => 'Bild und Text',
'call_to_action' => 'Handlungsaufruf',
'cards' => 'Karten',
'faq' => 'FAQ',
];
}
/**
* @param list<array<string, mixed>> $blocks
* @return list<array<string, mixed>>
*/
public function normalize(array $blocks): array
{
$normalized = [];
foreach (array_values($blocks) as $index => $block) {
if (! is_array($block)) {
throw ValidationException::withMessages([
"blocks.$index" => 'Ein Baustein ist unvollständig.',
]);
}
$type = $block['type'] ?? null;
if (! is_string($type) || ! array_key_exists($type, $this->labels())) {
throw ValidationException::withMessages([
"blocks.$index.type" => 'Dieser Bausteintyp ist nicht freigegeben.',
]);
}
$normalized[] = $this->normalizeOne($type, $block, $index);
}
return $normalized;
}
/**
* @param array<string, mixed> $block
* @return array<string, mixed>
*/
private function normalizeOne(string $type, array $block, int $index): array
{
$rules = match ($type) {
'heading' => [
'heading' => ['required', 'string', 'max:200'],
'intro' => ['nullable', 'string', 'max:1000'],
],
'prose' => [
'body' => ['required', 'string', 'max:20000'],
],
'image_text' => [
'image' => ['nullable', 'string', 'max:255'],
'alt' => ['required', 'string', 'max:300'],
'body' => ['required', 'string', 'max:5000'],
],
'call_to_action' => [
'heading' => ['required', 'string', 'max:200'],
'text' => ['nullable', 'string', 'max:1000'],
'label' => ['required', 'string', 'max:80'],
'url' => ['required', 'string', 'max:500'],
],
'cards' => [
'items' => ['required', 'array', 'min:1', 'max:6'],
'items.*.title' => ['required', 'string', 'max:120'],
'items.*.text' => ['nullable', 'string', 'max:500'],
'items.*.url' => ['nullable', 'string', 'max:500'],
],
'faq' => [
'items' => ['required', 'array', 'min:1', 'max:20'],
'items.*.question' => ['required', 'string', 'max:300'],
'items.*.answer' => ['required', 'string', 'max:2000'],
],
default => [],
};
$validator = Validator::make($block, $rules);
if ($validator->fails()) {
$messages = [];
foreach ($validator->errors()->messages() as $key => $errors) {
$messages["blocks.$index.$key"] = $errors;
}
throw ValidationException::withMessages($messages);
}
$clean = ['type' => $type];
foreach (array_keys($rules) as $key) {
if (str_contains($key, '.*')) {
continue;
}
$clean[$key] = $block[$key] ?? null;
}
if ($type === 'image_text') {
$clean['image'] = $this->imagePath($clean['image'] ?? null, $index);
}
if (in_array($type, ['call_to_action', 'cards'], true)) {
$clean = $this->assertSafeUrls($clean, $index);
}
return $clean;
}
private function imagePath(mixed $image, int $index): ?string
{
if (is_array($image)) {
$image = $image[0] ?? null;
}
if ($image === null || $image === '') {
return null;
}
if (! is_string($image) || str_contains($image, '..') || ! str_starts_with($image, 'cms/')) {
throw ValidationException::withMessages([
"blocks.$index.image" => 'Das Bild liegt nicht im öffentlichen Medienbereich.',
]);
}
return $image;
}
/**
* @param array<string, mixed> $block
* @return array<string, mixed>
*/
private function assertSafeUrls(array $block, int $index): array
{
if (array_key_exists('url', $block)) {
$block['url'] = $this->safeUrl($block['url'], "blocks.$index.url");
}
if (isset($block['items']) && is_array($block['items'])) {
foreach ($block['items'] as $itemIndex => $item) {
if (is_array($item) && filled($item['url'] ?? null)) {
$block['items'][$itemIndex]['url'] = $this->safeUrl($item['url'], "blocks.$index.items.$itemIndex.url");
}
}
}
return $block;
}
private function safeUrl(mixed $url, string $key): string
{
if (! is_string($url)) {
throw ValidationException::withMessages([$key => 'Die Adresse ist ungültig.']);
}
$isRelative = str_starts_with($url, '/') && ! str_starts_with($url, '//');
$isAbsolute = preg_match('#^https?://#i', $url) === 1;
if (! $isRelative && ! $isAbsolute) {
throw ValidationException::withMessages([$key => 'Erlaubt sind Seitenpfade oder http(s)-Adressen.']);
}
return $url;
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace App\Domain\Cms;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class NavigationItem extends Model
{
protected $fillable = [
'label',
'page_id',
'url',
'placement',
'sort_order',
];
public function page(): BelongsTo
{
return $this->belongsTo(Page::class);
}
public function href(): ?string
{
if ($this->page !== null) {
return $this->page->path === '/' ? url('/') : url($this->page->path);
}
if ($this->url === null || $this->url === '') {
return null;
}
if (str_starts_with($this->url, '/') && ! str_starts_with($this->url, '//')) {
return url($this->url);
}
return $this->url;
}
}
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace App\Domain\Cms;
use App\Domain\Identity\StaffRole;
use App\Models\User;
class NavigationItemPolicy
{
public function viewAny(User $user): bool
{
return $user->hasStaffRole(StaffRole::Redakteur);
}
public function view(User $user, NavigationItem $item): bool
{
return $this->viewAny($user);
}
public function create(User $user): bool
{
return $this->viewAny($user);
}
public function update(User $user, NavigationItem $item): bool
{
return $this->viewAny($user);
}
public function delete(User $user, NavigationItem $item): bool
{
return $this->viewAny($user);
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace App\Domain\Cms;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
class Page extends Model
{
protected $fillable = [
'path',
];
public function revisions(): HasMany
{
return $this->hasMany(PageRevision::class)->latest('id');
}
public function publishedRevision(): BelongsTo
{
return $this->belongsTo(PageRevision::class, 'published_revision_id');
}
public function latestRevision(): HasOne
{
return $this->hasOne(PageRevision::class)->latestOfMany();
}
public function navigationItems(): HasMany
{
return $this->hasMany(NavigationItem::class);
}
public function isPublished(): bool
{
return $this->published_revision_id !== null;
}
public function publicUrl(): string
{
return $this->path === '/' ? url('/') : url($this->path);
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace App\Domain\Cms;
use App\Domain\Identity\StaffRole;
use App\Models\User;
class PagePolicy
{
public function viewAny(User $user): bool
{
return $user->hasStaffRole(StaffRole::Redakteur);
}
public function view(User $user, Page $page): bool
{
return $this->viewAny($user);
}
public function create(User $user): bool
{
return $this->viewAny($user);
}
public function update(User $user, Page $page): bool
{
return $this->viewAny($user);
}
public function publish(User $user, Page $page): bool
{
return $this->viewAny($user);
}
public function delete(User $user, Page $page): bool
{
return false;
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Domain\Cms;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PageRevision extends Model
{
public const UPDATED_AT = null;
protected $fillable = [
'page_id',
'blocks',
'seo_title',
'seo_description',
'created_by',
];
protected function casts(): array
{
return [
'blocks' => 'array',
'created_at' => 'datetime',
];
}
public function page(): BelongsTo
{
return $this->belongsTo(Page::class);
}
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
}
+84
View File
@@ -0,0 +1,84 @@
<?php
namespace App\Domain\Cms;
use App\Domain\Cms\Blocks\BlockRegistry;
use App\Jobs\PublishPublicMedia;
use App\Models\User;
use Illuminate\Validation\ValidationException;
class PageService
{
public function __construct(private readonly BlockRegistry $blocks) {}
/**
* @param list<array<string, mixed>> $blocks
*/
public function saveRevision(Page $page, array $blocks, ?string $seoTitle, ?string $seoDescription, ?User $author): PageRevision
{
$normalized = $this->blocks->normalize($blocks);
$revision = $page->revisions()->create([
'blocks' => $normalized,
'seo_title' => $seoTitle !== null && $seoTitle !== '' ? $seoTitle : null,
'seo_description' => $seoDescription !== null && $seoDescription !== '' ? $seoDescription : null,
'created_by' => $author?->id,
]);
foreach ($normalized as $block) {
if (($block['type'] ?? null) === 'image_text' && filled($block['image'] ?? null)) {
PublishPublicMedia::dispatch($block['image']);
}
}
return $revision;
}
public function publish(Page $page, PageRevision $revision): void
{
if ($revision->page_id !== $page->id) {
throw ValidationException::withMessages([
'revision' => 'Die Revision gehört zu einer anderen Seite.',
]);
}
$page->published_revision_id = $revision->id;
$page->save();
}
public function restore(Page $page, PageRevision $source, ?User $author): PageRevision
{
if ($source->page_id !== $page->id) {
throw ValidationException::withMessages([
'revision' => 'Die Revision gehört zu einer anderen Seite.',
]);
}
return $this->saveRevision(
$page,
$source->blocks,
$source->seo_title,
$source->seo_description,
$author,
);
}
public function normalizePath(string $path): string
{
$path = '/'.trim($path, '/');
if ($path === '/') {
return '/';
}
$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;
}
}