Stelle das U0-Fundament mit CMS, Mitgliedern und Filament bereit.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
89b35ac480
commit
2035c46edd
130 files changed
+18519
-50
No files matched your search
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Domain\Identity\AssignStaffRoles;
|
||||
use App\Domain\Identity\RegisterAccount;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateStaffUser extends Command
|
||||
{
|
||||
protected $signature = 'luf:personal {email} {--role=systemverwalter} {--name=Personal}';
|
||||
|
||||
protected $description = 'Legt ein bestätigtes Personalkonto an und gibt das Passwort einmal aus';
|
||||
|
||||
public function handle(RegisterAccount $register, AssignStaffRoles $assign): int
|
||||
{
|
||||
$role = StaffRole::tryFrom((string) $this->option('role'));
|
||||
|
||||
if ($role === null) {
|
||||
$this->error('Unbekannte Rolle.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$password = Str::password(20);
|
||||
$user = $register->register((string) $this->option('name'), (string) $this->argument('email'), $password, true);
|
||||
$user->markEmailAsVerified();
|
||||
$assign->sync($user, [$role->value], $user);
|
||||
|
||||
$this->info('Konto angelegt. Passwort (nur diese Ausgabe):');
|
||||
$this->line($password);
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Identity;
|
||||
|
||||
enum AccountStatus: string
|
||||
{
|
||||
case Aktiv = 'aktiv';
|
||||
case Gesperrt = 'gesperrt';
|
||||
case Geloescht = 'geloescht';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Aktiv => 'Aktiv',
|
||||
self::Gesperrt => 'Gesperrt',
|
||||
self::Geloescht => 'Gelöscht',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Identity;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class AssignStaffRoles
|
||||
{
|
||||
/**
|
||||
* @param list<string> $roles
|
||||
*/
|
||||
public function sync(User $user, array $roles, User $actor): void
|
||||
{
|
||||
$roles = array_values(array_unique($roles));
|
||||
|
||||
foreach ($roles as $role) {
|
||||
if (StaffRole::tryFrom($role) === null) {
|
||||
throw ValidationException::withMessages([
|
||||
'roles' => 'Unbekannte Personalrolle.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
$actor->hasStaffRole(StaffRole::Systemverwalter)
|
||||
&& $user->is($actor)
|
||||
&& ! in_array(StaffRole::Systemverwalter->value, $roles, true)
|
||||
) {
|
||||
throw ValidationException::withMessages([
|
||||
'roles' => 'Das eigene Systemverwalter-Recht bleibt bestehen.',
|
||||
]);
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($user, $roles): void {
|
||||
$user->staffRoles()->delete();
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$user->staffRoles()->create(['role' => $role]);
|
||||
}
|
||||
});
|
||||
|
||||
$user->unsetRelation('staffRoles');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Identity;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class Party extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'type',
|
||||
'display_name',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'type' => PartyType::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): HasOne
|
||||
{
|
||||
return $this->hasOne(User::class);
|
||||
}
|
||||
|
||||
public function profile(): HasOne
|
||||
{
|
||||
return $this->hasOne(Profile::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Identity;
|
||||
|
||||
enum PartyType: string
|
||||
{
|
||||
case Person = 'person';
|
||||
case Organisation = 'organisation';
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Identity;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Profile extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'party_id',
|
||||
'display_name',
|
||||
'visibility',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'visibility' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function party(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Party::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Identity;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class RegisterAccount
|
||||
{
|
||||
public function register(string $name, string $email, string $password, bool $adult): User
|
||||
{
|
||||
if (! $adult) {
|
||||
throw ValidationException::withMessages([
|
||||
'adult' => 'Die Plattform richtet sich an Erwachsene. Ein Konto setzt die Bestätigung voraus.',
|
||||
]);
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($name, $email, $password): User {
|
||||
$party = Party::query()->create([
|
||||
'type' => PartyType::Person,
|
||||
'display_name' => $name,
|
||||
]);
|
||||
|
||||
Profile::query()->create([
|
||||
'party_id' => $party->id,
|
||||
'display_name' => $name,
|
||||
'visibility' => ['display_name' => 'private'],
|
||||
]);
|
||||
|
||||
return User::query()->create([
|
||||
'party_id' => $party->id,
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'status' => AccountStatus::Aktiv,
|
||||
'confirmed_adult_at' => now(),
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Identity;
|
||||
|
||||
enum StaffRole: string
|
||||
{
|
||||
case Redakteur = 'redakteur';
|
||||
case Fachpruefer = 'fachpruefer';
|
||||
case Katalogverwalter = 'katalogverwalter';
|
||||
case Kundenbetreuung = 'kundenbetreuung';
|
||||
case Verifikationspruefer = 'verifikationspruefer';
|
||||
case Moderator = 'moderator';
|
||||
case Systemverwalter = 'systemverwalter';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Redakteur => 'Redakteur',
|
||||
self::Fachpruefer => 'Fachprüfer',
|
||||
self::Katalogverwalter => 'Katalogverwalter',
|
||||
self::Kundenbetreuung => 'Kundenbetreuung',
|
||||
self::Verifikationspruefer => 'Verifikationsprüfer',
|
||||
self::Moderator => 'Moderator',
|
||||
self::Systemverwalter => 'Systemverwalter',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function options(): array
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach (self::cases() as $role) {
|
||||
$options[$role->value] = $role->label();
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Identity;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class StaffRoleAssignment extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'role',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'role' => StaffRole::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\NavigationItems;
|
||||
|
||||
use App\Domain\Cms\NavigationItem;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Filament\Resources\NavigationItems\Pages\ManageNavigationItems;
|
||||
use Closure;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class NavigationItemResource extends Resource
|
||||
{
|
||||
protected static ?string $model = NavigationItem::class;
|
||||
|
||||
protected static ?string $navigationLabel = 'Navigation';
|
||||
|
||||
protected static ?string $modelLabel = 'Navigationspunkt';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Navigation';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
TextInput::make('label')->label('Beschriftung')->required()->maxLength(80),
|
||||
Select::make('page_id')
|
||||
->label('Seite')
|
||||
->options(fn (): array => Page::query()->orderBy('path')->pluck('path', 'id')->all())
|
||||
->searchable(),
|
||||
TextInput::make('url')
|
||||
->label('Adresse')
|
||||
->maxLength(500)
|
||||
->rule(function (Get $get): Closure {
|
||||
return function (string $attribute, mixed $value, Closure $fail) use ($get): void {
|
||||
if (blank($get('page_id')) && blank($value)) {
|
||||
$fail('Wählen Sie eine Seite oder eine Adresse.');
|
||||
}
|
||||
};
|
||||
}),
|
||||
Select::make('placement')
|
||||
->label('Platz')
|
||||
->options([
|
||||
'header' => 'Kopfzeile',
|
||||
'footer' => 'Fußzeile',
|
||||
])
|
||||
->required(),
|
||||
TextInput::make('sort_order')->label('Reihenfolge')->numeric()->required()->default(0),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('label')->label('Beschriftung'),
|
||||
TextColumn::make('page.path')->label('Seite'),
|
||||
TextColumn::make('url')->label('Adresse'),
|
||||
TextColumn::make('placement')->label('Platz'),
|
||||
TextColumn::make('sort_order')->label('Reihenfolge')->sortable(),
|
||||
])
|
||||
->defaultSort('sort_order');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ManageNavigationItems::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\NavigationItems\Pages;
|
||||
|
||||
use App\Filament\Resources\NavigationItems\NavigationItemResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManageNavigationItems extends ManageRecords
|
||||
{
|
||||
protected static string $resource = NavigationItemResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pages;
|
||||
|
||||
use App\Domain\Cms\Blocks\BlockRegistry;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Filament\Resources\Pages\Pages\CreatePage;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Filament\Resources\Pages\Pages\ListPages;
|
||||
use App\Filament\Resources\Pages\RelationManagers\RevisionsRelationManager;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class PageResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Page::class;
|
||||
|
||||
protected static ?string $navigationLabel = 'Seiten';
|
||||
|
||||
protected static ?string $modelLabel = 'Seite';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Seiten';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'path';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
$labels = app(BlockRegistry::class)->labels();
|
||||
|
||||
return $schema->components([
|
||||
TextInput::make('path')
|
||||
->label('Pfad')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->helperText('Zum Beispiel / oder /praevention'),
|
||||
TextInput::make('seo_title')
|
||||
->label('SEO-Titel')
|
||||
->maxLength(255),
|
||||
Textarea::make('seo_description')
|
||||
->label('SEO-Beschreibung')
|
||||
->maxLength(500)
|
||||
->columnSpanFull(),
|
||||
Repeater::make('blocks')
|
||||
->label('Bausteine')
|
||||
->schema([
|
||||
Select::make('type')
|
||||
->label('Typ')
|
||||
->options($labels)
|
||||
->required()
|
||||
->live(),
|
||||
TextInput::make('heading')
|
||||
->label('Überschrift')
|
||||
->visible(fn (Get $get): bool => in_array($get('type'), ['heading', 'call_to_action'], true)),
|
||||
Textarea::make('intro')
|
||||
->label('Einleitung')
|
||||
->visible(fn (Get $get): bool => $get('type') === 'heading'),
|
||||
Textarea::make('body')
|
||||
->label('Text')
|
||||
->visible(fn (Get $get): bool => in_array($get('type'), ['prose', 'image_text'], true))
|
||||
->columnSpanFull(),
|
||||
FileUpload::make('image')
|
||||
->label('Bild')
|
||||
->disk('cms_incoming')
|
||||
->directory('cms')
|
||||
->image()
|
||||
->visible(fn (Get $get): bool => $get('type') === 'image_text'),
|
||||
TextInput::make('alt')
|
||||
->label('Alternativtext')
|
||||
->visible(fn (Get $get): bool => $get('type') === 'image_text'),
|
||||
Textarea::make('text')
|
||||
->label('Text')
|
||||
->visible(fn (Get $get): bool => $get('type') === 'call_to_action'),
|
||||
TextInput::make('label')
|
||||
->label('Beschriftung der Aktion')
|
||||
->visible(fn (Get $get): bool => $get('type') === 'call_to_action'),
|
||||
TextInput::make('url')
|
||||
->label('Adresse')
|
||||
->visible(fn (Get $get): bool => $get('type') === 'call_to_action'),
|
||||
Repeater::make('items')
|
||||
->label('Einträge')
|
||||
->visible(fn (Get $get): bool => in_array($get('type'), ['cards', 'faq'], true))
|
||||
->schema([
|
||||
TextInput::make('title')->label('Titel')->visible(fn (Get $get): bool => $get('../../type') === 'cards'),
|
||||
Textarea::make('text')->label('Text')->visible(fn (Get $get): bool => $get('../../type') === 'cards'),
|
||||
TextInput::make('url')->label('Adresse')->visible(fn (Get $get): bool => $get('../../type') === 'cards'),
|
||||
TextInput::make('question')->label('Frage')->visible(fn (Get $get): bool => $get('../../type') === 'faq'),
|
||||
Textarea::make('answer')->label('Antwort')->visible(fn (Get $get): bool => $get('../../type') === 'faq'),
|
||||
]),
|
||||
])
|
||||
->columnSpanFull()
|
||||
->reorderable()
|
||||
->collapsed(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('path')->label('Pfad')->searchable(),
|
||||
TextColumn::make('published_revision_id')
|
||||
->label('Veröffentlicht')
|
||||
->formatStateUsing(fn ($state): string => $state ? 'Ja' : 'Entwurf'),
|
||||
TextColumn::make('updated_at')->label('Geändert')->dateTime('d.m.Y H:i'),
|
||||
])
|
||||
->recordUrl(fn (Page $record): string => static::getUrl('edit', ['record' => $record]));
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RevisionsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListPages::route('/'),
|
||||
'create' => CreatePage::route('/create'),
|
||||
'edit' => EditPage::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pages\Pages;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Filament\Resources\Pages\PageResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CreatePage extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PageResource::class;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
$service = app(PageService::class);
|
||||
$page = Page::query()->create([
|
||||
'path' => $service->normalizePath($data['path']),
|
||||
]);
|
||||
|
||||
$service->saveRevision(
|
||||
$page,
|
||||
$data['blocks'] ?? [],
|
||||
$data['seo_title'] ?? null,
|
||||
$data['seo_description'] ?? null,
|
||||
auth()->user(),
|
||||
);
|
||||
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pages\Pages;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Filament\Resources\Pages\PageResource;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EditPage extends EditRecord
|
||||
{
|
||||
protected static string $resource = PageResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('preview')
|
||||
->label('Vorschau')
|
||||
->url(function (): string {
|
||||
$revision = $this->record->latestRevision;
|
||||
|
||||
return $revision === null
|
||||
? '#'
|
||||
: route('pages.preview', $revision);
|
||||
})
|
||||
->openUrlInNewTab(),
|
||||
Action::make('publish')
|
||||
->label('Veröffentlichen')
|
||||
->requiresConfirmation()
|
||||
->visible(fn (): bool => auth()->user()?->can('publish', $this->record) ?? false)
|
||||
->action(function (PageService $service): void {
|
||||
$revision = $this->record->latestRevision;
|
||||
abort_if($revision === null, 404);
|
||||
$service->publish($this->record, $revision);
|
||||
$this->record->refresh();
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$revision = $this->record->latestRevision ?? $this->record->publishedRevision;
|
||||
$data['blocks'] = $revision?->blocks ?? [];
|
||||
$data['seo_title'] = $revision?->seo_title;
|
||||
$data['seo_description'] = $revision?->seo_description;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
{
|
||||
/** @var Page $record */
|
||||
$service = app(PageService::class);
|
||||
$record->update([
|
||||
'path' => $service->normalizePath($data['path']),
|
||||
]);
|
||||
|
||||
$service->saveRevision(
|
||||
$record,
|
||||
$data['blocks'] ?? [],
|
||||
$data['seo_title'] ?? null,
|
||||
$data['seo_description'] ?? null,
|
||||
auth()->user(),
|
||||
);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pages\Pages;
|
||||
|
||||
use App\Filament\Resources\Pages\PageResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPages extends ListRecords
|
||||
{
|
||||
protected static string $resource = PageResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pages\RelationManagers;
|
||||
|
||||
use App\Domain\Cms\PageRevision;
|
||||
use App\Domain\Cms\PageService;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class RevisionsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'revisions';
|
||||
|
||||
protected static ?string $title = 'Revisionen';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')->label('Nr.'),
|
||||
TextColumn::make('created_at')->label('Gespeichert')->dateTime('d.m.Y H:i'),
|
||||
TextColumn::make('author.name')->label('Von'),
|
||||
TextColumn::make('published')
|
||||
->label('Live')
|
||||
->state(fn (PageRevision $record): string => $record->id === $this->getOwnerRecord()->published_revision_id ? 'Ja' : 'Nein'),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('publish')
|
||||
->label('Veröffentlichen')
|
||||
->requiresConfirmation()
|
||||
->visible(fn (): bool => auth()->user()?->can('publish', $this->getOwnerRecord()) ?? false)
|
||||
->action(function (PageRevision $record, PageService $service): void {
|
||||
$service->publish($this->getOwnerRecord(), $record);
|
||||
$this->getOwnerRecord()->refresh();
|
||||
}),
|
||||
Action::make('restore')
|
||||
->label('Wiederherstellen')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Es entsteht eine neue Revision. Die Live-Seite bleibt unverändert, bis sie veröffentlicht wird.')
|
||||
->action(function (PageRevision $record, PageService $service): void {
|
||||
$service->restore($this->getOwnerRecord(), $record, auth()->user());
|
||||
}),
|
||||
])
|
||||
->defaultSort('id', 'desc');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users\Pages;
|
||||
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CreateUser extends CreateRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
return UserResource::persist(new ($this->getModel()), $data, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users\Pages;
|
||||
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EditUser extends EditRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$data['roles'] = $this->record->staffRoles->map(fn ($assignment) => $assignment->role->value)->all();
|
||||
$data['status'] = $this->record->status->value;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
{
|
||||
return UserResource::persist($record, $data, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users\Pages;
|
||||
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListUsers extends ListRecords
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users;
|
||||
|
||||
use App\Domain\Identity\AccountStatus;
|
||||
use App\Domain\Identity\AssignStaffRoles;
|
||||
use App\Domain\Identity\RegisterAccount;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Filament\Resources\Users\Pages\CreateUser;
|
||||
use App\Filament\Resources\Users\Pages\EditUser;
|
||||
use App\Filament\Resources\Users\Pages\ListUsers;
|
||||
use App\Models\User;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class UserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = User::class;
|
||||
|
||||
protected static ?string $navigationLabel = 'Benutzer';
|
||||
|
||||
protected static ?string $modelLabel = 'Benutzer';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Benutzer';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'email';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
TextInput::make('name')->label('Name')->required()->maxLength(120),
|
||||
TextInput::make('email')->label('E-Mail')->email()->required()->maxLength(255),
|
||||
TextInput::make('password')
|
||||
->label('Passwort')
|
||||
->password()
|
||||
->revealable()
|
||||
->required(fn (string $operation): bool => $operation === 'create')
|
||||
->dehydrated(fn (?string $state): bool => filled($state))
|
||||
->minLength(8),
|
||||
Select::make('status')
|
||||
->label('Status')
|
||||
->options(collect(AccountStatus::cases())->mapWithKeys(
|
||||
fn (AccountStatus $status): array => [$status->value => $status->label()],
|
||||
)->all())
|
||||
->required()
|
||||
->default(AccountStatus::Aktiv->value),
|
||||
CheckboxList::make('roles')
|
||||
->label('Personalrollen')
|
||||
->options(StaffRole::options())
|
||||
->columns(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Name')->searchable(),
|
||||
TextColumn::make('email')->label('E-Mail')->searchable(),
|
||||
TextColumn::make('status')->label('Status')->formatStateUsing(
|
||||
fn (AccountStatus|string|null $state): string => $state instanceof AccountStatus ? $state->label() : (string) $state,
|
||||
),
|
||||
TextColumn::make('staffRoles.role')
|
||||
->label('Rollen')
|
||||
->badge()
|
||||
->formatStateUsing(fn (StaffRole|string $state): string => $state instanceof StaffRole ? $state->label() : StaffRole::from($state)->label()),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListUsers::route('/'),
|
||||
'create' => CreateUser::route('/create'),
|
||||
'edit' => EditUser::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public static function persist(User $user, array $data, bool $creating): User
|
||||
{
|
||||
$roles = $data['roles'] ?? [];
|
||||
unset($data['roles']);
|
||||
|
||||
if ($creating) {
|
||||
$user = app(RegisterAccount::class)->register(
|
||||
$data['name'],
|
||||
$data['email'],
|
||||
$data['password'],
|
||||
true,
|
||||
);
|
||||
$user->forceFill([
|
||||
'status' => $data['status'],
|
||||
'email_verified_at' => now(),
|
||||
])->save();
|
||||
} else {
|
||||
if (blank($data['password'] ?? null)) {
|
||||
unset($data['password']);
|
||||
}
|
||||
|
||||
$user->update($data);
|
||||
}
|
||||
|
||||
app(AssignStaffRoles::class)->sync($user, $roles, auth()->user());
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EmailVerificationController extends Controller
|
||||
{
|
||||
public function notice(Request $request): View|RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->route('member.dashboard');
|
||||
}
|
||||
|
||||
return view('auth.verify-email');
|
||||
}
|
||||
|
||||
public function verify(EmailVerificationRequest $request): RedirectResponse
|
||||
{
|
||||
$request->fulfill();
|
||||
|
||||
return redirect()->route('member.dashboard');
|
||||
}
|
||||
|
||||
public function send(Request $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->route('member.dashboard');
|
||||
}
|
||||
|
||||
$request->user()->sendEmailVerificationNotification();
|
||||
|
||||
return back()->with('status', 'Die Nachricht ist erneut unterwegs.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules\Password as PasswordRule;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PasswordResetController extends Controller
|
||||
{
|
||||
public function requestForm(): View
|
||||
{
|
||||
return view('auth.forgot-password');
|
||||
}
|
||||
|
||||
public function send(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate(['email' => ['required', 'email']]);
|
||||
|
||||
$status = Password::sendResetLink($request->only('email'));
|
||||
|
||||
return $status === Password::RESET_LINK_SENT
|
||||
? back()->with('status', 'Wenn ein Konto zu dieser Adresse besteht, ist die Nachricht unterwegs.')
|
||||
: back()->withErrors(['email' => 'Die Nachricht konnte nicht gesendet werden.']);
|
||||
}
|
||||
|
||||
public function resetForm(string $token): View
|
||||
{
|
||||
return view('auth.reset-password', ['token' => $token, 'email' => request('email')]);
|
||||
}
|
||||
|
||||
public function reset(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token' => ['required'],
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'confirmed', PasswordRule::defaults()],
|
||||
]);
|
||||
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function ($user, string $password): void {
|
||||
$user->forceFill([
|
||||
'password' => $password,
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
},
|
||||
);
|
||||
|
||||
return $status === Password::PASSWORD_RESET
|
||||
? redirect()->route('login')->with('status', 'Das Passwort ist geändert. Sie können sich anmelden.')
|
||||
: back()->withErrors(['email' => 'Der Link ist ungültig oder abgelaufen.']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Domain\Identity\RegisterAccount;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RegistrationController extends Controller
|
||||
{
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
public function store(Request $request, RegisterAccount $register): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => ['required', 'string', 'max:120'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email'],
|
||||
'password' => ['required', 'confirmed', Password::defaults()],
|
||||
'adult' => ['accepted'],
|
||||
], [
|
||||
'adult.accepted' => 'Die Plattform richtet sich an Erwachsene. Bitte bestätigen Sie das.',
|
||||
]);
|
||||
|
||||
$user = $register->register($data['name'], $data['email'], $data['password'], true);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
auth()->login($user);
|
||||
|
||||
return redirect()->route('verification.notice');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Domain\Identity\AccountStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class SessionController extends Controller
|
||||
{
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$credentials = $request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'string'],
|
||||
]);
|
||||
|
||||
$user = User::query()->where('email', $credentials['email'])->first();
|
||||
|
||||
if ($user !== null && $user->status !== AccountStatus::Aktiv) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => 'Dieses Konto ist nicht aktiv.',
|
||||
]);
|
||||
}
|
||||
|
||||
if (! Auth::attempt($credentials, $request->boolean('remember'))) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => 'E-Mail oder Passwort stimmt nicht.',
|
||||
]);
|
||||
}
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return redirect()->intended(route('member.dashboard'));
|
||||
}
|
||||
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect()->route('home');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Member;
|
||||
|
||||
use App\Domain\Identity\AccountStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class MemberController extends Controller
|
||||
{
|
||||
public function dashboard(): View
|
||||
{
|
||||
return view('member.dashboard');
|
||||
}
|
||||
|
||||
public function library(): View
|
||||
{
|
||||
return view('member.library');
|
||||
}
|
||||
|
||||
public function materials(): View
|
||||
{
|
||||
return view('member.materials');
|
||||
}
|
||||
|
||||
public function grants(): View
|
||||
{
|
||||
return view('member.grants');
|
||||
}
|
||||
|
||||
public function profile(): View
|
||||
{
|
||||
return view('member.profile');
|
||||
}
|
||||
|
||||
public function updateProfile(Request $request): RedirectResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
abort_if($user->status !== AccountStatus::Aktiv, 403);
|
||||
|
||||
$data = $request->validate([
|
||||
'name' => ['required', 'string', 'max:120'],
|
||||
]);
|
||||
|
||||
$user->name = $data['name'];
|
||||
$user->save();
|
||||
|
||||
$user->party?->update(['display_name' => $data['name']]);
|
||||
$user->party?->profile?->update(['display_name' => $data['name']]);
|
||||
|
||||
return redirect()->route('member.profile')->with('status', 'Der Name ist gespeichert. Er ist nicht öffentlich.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageRevision;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class PageController extends Controller
|
||||
{
|
||||
public function home(): View
|
||||
{
|
||||
return $this->render(Page::query()->where('path', '/')->firstOrFail(), preview: false);
|
||||
}
|
||||
|
||||
public function show(string $path): View
|
||||
{
|
||||
return $this->render(Page::query()->where('path', '/'.$path)->firstOrFail(), preview: false);
|
||||
}
|
||||
|
||||
public function preview(PageRevision $revision): View
|
||||
{
|
||||
$page = $revision->page;
|
||||
Gate::authorize('view', $page);
|
||||
|
||||
return $this->render($page, preview: true, revision: $revision);
|
||||
}
|
||||
|
||||
public function sitemap(): Response
|
||||
{
|
||||
$pages = Page::query()->whereNotNull('published_revision_id')->orderBy('path')->get();
|
||||
|
||||
return response()
|
||||
->view('public.sitemap', ['pages' => $pages])
|
||||
->header('Content-Type', 'application/xml');
|
||||
}
|
||||
|
||||
private function render(Page $page, bool $preview, ?PageRevision $revision = null): View
|
||||
{
|
||||
$revision ??= $page->publishedRevision;
|
||||
abort_if($revision === null, 404);
|
||||
|
||||
$heading = collect($revision->blocks)->firstWhere('type', 'heading');
|
||||
|
||||
return view('public.page', [
|
||||
'page' => $page,
|
||||
'revision' => $revision,
|
||||
'preview' => $preview,
|
||||
'documentTitle' => $revision->seo_title ?: ($heading['heading'] ?? config('app.name')),
|
||||
'documentDescription' => $revision->seo_description,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class PublicMediaController extends Controller
|
||||
{
|
||||
public function show(string $path): StreamedResponse
|
||||
{
|
||||
abort_if(str_contains($path, '..') || ! str_starts_with($path, 'cms/'), 404);
|
||||
|
||||
foreach (['media_public', 'cms_incoming'] as $disk) {
|
||||
if (Storage::disk($disk)->exists($path)) {
|
||||
return Storage::disk($disk)->response($path);
|
||||
}
|
||||
}
|
||||
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class UseStaffSessionCookie
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$referer = (string) $request->headers->get('referer', '');
|
||||
$staffRequest = $request->is('verwaltung', 'verwaltung/*')
|
||||
|| str_contains($referer, '/verwaltung');
|
||||
|
||||
if ($staffRequest) {
|
||||
config(['session.cookie' => 'luf_staff_session']);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PublishPublicMedia implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(public string $path) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
if (str_contains($this->path, '..') || ! str_starts_with($this->path, 'cms/')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$incoming = Storage::disk('cms_incoming');
|
||||
|
||||
if (! $incoming->exists($this->path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Storage::disk('media_public')->put($this->path, $incoming->get($this->path));
|
||||
$incoming->delete($this->path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Domain\Identity\AccountStatus;
|
||||
use App\Domain\Identity\Party;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Domain\Identity\StaffRoleAssignment;
|
||||
use Database\Factories\UserFactory;
|
||||
use Filament\Auth\MultiFactor\App\Concerns\InteractsWithAppAuthentication;
|
||||
use Filament\Auth\MultiFactor\App\Concerns\InteractsWithAppAuthenticationRecovery;
|
||||
use Filament\Auth\MultiFactor\App\Contracts\HasAppAuthentication;
|
||||
use Filament\Auth\MultiFactor\App\Contracts\HasAppAuthenticationRecovery;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['party_id', 'name', 'email', 'password', 'status', 'confirmed_adult_at'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable implements FilamentUser, HasAppAuthentication, HasAppAuthenticationRecovery, MustVerifyEmail
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
use InteractsWithAppAuthentication;
|
||||
use InteractsWithAppAuthenticationRecovery;
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'confirmed_adult_at' => 'datetime',
|
||||
'status' => AccountStatus::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function party(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Party::class);
|
||||
}
|
||||
|
||||
public function staffRoles(): HasMany
|
||||
{
|
||||
return $this->hasMany(StaffRoleAssignment::class);
|
||||
}
|
||||
|
||||
public function hasStaffRole(StaffRole $role): bool
|
||||
{
|
||||
if ($this->relationLoaded('staffRoles')) {
|
||||
return $this->staffRoles->contains(fn (StaffRoleAssignment $assignment): bool => $assignment->role === $role);
|
||||
}
|
||||
|
||||
return $this->staffRoles()->where('role', $role->value)->exists();
|
||||
}
|
||||
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
return $this->status === AccountStatus::Aktiv
|
||||
&& $this->hasVerifiedEmail()
|
||||
&& $this->staffRoles()->exists();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Models\User;
|
||||
|
||||
class UserPolicy
|
||||
{
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->hasStaffRole(StaffRole::Systemverwalter);
|
||||
}
|
||||
|
||||
public function view(User $user, User $model): bool
|
||||
{
|
||||
return $this->viewAny($user);
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $this->viewAny($user);
|
||||
}
|
||||
|
||||
public function update(User $user, User $model): bool
|
||||
{
|
||||
return $this->viewAny($user);
|
||||
}
|
||||
|
||||
public function delete(User $user, User $model): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Domain\Cms\NavigationItem;
|
||||
use App\Domain\Cms\NavigationItemPolicy;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PagePolicy;
|
||||
use App\Models\User;
|
||||
use App\Policies\UserPolicy;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
Gate::policy(Page::class, PagePolicy::class);
|
||||
Gate::policy(NavigationItem::class, NavigationItemPolicy::class);
|
||||
Gate::policy(User::class, UserPolicy::class);
|
||||
|
||||
View::composer('layouts.site', function ($view): void {
|
||||
if (! array_key_exists('navigation', $view->getData())) {
|
||||
$view->with('navigation', NavigationItem::query()->with('page')->orderBy('sort_order')->orderBy('id')->get());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers\Filament;
|
||||
|
||||
use Filament\Auth\MultiFactor\App\AppAuthentication;
|
||||
use Filament\Http\Middleware\Authenticate;
|
||||
use Filament\Http\Middleware\AuthenticateSession;
|
||||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||||
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
||||
use Filament\Pages\Dashboard;
|
||||
use Filament\Panel;
|
||||
use Filament\PanelProvider;
|
||||
use Filament\Support\Colors\Color;
|
||||
use Filament\Widgets\AccountWidget;
|
||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestForgery;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
|
||||
class AdminPanelProvider extends PanelProvider
|
||||
{
|
||||
public function panel(Panel $panel): Panel
|
||||
{
|
||||
return $panel
|
||||
->default()
|
||||
->id('verwaltung')
|
||||
->path('verwaltung')
|
||||
->login()
|
||||
->brandName('Verwaltung')
|
||||
->authGuard('staff')
|
||||
->colors([
|
||||
'primary' => Color::hex('#0F6E56'),
|
||||
])
|
||||
->multiFactorAuthentication([
|
||||
AppAuthentication::make()->recoverable(),
|
||||
], isRequired: true)
|
||||
->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources')
|
||||
->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages')
|
||||
->pages([
|
||||
Dashboard::class,
|
||||
])
|
||||
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets')
|
||||
->widgets([
|
||||
AccountWidget::class,
|
||||
])
|
||||
->middleware([
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartSession::class,
|
||||
AuthenticateSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
PreventRequestForgery::class,
|
||||
SubstituteBindings::class,
|
||||
DisableBladeIconComponents::class,
|
||||
DispatchServingFilamentEvent::class,
|
||||
])
|
||||
->authMiddleware([
|
||||
Authenticate::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user