Phase 4: Seiten mit Pagebuilder, Redaktion und Freigaben
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
- Seiten-Plugin: Seitenbaum mit Adressen, Seitennavigation, Brotkrumen und optional Hauptnavigation; Sichtbarkeit vererbt sich auf Unterseiten - Pagebuilder (Block-Registry im Kern, Plugins tragen Blöcke bei): Abschnitt, Spalten, Tabs, Akkordeon, Box, Überschrift, Text (TipTap), Zitat, Schaltflächen, Symbolliste, Tabelle, Trennlinie, Abstand, Bild, Galerie, Video (erst nach Klick), Titelbild, Ansprechpartner, Downloads, Unterseiten, Neuigkeiten, Termine; Sichtbarkeit je Block; Bereinigung beim Speichern - Editor im Portal: Ziehen und Ablegen, Autospeichern als Entwurf, Rückgängig, Gerätevorschau, Versionen, Zeitsteuerung, Bearbeitungssperre, Freigabe anfordern - Rechte „inkl. Unterseiten“ werden im Rechte-Cache aufgelöst - Neuigkeiten: Schreiben im Portal, Freigabe-Workflow mit Benachrichtigungen - Bereich „Redaktion“, Benachrichtigungen im Portal - storage/.migrations-fingerprint nicht mehr ausliefern Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6269d3302c
commit
f3987e8386
328 changed files with 10618 additions and 389 deletions
|
|
@ -14,7 +14,7 @@ class Abilities
|
|||
/** @var array<string, array{label: string, group: string, resource: string|null}> */
|
||||
private array $abilities = [];
|
||||
|
||||
/** @var array<string, array{label: string, options: callable}> */
|
||||
/** @var array<string, array{label: string, options: callable, descendants: callable|null}> */
|
||||
private array $resourceTypes = [];
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -36,11 +36,20 @@ class Abilities
|
|||
/**
|
||||
* Objekttyp, auf den sich Rechte beziehen können (z. B. „news_category“).
|
||||
*
|
||||
* Hierarchische Typen (z. B. Seiten) geben $descendants an: Rechte mit
|
||||
* „inkl. Unterobjekten“ gelten dann auch für alle Nachfahren.
|
||||
*
|
||||
* @param callable(): array<int|string, string> $options ID => Bezeichnung
|
||||
* @param (callable(list<int>): list<int>)|null $descendants IDs => IDs aller Nachfahren
|
||||
*/
|
||||
public function resourceType(string $type, string $label, callable $options): void
|
||||
public function resourceType(string $type, string $label, callable $options, ?callable $descendants = null): void
|
||||
{
|
||||
$this->resourceTypes[$type] = ['label' => $label, 'options' => $options];
|
||||
$this->resourceTypes[$type] = ['label' => $label, 'options' => $options, 'descendants' => $descendants];
|
||||
}
|
||||
|
||||
public function isHierarchical(?string $type): bool
|
||||
{
|
||||
return $type !== null && isset($this->resourceTypes[$type]['descendants']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -68,7 +77,7 @@ class Abilities
|
|||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{label: string, options: callable}>
|
||||
* @return array<string, array{label: string, options: callable, descendants: callable|null}>
|
||||
*/
|
||||
public function resourceTypes(): array
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Support;
|
||||
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\Drivers\Gd\Driver;
|
||||
use Intervention\Image\Encoders\WebpEncoder;
|
||||
use Intervention\Image\ImageManager;
|
||||
|
|
@ -46,6 +48,31 @@ class Images
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bild für Inhalte (Pagebuilder, Beiträge): Seitenverhältnis bleibt, höchstens
|
||||
* 2000 Pixel breit, als WebP. GIFs bleiben unverändert (Animationen).
|
||||
*
|
||||
* @return string Pfad im Speicher „uploads“
|
||||
*/
|
||||
public function storeContentImage(UploadedFile $file, string $directory): string
|
||||
{
|
||||
$disk = Storage::disk('uploads');
|
||||
$name = $directory.'/'.now()->format('Y/m').'/'.Str::random(24);
|
||||
|
||||
if ($file->getMimeType() === 'image/gif') {
|
||||
$disk->putFileAs(dirname($name), $file, basename($name).'.gif');
|
||||
|
||||
return $name.'.gif';
|
||||
}
|
||||
|
||||
self::raiseMemoryLimitFor($file->getRealPath());
|
||||
$image = ImageManager::usingDriver(Driver::class)->decodePath($file->getRealPath());
|
||||
$image->scaleDown(width: 2000);
|
||||
$disk->put($name.'.webp', $image->encode(new WebpEncoder(quality: 84))->toString());
|
||||
|
||||
return $name.'.webp';
|
||||
}
|
||||
|
||||
public function deleteWithVariants(?string $path): void
|
||||
{
|
||||
if (! $path) {
|
||||
|
|
|
|||
|
|
@ -4,18 +4,28 @@ namespace App\Support;
|
|||
|
||||
use App\Models\User;
|
||||
use App\Plugins\Hooks;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Hauptnavigation des Portals als Registry: Kern und Plugins tragen Einträge ein.
|
||||
*
|
||||
* app(Navigation::class)->add('news', 'Neuigkeiten', '/neuigkeiten', active: 'news.*', sort: 20);
|
||||
*
|
||||
* Dynamische Einträge (z. B. Seiten aus dem Seitenbaum) liefert ein Provider:
|
||||
*
|
||||
* app(Navigation::class)->provider('pages', fn (Request $request, ?User $user) => [
|
||||
* ['key' => 'page-3', 'label' => 'MAV', 'href' => '/seiten/mav', 'active' => true, 'sort' => 40],
|
||||
* ]);
|
||||
*/
|
||||
class Navigation
|
||||
{
|
||||
/** @var array<string, array{label: string, href: string, active: list<string>, sort: int, ability: string|null}> */
|
||||
/** @var array<string, array{label: string, href: string, active: list<string>, sort: int, ability: string|null, visible: Closure|null}> */
|
||||
private array $items = [];
|
||||
|
||||
/** @var array<string, Closure> */
|
||||
private array $providers = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->add('home', 'Startseite', '/', active: 'dashboard', sort: 0);
|
||||
|
|
@ -24,15 +34,24 @@ class Navigation
|
|||
|
||||
/**
|
||||
* @param string|list<string> $active Routennamen (mit *), bei denen der Eintrag aktiv ist
|
||||
* @param (Closure(User): bool)|null $visible zusätzliche Bedingung je Person
|
||||
*/
|
||||
public function add(string $key, string $label, string $href, string|array $active = [], int $sort = 50, ?string $ability = null): void
|
||||
public function add(string $key, string $label, string $href, string|array $active = [], int $sort = 50, ?string $ability = null, ?Closure $visible = null): void
|
||||
{
|
||||
$this->items[$key] = ['label' => $label, 'href' => $href, 'active' => (array) $active, 'sort' => $sort, 'ability' => $ability];
|
||||
$this->items[$key] = ['label' => $label, 'href' => $href, 'active' => (array) $active, 'sort' => $sort, 'ability' => $ability, 'visible' => $visible];
|
||||
}
|
||||
|
||||
public function remove(string $key): void
|
||||
{
|
||||
unset($this->items[$key]);
|
||||
unset($this->items[$key], $this->providers[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Closure(Request, User|null): list<array{key: string, label: string, href: string, active: bool, sort: int}> $items
|
||||
*/
|
||||
public function provider(string $key, Closure $items): void
|
||||
{
|
||||
$this->providers[$key] = $items;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -42,13 +61,21 @@ class Navigation
|
|||
{
|
||||
$items = collect($this->items)
|
||||
->filter(fn (array $item) => $item['ability'] === null || ($user?->can($item['ability']) ?? false))
|
||||
->sortBy('sort')
|
||||
->filter(fn (array $item) => $item['visible'] === null || ($user !== null && ($item['visible'])($user)))
|
||||
->map(fn (array $item, string $key) => [
|
||||
'key' => $key,
|
||||
'label' => $item['label'],
|
||||
'href' => $item['href'],
|
||||
'active' => $item['active'] !== [] && $request->routeIs(...$item['active']),
|
||||
])
|
||||
'sort' => $item['sort'],
|
||||
]);
|
||||
|
||||
foreach ($this->providers as $provider) {
|
||||
$items = $items->merge($provider($request, $user));
|
||||
}
|
||||
|
||||
$items = $items->sortBy('sort')
|
||||
->map(fn (array $item) => ['key' => $item['key'], 'label' => $item['label'], 'href' => $item['href'], 'active' => (bool) $item['active']])
|
||||
->values()
|
||||
->all();
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,47 @@ class Audiences
|
|||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle Regeln eines Typs auf einmal – für gecachte Strukturen wie den Seitenbaum.
|
||||
*
|
||||
* @return array<int, array{role: list<string>, department: list<string>, location: list<string>}> ID => Regeln
|
||||
*/
|
||||
public static function allOfType(string $type): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach (Audience::query()->where('resource_type', $type)->get(['resource_id', 'rule_type', 'rule_value']) as $audience) {
|
||||
$result[$audience->resource_id] ??= ['role' => [], 'department' => [], 'location' => []];
|
||||
$result[$audience->resource_id][$audience->rule_type][] = $audience->rule_value;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dieselbe Prüfung wie constrain()/allows(), aber in PHP auf bereits geladenen Regeln.
|
||||
*
|
||||
* @param array{role?: list<int|string>, department?: list<string>, location?: list<string>}|null $rules
|
||||
*/
|
||||
public static function matches(?array $rules, ?User $user): bool
|
||||
{
|
||||
$rules = array_filter((array) $rules);
|
||||
|
||||
if ($rules === []) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$roleIds = array_map('strval', $user->permissions()->roleIds);
|
||||
|
||||
return array_intersect(array_map('strval', $rules['role'] ?? []), $roleIds) !== []
|
||||
|| (filled($user->department) && in_array($user->department, $rules['department'] ?? [], true))
|
||||
|| (filled($user->location) && in_array($user->location, $rules['location'] ?? [], true));
|
||||
}
|
||||
|
||||
private static function matching(QueryBuilder $rules, User $user): void
|
||||
{
|
||||
$roleIds = array_map('strval', $user->permissions()->roleIds);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Support\Permissions;
|
|||
|
||||
use App\Models\Grant;
|
||||
use App\Models\User;
|
||||
use App\Support\Abilities;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
|
@ -48,14 +49,33 @@ class Permissions
|
|||
$roleIds = DB::table('role_user')->where('user_id', $user->id)->distinct()->pluck('role_id')->map(fn ($id) => (int) $id)->all();
|
||||
$global = [];
|
||||
$objects = [];
|
||||
$inherited = [];
|
||||
|
||||
foreach (Grant::query()->whereIn('role_id', $roleIds)->get(['ability', 'resource_type', 'resource_id']) as $grant) {
|
||||
foreach (Grant::query()->whereIn('role_id', $roleIds)->get(['ability', 'resource_type', 'resource_id', 'include_children']) as $grant) {
|
||||
if ($grant->resource_type === null) {
|
||||
$global[$grant->ability] = true;
|
||||
} elseif ($grant->resource_id === null) {
|
||||
$objects[$grant->ability][$grant->resource_type] = true;
|
||||
} elseif (($objects[$grant->ability][$grant->resource_type] ?? null) !== true) {
|
||||
$objects[$grant->ability][$grant->resource_type][] = $grant->resource_id;
|
||||
|
||||
if ($grant->include_children) {
|
||||
$inherited[$grant->resource_type][$grant->ability][] = $grant->resource_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// „Inkl. Unterobjekten“: Nachfahren einmalig auflösen – die Prüfung bleibt ein Array-Zugriff.
|
||||
// Hierarchische Typen leeren den Rechte-Cache, wenn sich ihr Baum ändert.
|
||||
$types = app(Abilities::class)->resourceTypes();
|
||||
|
||||
foreach ($inherited as $type => $byAbility) {
|
||||
$descendants = $types[$type]['descendants'] ?? null;
|
||||
|
||||
foreach ($descendants ? $byAbility : [] as $ability => $ids) {
|
||||
if (is_array($objects[$ability][$type] ?? null)) {
|
||||
$objects[$ability][$type] = array_merge($objects[$ability][$type], array_map('intval', $descendants($ids)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,14 @@ class RichText
|
|||
return $this->sanitizer()->sanitize($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML aus dem Portal-Editor (TipTap) bereinigen.
|
||||
*/
|
||||
public function sanitize(?string $html): string
|
||||
{
|
||||
return blank($html) ? '' : $this->sanitizer()->sanitize((string) $html);
|
||||
}
|
||||
|
||||
public function readingMinutes(?string $html): int
|
||||
{
|
||||
$words = str_word_count(strip_tags((string) $html), 0, 'ÄÖÜäöüß');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue