Gib Website-Bilder aus dem Medienmanager frei, ohne sie zu lizenzieren.
Deploy Test / test (push) Successful in 48s
Deploy Test / deploy (push) Successful in 29s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-18 22:01:05 +01:00
1 parent 72130d66c5
commit 13530b8171
18 files changed
+940 -2

No files matched your search

+5
View File
@@ -17,6 +17,10 @@ class ContentElement extends Model
'description',
'usage_note',
'license_note',
'website_credit',
'website_alt',
'website_released_at',
'website_public_path',
'summary',
'thumbnail_path',
'thumbnail_alt',
@@ -30,6 +34,7 @@ protected function casts(): array
{
return [
'archived_at' => 'datetime',
'website_released_at' => 'datetime',
];
}
+20
View File
@@ -52,6 +52,18 @@ public function forElementUpload(ContentElement $element, string $incoming): voi
$this->rememberElement($element, 'eigen');
}
public function forWebsiteImage(ContentElement $element, string $incoming): void
{
if ($element->output_class !== 'bild' || ! $this->incomingIsSafe($incoming)) {
$this->fail($element, 'Das Bild für die Website wurde nicht übernommen.');
return;
}
$this->still($element, Storage::disk('cms_incoming'), $incoming, 'element-'.$element->id);
$this->rememberElement($element, 'eigen');
}
public function forElementFrame(ContentElement $element, ContentElementVersion $version, float $seconds): void
{
if ($version->content_element_id !== $element->id || $element->output_class !== 'film') {
@@ -201,6 +213,14 @@ private function readableDerived(mixed $path, string $prefix): bool
return Storage::disk('media_derived')->exists($path);
}
private function incomingIsSafe(string $incoming): bool
{
return (str_starts_with($incoming, 'cms/') || str_starts_with($incoming, 'vorschau/'))
&& ! str_contains($incoming, '..')
&& preg_match('#^(cms|vorschau)/[A-Za-z0-9._\-/]+$#', $incoming) === 1
&& Storage::disk('cms_incoming')->exists($incoming);
}
private function secondText(float $seconds): string
{
$seconds = max(0, min(7200, $seconds));
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace App\Domain\Media;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\IdentityProfile;
use App\Jobs\AcceptWebsiteImage;
use App\Models\User;
use Illuminate\Support\Facades\Storage;
/**
* Nimmt ein neues Website-Bild in den Medienmanager auf.
* Die Warteschlange erzeugt danach die Ableitung und gibt sie frei.
*/
class WebsiteIntake
{
public function acceptImage(
string $incomingPath,
string $title,
?string $credit = null,
?string $alt = null,
?User $actor = null,
): ContentElement {
$title = trim($title);
if ($title === '') {
throw new DomainRuleException('Der Titel fehlt.');
}
if (! $this->incomingIsReadable($incomingPath)) {
throw new DomainRuleException('Die Bilddatei liegt nicht im Eingang.');
}
$element = app(ContentService::class)->createElement('bild', 'bild', $title);
app(IdentityProfile::class)->fill($element, [
'display_title' => $title,
'website_credit' => $credit,
'website_alt' => $alt,
], $actor);
AcceptWebsiteImage::dispatch($element->id, $incomingPath, $actor?->id);
return $element->fresh();
}
private function incomingIsReadable(string $path): bool
{
return (str_starts_with($path, 'cms/') || str_starts_with($path, 'vorschau/'))
&& ! str_contains($path, '..')
&& preg_match('#^(cms|vorschau)/[A-Za-z0-9._\-/]+$#', $path) === 1
&& Storage::disk('cms_incoming')->exists($path);
}
}
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace App\Domain\Media;
use App\Domain\Catalog\ContentElement;
use Illuminate\Support\Facades\Storage;
/**
* Lesesicht für Hero, Teaser und Slideshow.
* Liefert nur eine freigegebene öffentliche Ableitung, sonst nichts.
*/
class WebsiteMedia
{
public function present(ContentElement|int $element): ?WebsitePresentation
{
$element = $element instanceof ContentElement
? $element
: ContentElement::query()->find($element);
if (! $element instanceof ContentElement || $element->website_released_at === null) {
return null;
}
$path = $element->website_public_path;
$expected = '#^website/'.$element->id.'/datei\.[a-z0-9]+$#';
if (! is_string($path) || preg_match($expected, $path) !== 1) {
return null;
}
if (! Storage::disk('media_public')->exists($path)) {
return null;
}
$title = trim((string) ($element->display_title ?: $element->working_title));
$alt = trim((string) ($element->website_alt ?? ''));
return new WebsitePresentation(
elementId: $element->id,
title: $title,
alt: $alt !== '' ? $alt : $title,
credit: filled($element->website_credit) ? trim((string) $element->website_credit) : null,
kind: $element->output_class === 'film' ? 'film' : 'bild',
url: route('website.media', $element),
);
}
/**
* Slideshow: freigegebene Medien in der angegebenen Reihenfolge. Nicht freigegebene Einträge entfallen.
*
* @param list<int|string> $ids
* @return list<WebsitePresentation>
*/
public function presentMany(array $ids): array
{
$presentations = [];
foreach ($ids as $id) {
if (! is_numeric($id)) {
continue;
}
$presentation = $this->present((int) $id);
if ($presentation !== null) {
$presentations[] = $presentation;
}
}
return $presentations;
}
}
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App\Domain\Media;
/**
* Öffentliche Ableitung eines für die Website freigegebenen Mediums.
* Enthält keine internen Vermerke und keine Adresse einer Bestandsdatei.
*/
final class WebsitePresentation
{
public function __construct(
public readonly int $elementId,
public readonly string $title,
public readonly string $alt,
public readonly ?string $credit,
public readonly string $kind,
public readonly string $url,
) {}
}
+121
View File
@@ -0,0 +1,121 @@
<?php
namespace App\Domain\Media;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\EditorialContentKind;
use App\Domain\Cms\Catalog\PublicMaterialReader;
use App\Jobs\PublishWebsiteMedia;
use App\Models\User;
use Illuminate\Support\Facades\Storage;
/**
* Gibt eine Ableitung für die Website frei oder nimmt sie zurück.
* Legt keinen Lizenzartikel an und ruft DecideAccess nicht auf.
* Der Web-Prozess schreibt die öffentliche Datei nicht selbst; das tut die Warteschlange.
*/
class WebsiteRelease
{
public function release(ContentElement $element, ?User $actor = null): string
{
$refusal = $this->refusal($element);
if ($refusal !== null) {
return $refusal;
}
PublishWebsiteMedia::dispatch($element->id, 'release', $actor?->id);
return 'Für die Website freigegeben. Öffentliche Seiten lesen nur diese Ableitung.';
}
public function withdraw(ContentElement $element, ?User $actor = null): string
{
PublishWebsiteMedia::dispatch($element->id, 'withdraw', $actor?->id);
return 'Die Website-Freigabe ist zurückgenommen.';
}
public function refusal(ContentElement $element): ?string
{
if ($this->isConfidential($element)) {
return 'Traineranleitungen werden nicht für die Website freigegeben.';
}
if ($this->derivedPath($element) === null) {
return 'Für die Website fehlt eine freigebbare Ableitung. Beim Bild ist das das Vorschaubild, beim Film eine Teaserfassung unter teaser/. Die Originaldatei bleibt geschützt.';
}
return null;
}
public function derivedPath(ContentElement $element): ?string
{
if ($this->isConfidential($element)) {
return null;
}
if ($element->output_class === 'bild') {
return $this->allowedDerivedPath($element->thumbnail_path, 'vorschau/');
}
if ($element->output_class !== 'film') {
return null;
}
$version = $element->versions()
->where('status', ContentVersionStatus::Bereit->value)
->orderByDesc('number')
->first();
if ($version === null) {
return null;
}
$path = MediaRendition::query()
->where('content_element_version_id', $version->id)
->where('role', 'preview')
->orderByDesc('id')
->value('path');
return $this->allowedDerivedPath($path, 'teaser/');
}
public function publicPath(ContentElement $element, string $derivedPath): string
{
$extension = strtolower(pathinfo($derivedPath, PATHINFO_EXTENSION));
return 'website/'.$element->id.'/datei.'.$extension;
}
private function isConfidential(ContentElement $element): bool
{
$slug = $element->editorialContentKind?->slug;
if ($slug === null && $element->editorial_content_kind_id !== null) {
$slug = EditorialContentKind::query()->whereKey($element->editorial_content_kind_id)->value('slug');
}
return in_array($slug, PublicMaterialReader::CONFIDENTIAL_KINDS, true);
}
private function allowedDerivedPath(mixed $path, string $prefix): ?string
{
if (! is_string($path) || ! str_starts_with($path, $prefix) || str_contains($path, '..')) {
return null;
}
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
if (! in_array($extension, ['jpg', 'jpeg', 'png', 'webp', 'gif', 'mp4', 'webm'], true)) {
return null;
}
if (! Storage::disk('media_derived')->exists($path)) {
return null;
}
return $path;
}
}
@@ -15,6 +15,8 @@
use App\Domain\Cms\Catalog\PublicMaterialReader;
use App\Domain\Cms\Widgets\RenderContext;
use App\Domain\Media\ThumbnailRef;
use App\Domain\Media\WebsiteMedia;
use App\Domain\Media\WebsiteRelease;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\CatalogReading;
use App\Filament\Support\EditorialCatalog;
@@ -67,6 +69,12 @@ class ViewContentElement extends ViewRecord
public string $licenseNote = '';
public string $websiteCredit = '';
public string $websiteAlt = '';
public string $websiteFeedback = '';
public int|string|null $kindId = null;
/** @var list<int|string> */
@@ -453,6 +461,8 @@ public function saveEditorial(): void
'description' => $this->descriptionText,
'usage_note' => $this->usageNote,
'license_note' => $this->licenseNote,
'website_credit' => $this->websiteCredit,
'website_alt' => $this->websiteAlt,
'thumbnail_alt' => $this->thumbnailAlt,
'editorial_content_kind_id' => filled($this->kindId) ? (int) $this->kindId : null,
], auth()->user());
@@ -476,6 +486,41 @@ public function saveEditorial(): void
: 'Gespeichert. Prüfe die Fassungen, ihre Zahl hat sich geändert.';
}
public function releaseForWebsite(): void
{
abort_unless(ContentElementResource::editor(), 403);
/** @var ContentElement $element */
$element = $this->getRecord();
app(IdentityProfile::class)->fill($element, [
'website_credit' => $this->websiteCredit,
'website_alt' => $this->websiteAlt,
], auth()->user());
$element->refresh();
$this->websiteFeedback = app(WebsiteRelease::class)->release($element, auth()->user());
$element->refresh();
$this->fillEditorial();
}
public function withdrawWebsite(): void
{
abort_unless(ContentElementResource::editor(), 403);
/** @var ContentElement $element */
$element = $this->getRecord();
$this->websiteFeedback = app(WebsiteRelease::class)->withdraw($element, auth()->user());
$element->refresh();
$this->fillEditorial();
}
public function websiteIsPublic(): bool
{
/** @var ContentElement $element */
$element = $this->getRecord();
return app(WebsiteMedia::class)->present($element->fresh()) !== null;
}
public function adoptLibraryImage(): void
{
abort_unless(ContentElementResource::editor(), 403);
@@ -610,6 +655,9 @@ public function editorialHistory(): array
'summary' => 'Kurzbeschreibung',
'usage_note' => 'Einsatzhinweis',
'license_note' => 'Interner Lizenzvermerk',
'website_credit' => 'Quellenzeile',
'website_alt' => 'Alternativtext der Website',
'website_released_at' => 'Website-Freigabe',
'thumbnail_alt' => 'Alternativtext',
'thumbnail_path' => 'Vorschaubild',
'thumbnail_source' => 'Herkunft des Vorschaubilds',
@@ -651,6 +699,8 @@ private function fillEditorial(): void
$this->descriptionText = (string) ($element->description ?? '');
$this->usageNote = (string) ($element->usage_note ?? '');
$this->licenseNote = (string) ($element->license_note ?? '');
$this->websiteCredit = (string) ($element->website_credit ?? '');
$this->websiteAlt = (string) ($element->website_alt ?? '');
$this->kindId = $element->editorial_content_kind_id;
$this->pillarIds = $element->pillars()->pluck('pillars.id')->all();
$this->dimensionIds = IdentityDimensionValue::query()
@@ -0,0 +1,25 @@
<?php
namespace App\Http\Controllers;
use App\Domain\Catalog\ContentElement;
use App\Domain\Media\WebsiteMedia;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\StreamedResponse;
class WebsiteMediaController extends Controller
{
public function show(ContentElement $element, WebsiteMedia $media): StreamedResponse
{
$presentation = $media->present($element);
abort_if($presentation === null, 404);
$path = $element->website_public_path;
abort_if(! is_string($path), 404);
return Storage::disk('media_public')->response($path, null, [
'Content-Disposition' => 'inline',
'X-Content-Type-Options' => 'nosniff',
]);
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace App\Jobs;
use App\Domain\Catalog\ContentElement;
use App\Domain\Media\ThumbnailDeriver;
use App\Domain\Media\WebsiteRelease;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Storage;
class AcceptWebsiteImage implements ShouldQueue
{
use Queueable;
public function __construct(
public int $elementId,
public string $incoming,
public ?int $actorId = null,
) {}
public function handle(ThumbnailDeriver $deriver, WebsiteRelease $release): void
{
$element = ContentElement::query()->find($this->elementId);
if (! $element instanceof ContentElement) {
return;
}
$deriver->forWebsiteImage($element, $this->incoming);
$element->refresh();
if ($release->derivedPath($element) === null) {
return;
}
if ($this->incomingIsDisposable()) {
Storage::disk('cms_incoming')->delete($this->incoming);
}
PublishWebsiteMedia::dispatch($element->id, 'release', $this->actorId);
}
private function incomingIsDisposable(): bool
{
return (str_starts_with($this->incoming, 'cms/') || str_starts_with($this->incoming, 'vorschau/'))
&& ! str_contains($this->incoming, '..');
}
}
+90
View File
@@ -0,0 +1,90 @@
<?php
namespace App\Jobs;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\IdentityChange;
use App\Domain\Media\WebsiteRelease;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Storage;
class PublishWebsiteMedia implements ShouldQueue
{
use Queueable;
public function __construct(
public int $elementId,
public string $action,
public ?int $actorId = null,
) {}
public function handle(WebsiteRelease $release): void
{
$element = ContentElement::query()->find($this->elementId);
if (! $element instanceof ContentElement || ! in_array($this->action, ['release', 'withdraw'], true)) {
return;
}
if ($this->action === 'withdraw') {
$this->deletePublicFile($element);
$this->mark($element, $element->website_released_at?->toIso8601String(), null);
$element->forceFill([
'website_released_at' => null,
'website_public_path' => null,
])->save();
return;
}
$derived = $release->derivedPath($element);
if ($derived === null) {
return;
}
$target = $release->publicPath($element, $derived);
$previous = $element->website_public_path;
Storage::disk('media_public')->put($target, Storage::disk('media_derived')->get($derived));
if (is_string($previous) && $previous !== $target && str_starts_with($previous, 'website/'.$element->id.'/')) {
Storage::disk('media_public')->delete($previous);
}
$this->mark($element, $element->website_released_at?->toIso8601String(), now()->toIso8601String());
$element->forceFill([
'website_released_at' => now(),
'website_public_path' => $target,
])->save();
}
private function deletePublicFile(ContentElement $element): void
{
$path = $element->website_public_path;
if (! is_string($path) || ! str_starts_with($path, 'website/'.$element->id.'/') || str_contains($path, '..')) {
return;
}
Storage::disk('media_public')->delete($path);
}
private function mark(ContentElement $element, ?string $before, ?string $after): void
{
if ($before === $after) {
return;
}
IdentityChange::query()->create([
'subject_type' => $element->getMorphClass(),
'subject_id' => $element->id,
'field' => 'website_released_at',
'before' => $before,
'after' => $after,
'actor_id' => $this->actorId,
'occurred_at' => now(),
]);
}
}