From af85a94cd56988256c34a3a1405b08b14543b1fd Mon Sep 17 00:00:00 2001 From: Lars Date: Sun, 15 Nov 2026 11:25:08 +0100 Subject: [PATCH] Zeige Medienfassungen in der Verwaltung und halte Beschreibungen davon getrennt. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eine Fassung bleibt nummeriert und kann deaktiviert werden. Beschreibung und fachliche Säulen gehören zum Medium und legen keine neue Fassung an. Co-authored-by: Cursor --- app/Domain/Catalog/ContentElement.php | 7 + app/Domain/Catalog/ContentElementVersion.php | 12 +- app/Domain/Catalog/ContentService.php | 13 ++ app/Domain/Catalog/Pillar.php | 18 ++ app/Domain/Catalog/PillarService.php | 63 +++++++ .../Compositions/Pages/EditComposition.php | 7 + .../ContentElementResource.php | 24 ++- .../Pages/EditContentElement.php | 166 ++++-------------- .../Pages/ListContentElements.php | 2 +- .../Pages/ViewContentElement.php | 161 +++++++++++++++++ .../Resources/Pillars/Pages/EditPillar.php | 58 ++++++ .../Resources/Pillars/Pages/ListPillars.php | 46 +++++ .../Resources/Pillars/PillarResource.php | 67 +++++++ app/Filament/Support/CatalogReading.php | 33 ++++ app/Filament/Support/ElementRevision.php | 103 +++++++++++ .../Controllers/ContentPreviewController.php | 66 +++++-- .../Controllers/Member/LibraryController.php | 3 +- .../2026_11_15_150000_create_pillars.php | 29 +++ ...026_11_15_160000_add_media_description.php | 30 ++++ docs/betrieb/MVP-Stand.md | 2 +- resources/views/content/player.blade.php | 27 +++ resources/views/content/preview.blade.php | 9 +- .../views/filament/media/viewer.blade.php | 69 ++++++++ resources/views/member/article.blade.php | 6 + routes/web.php | 5 +- tests/Feature/CatalogAdministrationTest.php | 4 +- tests/Feature/MediaAdministrationTest.php | 66 ++++++- tests/Feature/PillarAssignmentTest.php | 74 ++++++++ 28 files changed, 1002 insertions(+), 168 deletions(-) create mode 100644 app/Domain/Catalog/Pillar.php create mode 100644 app/Domain/Catalog/PillarService.php create mode 100644 app/Filament/Resources/ContentElements/Pages/ViewContentElement.php create mode 100644 app/Filament/Resources/Pillars/Pages/EditPillar.php create mode 100644 app/Filament/Resources/Pillars/Pages/ListPillars.php create mode 100644 app/Filament/Resources/Pillars/PillarResource.php create mode 100644 app/Filament/Support/ElementRevision.php create mode 100644 database/migrations/2026_11_15_150000_create_pillars.php create mode 100644 database/migrations/2026_11_15_160000_add_media_description.php create mode 100644 resources/views/content/player.blade.php create mode 100644 resources/views/filament/media/viewer.blade.php create mode 100644 tests/Feature/PillarAssignmentTest.php diff --git a/app/Domain/Catalog/ContentElement.php b/app/Domain/Catalog/ContentElement.php index 81dfd42..1844e79 100644 --- a/app/Domain/Catalog/ContentElement.php +++ b/app/Domain/Catalog/ContentElement.php @@ -3,6 +3,7 @@ namespace App\Domain\Catalog; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; class ContentElement extends Model @@ -11,6 +12,7 @@ class ContentElement extends Model 'kind', 'output_class', 'working_title', + 'description', 'archived_at', ]; @@ -25,4 +27,9 @@ public function versions(): HasMany { return $this->hasMany(ContentElementVersion::class); } + + public function pillars(): BelongsToMany + { + return $this->belongsToMany(Pillar::class)->orderBy('pillars.name'); + } } diff --git a/app/Domain/Catalog/ContentElementVersion.php b/app/Domain/Catalog/ContentElementVersion.php index f4020eb..1b92261 100644 --- a/app/Domain/Catalog/ContentElementVersion.php +++ b/app/Domain/Catalog/ContentElementVersion.php @@ -15,6 +15,7 @@ class ContentElementVersion extends Model 'body', 'metadata', 'change_note', + 'block_reason', ]; protected function casts(): array @@ -37,7 +38,16 @@ protected static function booted(): void return; } - $dirty = array_diff(array_keys($version->getDirty()), ['status', 'updated_at']); + $allowed = ['status', 'updated_at']; + + if ( + $original === ContentVersionStatus::Bereit->value + && StatusValue::of($version->status) === ContentVersionStatus::Gesperrt->value + ) { + $allowed[] = 'block_reason'; + } + + $dirty = array_diff(array_keys($version->getDirty()), $allowed); if ($dirty !== [] || $original === ContentVersionStatus::Gesperrt->value) { throw new DomainRuleException('Eine bereitgestellte Inhaltsfassung ist unveränderlich.'); diff --git a/app/Domain/Catalog/ContentService.php b/app/Domain/Catalog/ContentService.php index 299fa25..1e418dd 100644 --- a/app/Domain/Catalog/ContentService.php +++ b/app/Domain/Catalog/ContentService.php @@ -30,9 +30,22 @@ public function block(ContentElementVersion|CompositionVersion $version, string } $version->status = ContentVersionStatus::Gesperrt; + + if ($version instanceof ContentElementVersion) { + $version->block_reason = trim($reason); + } + $version->save(); } + public function describe(ContentElement $element, string $workingTitle, ?string $description): void + { + $element->working_title = $this->required($workingTitle, 'Der Arbeitstitel fehlt.'); + $description = trim((string) $description); + $element->description = $description === '' ? null : $description; + $element->save(); + } + public function publishElementVersion( ContentElement $element, ?string $body = null, diff --git a/app/Domain/Catalog/Pillar.php b/app/Domain/Catalog/Pillar.php new file mode 100644 index 0000000..5260a72 --- /dev/null +++ b/app/Domain/Catalog/Pillar.php @@ -0,0 +1,18 @@ +belongsToMany(ContentElement::class); + } +} diff --git a/app/Domain/Catalog/PillarService.php b/app/Domain/Catalog/PillarService.php new file mode 100644 index 0000000..09cd440 --- /dev/null +++ b/app/Domain/Catalog/PillarService.php @@ -0,0 +1,63 @@ +name($name); + + if (Pillar::query()->where('name', $name)->exists()) { + throw new DomainRuleException('Diese fachliche Säule gibt es schon.'); + } + + return Pillar::query()->create(['name' => $name]); + } + + public function rename(Pillar $pillar, string $name): void + { + $name = $this->name($name); + + if (Pillar::query()->where('name', $name)->whereKeyNot($pillar->id)->exists()) { + throw new DomainRuleException('Diese fachliche Säule gibt es schon.'); + } + + $pillar->name = $name; + $pillar->save(); + } + + public function delete(Pillar $pillar): void + { + if ($pillar->elements()->exists()) { + throw new DomainRuleException('Eine Säule mit zugeordneten Medien wird nicht gelöscht.'); + } + + $pillar->delete(); + } + + /** + * @param list $pillarIds + */ + public function assign(ContentElement $element, array $pillarIds): void + { + $ids = array_values(array_unique(array_map(intval(...), $pillarIds))); + + if (Pillar::query()->whereIn('id', $ids)->count() !== count($ids)) { + throw new DomainRuleException('Eine fachliche Säule fehlt.'); + } + + $element->pillars()->sync($ids); + } + + private function name(string $name): string + { + $name = trim($name); + + if ($name === '') { + throw new DomainRuleException('Der Name der fachlichen Säule fehlt.'); + } + + return $name; + } +} diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index a237fa5..ffe15e2 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -51,6 +51,13 @@ public function form(Schema $schema): Schema return new HtmlString(collect($lines)->map(fn (string $line): string => e($line))->implode('
')); }), + Placeholder::make('pillars')->label('Säulen der Medien')->content(function (): HtmlString { + /** @var Composition $composition */ + $composition = $this->getRecord(); + $lines = app(CatalogReading::class)->memberPillars($composition); + + return new HtmlString(collect($lines)->map(fn (string $line): string => e($line))->implode('
')); + }), Repeater::make('members') ->label('Bausteine der neuen Fassung') ->schema([ diff --git a/app/Filament/Resources/ContentElements/ContentElementResource.php b/app/Filament/Resources/ContentElements/ContentElementResource.php index c2d0c29..7135b3a 100644 --- a/app/Filament/Resources/ContentElements/ContentElementResource.php +++ b/app/Filament/Resources/ContentElements/ContentElementResource.php @@ -6,6 +6,7 @@ use App\Domain\Identity\StaffRole; use App\Filament\Resources\ContentElements\Pages\EditContentElement; use App\Filament\Resources\ContentElements\Pages\ListContentElements; +use App\Filament\Resources\ContentElements\Pages\ViewContentElement; use App\Models\User; use Filament\Facades\Filament; use Filament\Resources\Resource; @@ -34,7 +35,11 @@ class ContentElementResource extends Resource public static function canViewAny(): bool { - return self::editor(); + $user = Filament::auth()->user(); + + return $user instanceof User && ( + $user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter) + ); } public static function editor(): bool @@ -44,6 +49,11 @@ public static function editor(): bool return $user instanceof User && $user->hasStaffRole(StaffRole::Redakteur); } + public static function getViewAuthorizationResponse(Model $record): Response + { + return self::canViewAny() ? Response::allow() : Response::deny(); + } + public static function getEditAuthorizationResponse(Model $record): Response { return self::editor() ? Response::allow() : Response::deny(); @@ -56,9 +66,14 @@ public static function form(Schema $schema): Schema public static function table(Table $table): Table { - return $table->columns([ + return $table->recordUrl( + fn (ContentElement $record): string => static::getUrl('view', ['record' => $record]) + )->columns([ TextColumn::make('working_title')->label('Arbeitstitel')->searchable(), TextColumn::make('kind')->label('Art'), + TextColumn::make('pillar_names')->label('Säulen')->state( + fn (ContentElement $record): string => $record->pillars->pluck('name')->join(', ') ?: '—' + ), TextColumn::make('stand')->label('Aktuelle Fassung')->state(function (ContentElement $record): string { $version = $record->versions->sortByDesc('number')->first(); @@ -75,14 +90,15 @@ public static function table(Table $table): Table public static function getEloquentQuery(): Builder { - return parent::getEloquentQuery()->with('versions'); + return parent::getEloquentQuery()->with(['versions', 'pillars']); } public static function getPages(): array { return [ 'index' => ListContentElements::route('/'), - 'edit' => EditContentElement::route('/{record}'), + 'view' => ViewContentElement::route('/{record}'), + 'edit' => EditContentElement::route('/{record}/bearbeiten'), ]; } } diff --git a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php index 1936c9e..cae043b 100644 --- a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php @@ -3,25 +3,22 @@ namespace App\Filament\Resources\ContentElements\Pages; use App\Domain\Catalog\ContentElement; -use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentService; -use App\Domain\Catalog\ContentVersionStatus; use App\Domain\Catalog\DomainRuleException; +use App\Domain\Catalog\Pillar; +use App\Domain\Catalog\PillarService; use App\Filament\Resources\ContentElements\ContentElementResource; -use App\Filament\Support\CatalogReading; -use App\Filament\Support\IncomingFile; +use App\Filament\Support\ElementRevision; use App\Filament\Support\MediaUploadLimit; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; +use Filament\Forms\Components\CheckboxList; use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Placeholder; -use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; -use Filament\Forms\Components\Toggle; use Filament\Notifications\Notification; use Filament\Resources\Pages\EditRecord; -use Filament\Schemas\Components\Section; use Filament\Schemas\Schema; use Filament\Support\Exceptions\Halt; use Illuminate\Contracts\Support\Htmlable; @@ -34,44 +31,27 @@ class EditContentElement extends EditRecord protected static string $resource = ContentElementResource::class; - protected ?string $savedTitle = null; - public function getSubheading(): string|Htmlable|null { - return 'Speichern legt eine neue Fassung an. Die bisherige Fassung bleibt erhalten und kann weiter angesehen werden. Ohne neue Datei bleibt die vorhandene Datei der neuen Fassung zugeordnet.'; + return 'Arbeitstitel, Beschreibung und Säulen gehören zum Medium. Speichern legt keine neue Fassung an. Text und Datei änderst du über eine neue Fassung; die bisherige bleibt erhalten.'; } public function form(Schema $schema): Schema { return $schema->columns(1)->components([ + Placeholder::make('open')->label('Medium')->content(function (): HtmlString { + $url = ContentElementResource::getUrl('view', ['record' => $this->getRecord()]); + + return new HtmlString('Medium und Fassungen ansehen'); + }), TextInput::make('working_title')->label('Arbeitstitel')->required(), - Placeholder::make('history')->label('Bisherige Fassungen')->content(function (): HtmlString { - /** @var ContentElement $element */ - $element = $this->getRecord(); - $lines = app(CatalogReading::class)->elementVersions($element); - $html = collect($lines)->map(fn (string $line): string => e($line))->implode('
'); - $links = $element->versions()->orderByDesc('number')->get()->map(function (ContentElementVersion $version): string { - return 'Fassung '.$version->number.' ansehen'; - })->implode(' · '); - - return new HtmlString($html.($links !== '' ? '
'.$links : '')); - }), - Placeholder::make('usage')->label('Verwendung')->content(function (): HtmlString { - /** @var ContentElement $element */ - $element = $this->getRecord(); - $lines = app(CatalogReading::class)->elementUsage($element); - - return new HtmlString(collect($lines)->map(fn (string $line): string => e($line))->implode('
')); - }), - Section::make('Neue Fassung')->schema([ - Textarea::make('body')->label('Text')->rows(8), - self::uploadField(), - Toggle::make('drop_file') - ->label('Datei in der neuen Fassung nicht mehr verwenden') - ->visible(fn (): bool => is_string($this->latest()?->metadata['file'] ?? null)), - TextInput::make('decision_seconds')->label('Entscheidungsmarke in Sekunden')->numeric()->minValue(0), - TextInput::make('change_note')->label('Änderungsnotiz'), - ]), + Textarea::make('description')->label('Beschreibung')->rows(4) + ->helperText('Gilt für das Medium, nicht für eine einzelne Fassung.'), + CheckboxList::make('pillars') + ->label('Fachliche Säulen') + ->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all()) + ->helperText('Ein Medium kann mehreren Säulen zugeordnet sein. Weitere Säulen legst du unter Fachliche Säulen an.') + ->columns(1), ]); } @@ -89,32 +69,20 @@ public static function uploadField(): FileUpload protected function getHeaderActions(): array { return [ - Action::make('preview') - ->label('Aktuelle Fassung ansehen') - ->url(fn (): ?string => ($version = $this->latest()) === null ? null : route('content.preview', $version)) - ->visible(fn (): bool => $this->latest() !== null) - ->openUrlInNewTab(), - Action::make('block') - ->label('Fassung sperren') - ->visible(fn (): bool => $this->getRecord()->versions()->where('status', ContentVersionStatus::Bereit)->exists()) - ->schema([ - Select::make('version')->label('Fassung')->options(function (): array { - return $this->getRecord()->versions() - ->where('status', ContentVersionStatus::Bereit) - ->orderByDesc('number') - ->pluck('number', 'id') - ->map(fn ($number): string => 'Fassung '.$number) - ->all(); - })->required(), - Textarea::make('reason')->label('Begründung')->required(), - ]) + Action::make('view') + ->label('Ansehen') + ->url(fn (): string => ContentElementResource::getUrl('view', ['record' => $this->getRecord()])), + Action::make('revise') + ->label('Neue Fassung anlegen') + ->schema(fn (): array => ElementRevision::fields($this->getRecord())) ->action(function (array $data): void { - $this->report(function () use ($data): void { - $version = ContentElementVersion::query()->findOrFail($data['version']); - app(ContentService::class)->block($version, $data['reason']); - }, 'Die Fassung ist gesperrt.'); + $this->report(function () use ($data): string { + /** @var ContentElement $element */ + $element = $this->getRecord(); + + return ElementRevision::publish($element, $data); + }, 'Die neue Fassung ist angelegt.'); $this->getRecord()->unsetRelation('versions'); - $this->fillForm(); }), Action::make('delete') ->label('Löschen') @@ -130,12 +98,12 @@ protected function getHeaderActions(): array protected function getSaveFormAction(): Action { - return parent::getSaveFormAction()->label('Neue Fassung anlegen'); + return parent::getSaveFormAction()->label('Speichern'); } protected function getSavedNotificationTitle(): ?string { - return $this->savedTitle ?? 'Die neue Fassung ist angelegt.'; + return 'Gespeichert. Es gibt keine neue Fassung.'; } /** @@ -144,15 +112,10 @@ protected function getSavedNotificationTitle(): ?string */ protected function mutateFormDataBeforeFill(array $data): array { - $latest = $this->latest(); - $metadata = is_array($latest?->metadata) ? $latest->metadata : []; - return [ 'working_title' => $this->getRecord()->working_title, - 'body' => $latest?->body, - 'decision_seconds' => $metadata['decision_seconds'] ?? null, - 'drop_file' => false, - 'change_note' => null, + 'description' => $this->getRecord()->description, + 'pillars' => $this->getRecord()->pillars()->pluck('pillars.id')->all(), ]; } @@ -163,52 +126,8 @@ protected function handleRecordUpdate(Model $record, array $data): Model { /** @var ContentElement $record */ try { - $record->working_title = trim((string) $data['working_title']); - $record->save(); - - $latest = $record->versions()->orderByDesc('number')->first(); - $metadata = []; - $incoming = IncomingFile::store($data['incoming'] ?? null); - $dropFile = (bool) ($data['drop_file'] ?? false); - $previousFile = is_array($latest?->metadata) ? ($latest->metadata['file'] ?? null) : null; - - if (is_string($incoming) && $incoming !== '') { - $metadata['incoming'] = $incoming; - } elseif (! $dropFile && is_string($previousFile) && $previousFile !== '') { - $metadata['file'] = $previousFile; - } - - $decision = is_numeric($data['decision_seconds'] ?? null) ? (int) $data['decision_seconds'] : null; - - if ($decision !== null) { - $metadata['decision_seconds'] = $decision; - } - - $body = is_string($data['body'] ?? null) ? $data['body'] : null; - $note = is_string($data['change_note'] ?? null) ? $data['change_note'] : null; - $previousDecision = is_array($latest?->metadata) && is_numeric($latest->metadata['decision_seconds'] ?? null) - ? (int) $latest->metadata['decision_seconds'] - : null; - $changed = $incoming !== null - || $dropFile - || trim((string) $body) !== trim((string) $latest?->body) - || $decision !== $previousDecision - || (is_string($note) && trim($note) !== ''); - - if (! $changed) { - $this->savedTitle = 'Der Arbeitstitel ist geändert. Text und Datei sind gleich geblieben, deshalb gibt es keine neue Fassung.'; - - return $record; - } - - if (trim((string) $body) === '' && $metadata === []) { - throw new DomainRuleException('Eine neue Fassung braucht einen Text oder eine Datei.'); - } - - app(ContentService::class)->publishElementVersion($record, $body, $metadata, $note); - $this->savedTitle = $incoming !== null - ? 'Die neue Fassung ist angelegt. Die Datei wird übernommen; die bisherige Fassung bleibt.' - : 'Die neue Fassung ist angelegt. Die bisherige Fassung bleibt erhalten.'; + app(ContentService::class)->describe($record, (string) $data['working_title'], $data['description'] ?? null); + app(PillarService::class)->assign($record, array_map(intval(...), $data['pillars'] ?? [])); } catch (DomainRuleException $exception) { Notification::make()->title($exception->getMessage())->danger()->send(); @@ -217,19 +136,4 @@ protected function handleRecordUpdate(Model $record, array $data): Model return $record; } - - protected function afterSave(): void - { - $this->getRecord()->unsetRelation('versions'); - $this->getRecord()->refresh(); - $this->fillForm(); - } - - private function latest(): ?ContentElementVersion - { - /** @var ContentElement $element */ - $element = $this->getRecord(); - - return $element->versions()->orderByDesc('number')->first(); - } } diff --git a/app/Filament/Resources/ContentElements/Pages/ListContentElements.php b/app/Filament/Resources/ContentElements/Pages/ListContentElements.php index 15b5f5f..f1dec60 100644 --- a/app/Filament/Resources/ContentElements/Pages/ListContentElements.php +++ b/app/Filament/Resources/ContentElements/Pages/ListContentElements.php @@ -76,7 +76,7 @@ protected function getHeaderActions(): array }, 'Das Medium ist angelegt.'); if ($element !== null) { - $this->redirect(ContentElementResource::getUrl('edit', ['record' => $element])); + $this->redirect(ContentElementResource::getUrl('view', ['record' => $element])); } }), ]; diff --git a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php new file mode 100644 index 0000000..72fff7b --- /dev/null +++ b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php @@ -0,0 +1,161 @@ +integer('fassung'); + + if ($requested > 0) { + $this->fassung = $requested; + } + } + + public function getSubheading(): string|Htmlable|null + { + return 'Jede Fassung hat eine eigene Nummer und bleibt einsehbar. Beschreibung, Arbeitstitel und Säulen gehören zum Medium und ändern keine Fassung. Eine deaktivierte Fassung wird nicht mehr ausgeliefert und lässt sich nicht neu einbauen.'; + } + + public function infolist(Schema $schema): Schema + { + return $schema->components([ + View::make('filament.media.viewer')->viewData(fn (): array => $this->viewerData()), + ]); + } + + public function showVersion(int $version): void + { + abort_unless($this->ownedVersion($version) instanceof ContentElementVersion, 404); + $this->fassung = $version; + } + + public function deactivateAction(): Action + { + return Action::make('deactivate') + ->label('Deaktivieren') + ->modalHeading('Fassung deaktivieren') + ->modalDescription('Die Fassung bleibt hier einsehbar. Sie wird nicht mehr ausgeliefert und kann nicht in eine neue Übung oder einen neuen Kurs übernommen werden.') + ->modalSubmitActionLabel('Deaktivieren') + ->visible(fn (): bool => ContentElementResource::editor()) + ->schema([ + Textarea::make('reason')->label('Begründung')->required(), + ]) + ->action(function (array $data, array $arguments): void { + abort_unless(ContentElementResource::editor(), 403); + $this->report(function () use ($data, $arguments): void { + $version = $this->ownedVersion((int) ($arguments['version'] ?? 0)); + abort_unless($version instanceof ContentElementVersion, 404); + app(ContentService::class)->block($version, (string) $data['reason']); + }, 'Die Fassung ist deaktiviert.'); + $this->getRecord()->unsetRelation('versions'); + }); + } + + protected function getHeaderActions(): array + { + return [ + Action::make('describe') + ->label('Beschreibung ändern') + ->visible(fn (): bool => ContentElementResource::editor()) + ->fillForm(fn (): array => [ + 'working_title' => $this->getRecord()->working_title, + 'description' => $this->getRecord()->description, + 'pillars' => $this->getRecord()->pillars()->pluck('pillars.id')->all(), + ]) + ->schema([ + TextInput::make('working_title')->label('Arbeitstitel')->required(), + Textarea::make('description')->label('Beschreibung')->rows(4) + ->helperText('Gilt für das Medium. Speichern legt keine neue Fassung an.'), + CheckboxList::make('pillars') + ->label('Fachliche Säulen') + ->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all()), + ]) + ->action(function (array $data): void { + $this->report(function () use ($data): void { + /** @var ContentElement $element */ + $element = $this->getRecord(); + app(ContentService::class)->describe($element, (string) $data['working_title'], $data['description'] ?? null); + app(PillarService::class)->assign($element, array_map(intval(...), $data['pillars'] ?? [])); + }, 'Die Beschreibung ist gespeichert.'); + $this->getRecord()->refresh(); + }), + Action::make('revise') + ->label('Neue Fassung anlegen') + ->visible(fn (): bool => ContentElementResource::editor()) + ->schema(fn (): array => ElementRevision::fields($this->getRecord())) + ->action(function (array $data): void { + $this->report(function () use ($data): string { + /** @var ContentElement $element */ + $element = $this->getRecord(); + + return ElementRevision::publish($element, $data); + }, 'Die neue Fassung ist angelegt.'); + $this->getRecord()->unsetRelation('versions'); + }), + ]; + } + + /** + * @return array{element: ContentElement, versions: Collection, shown: ?ContentElementVersion, fileUrl: ?string, pending: bool, pillars: list, usage: list, canRevise: bool} + */ + private function viewerData(): array + { + /** @var ContentElement $element */ + $element = $this->getRecord(); + $versions = $element->versions()->orderByDesc('number')->get(); + $shown = $versions->firstWhere('id', $this->fassung) + ?? $versions->first(fn (ContentElementVersion $version): bool => $version->status === ContentVersionStatus::Bereit) + ?? $versions->first(); + $preview = app(ContentPreviewController::class); + + return [ + 'element' => $element, + 'versions' => $versions, + 'shown' => $shown, + 'fileUrl' => $shown === null ? null : $preview->fileUrl($shown), + 'pending' => $shown !== null && $preview->isPending($shown), + 'pillars' => $element->pillars->pluck('name')->all(), + 'usage' => app(CatalogReading::class)->elementUsage($element), + 'canRevise' => ContentElementResource::editor(), + ]; + } + + private function ownedVersion(int $id): ?ContentElementVersion + { + /** @var ContentElement $element */ + $element = $this->getRecord(); + + return $element->versions()->whereKey($id)->first(); + } +} diff --git a/app/Filament/Resources/Pillars/Pages/EditPillar.php b/app/Filament/Resources/Pillars/Pages/EditPillar.php new file mode 100644 index 0000000..79c8a13 --- /dev/null +++ b/app/Filament/Resources/Pillars/Pages/EditPillar.php @@ -0,0 +1,58 @@ +label('Löschen') + ->color('danger') + ->requiresConfirmation() + ->action(function (): void { + /** @var Pillar $pillar */ + $pillar = $this->getRecord(); + $deleted = false; + $this->report(function () use ($pillar, &$deleted): void { + app(PillarService::class)->delete($pillar); + $deleted = true; + }, 'Die Säule ist gelöscht.'); + + if ($deleted) { + $this->redirect(PillarResource::getUrl('index')); + } + }), + ]; + } + + protected function handleRecordUpdate(Model $record, array $data): Model + { + /** @var Pillar $record */ + try { + app(PillarService::class)->rename($record, $data['name']); + } catch (DomainRuleException $exception) { + Notification::make()->title($exception->getMessage())->danger()->send(); + + throw new Halt; + } + + return $record; + } +} diff --git a/app/Filament/Resources/Pillars/Pages/ListPillars.php b/app/Filament/Resources/Pillars/Pages/ListPillars.php new file mode 100644 index 0000000..e5052db --- /dev/null +++ b/app/Filament/Resources/Pillars/Pages/ListPillars.php @@ -0,0 +1,46 @@ +label('Säule anlegen') + ->visible(fn (): bool => ContentElementResource::editor()) + ->schema([ + TextInput::make('name')->label('Name')->required(), + ]) + ->action(function (array $data): void { + $pillar = null; + $this->report(function () use ($data, &$pillar): void { + $pillar = app(PillarService::class)->create($data['name']); + }, 'Die Säule ist angelegt.'); + + if ($pillar !== null) { + $this->redirect(PillarResource::getUrl('edit', ['record' => $pillar])); + } + }), + ]; + } +} diff --git a/app/Filament/Resources/Pillars/PillarResource.php b/app/Filament/Resources/Pillars/PillarResource.php new file mode 100644 index 0000000..9e80f15 --- /dev/null +++ b/app/Filament/Resources/Pillars/PillarResource.php @@ -0,0 +1,67 @@ +components([ + TextInput::make('name')->label('Name')->required(), + ]); + } + + public static function table(Table $table): Table + { + return $table->columns([ + TextColumn::make('name')->label('Name')->searchable(), + TextColumn::make('elements_count')->counts('elements')->label('Medien'), + ]); + } + + public static function getPages(): array + { + return [ + 'index' => ListPillars::route('/'), + 'edit' => EditPillar::route('/{record}'), + ]; + } +} diff --git a/app/Filament/Support/CatalogReading.php b/app/Filament/Support/CatalogReading.php index adbcc8d..d9ca6f1 100644 --- a/app/Filament/Support/CatalogReading.php +++ b/app/Filament/Support/CatalogReading.php @@ -10,6 +10,8 @@ use App\Domain\Catalog\CompositionKind; use App\Domain\Catalog\CompositionMember; use App\Domain\Catalog\ContentElement; +use App\Domain\Catalog\ContentElementVersion; +use App\Domain\Catalog\ContentResolver; use App\Domain\Catalog\ContentVersionStatus; use App\Domain\Catalog\DomainRuleException; use App\Domain\Catalog\LicenseArticle; @@ -317,6 +319,37 @@ public function compositionMembers(Composition $composition): array return $lines; } + /** + * @return list + */ + public function memberPillars(Composition $composition): array + { + $version = $composition->versions() + ->where('status', ContentVersionStatus::Bereit) + ->orderByDesc('number') + ->first(); + + if ($version === null) { + return ['Noch keine Fassung, deshalb keine Säulen.']; + } + + $rows = app(ContentResolver::class)->expand($version); + $versions = ContentElementVersion::query() + ->whereIn('id', array_column($rows, 'version_id')) + ->with('element.pillars') + ->get() + ->keyBy('id'); + $lines = []; + + foreach ($rows as $row) { + $element = $versions[$row['version_id']]->element; + $names = $element->pillars->pluck('name'); + $lines[] = $element->working_title.' — '.($names->isEmpty() ? 'keiner Säule zugeordnet' : $names->join(', ')); + } + + return $lines === [] ? ['Diese Fassung enthält keine Medien.'] : $lines; + } + /** * @return list */ diff --git a/app/Filament/Support/ElementRevision.php b/app/Filament/Support/ElementRevision.php new file mode 100644 index 0000000..c253142 --- /dev/null +++ b/app/Filament/Support/ElementRevision.php @@ -0,0 +1,103 @@ + $data + */ + public static function publish(ContentElement $record, array $data): string + { + $latest = $record->versions()->orderByDesc('number')->first(); + $metadata = []; + $incoming = IncomingFile::store($data['incoming'] ?? null); + $dropFile = (bool) ($data['drop_file'] ?? false); + $previousFile = is_array($latest?->metadata) ? ($latest->metadata['file'] ?? null) : null; + + if (is_string($incoming) && $incoming !== '') { + $metadata['incoming'] = $incoming; + } elseif (! $dropFile && is_string($previousFile) && $previousFile !== '') { + $metadata['file'] = $previousFile; + } + + $decision = is_numeric($data['decision_seconds'] ?? null) ? (int) $data['decision_seconds'] : null; + + if ($decision !== null) { + $metadata['decision_seconds'] = $decision; + } + + $body = is_string($data['body'] ?? null) ? $data['body'] : null; + $note = is_string($data['change_note'] ?? null) ? $data['change_note'] : null; + $previousDecision = is_array($latest?->metadata) && is_numeric($latest->metadata['decision_seconds'] ?? null) + ? (int) $latest->metadata['decision_seconds'] + : null; + $changed = $incoming !== null + || $dropFile + || trim((string) $body) !== trim((string) $latest?->body) + || $decision !== $previousDecision + || (is_string($note) && trim($note) !== ''); + + if (! $changed) { + return 'Text und Datei sind gleich geblieben, deshalb gibt es keine neue Fassung.'; + } + + if (trim((string) $body) === '' && $metadata === []) { + throw new DomainRuleException('Eine neue Fassung braucht einen Text oder eine Datei.'); + } + + app(ContentService::class)->publishElementVersion($record, $body, $metadata, $note); + + return $incoming !== null + ? 'Die neue Fassung ist angelegt. Die Datei wird übernommen; die bisherige Fassung bleibt.' + : 'Die neue Fassung ist angelegt. Die bisherige Fassung bleibt erhalten.'; + } + + /** + * @return list + */ + public static function fields(ContentElement $element): array + { + $latest = $element->versions()->orderByDesc('number')->first(); + + return [ + Textarea::make('body')->label('Text')->rows(8)->default($latest?->body), + EditContentElement::uploadField(), + Toggle::make('drop_file') + ->label('Datei in der neuen Fassung nicht mehr verwenden') + ->visible(fn (): bool => is_string(self::fileOf($element))), + TextInput::make('decision_seconds') + ->label('Entscheidungsmarke in Sekunden') + ->numeric() + ->minValue(0) + ->default(self::decisionOf($latest)), + TextInput::make('change_note')->label('Änderungsnotiz'), + ]; + } + + private static function fileOf(ContentElement $element): mixed + { + $latest = $element->versions()->orderByDesc('number')->first(); + + return is_array($latest?->metadata) ? ($latest->metadata['file'] ?? null) : null; + } + + private static function decisionOf(?ContentElementVersion $version): ?int + { + if (! is_array($version?->metadata) || ! is_numeric($version->metadata['decision_seconds'] ?? null)) { + return null; + } + + return (int) $version->metadata['decision_seconds']; + } +} diff --git a/app/Http/Controllers/ContentPreviewController.php b/app/Http/Controllers/ContentPreviewController.php index 44804df..7dbe05a 100644 --- a/app/Http/Controllers/ContentPreviewController.php +++ b/app/Http/Controllers/ContentPreviewController.php @@ -11,25 +11,63 @@ class ContentPreviewController extends Controller { - public function __invoke(ContentElementVersion $version): View|StreamedResponse + public function show(ContentElementVersion $version): View + { + $this->authorizeStaff(); + $version->loadMissing('element'); + + return view('content.preview', [ + 'version' => $version, + 'fileUrl' => $this->fileUrl($version), + 'pending' => $this->isPending($version), + ]); + } + + public function file(ContentElementVersion $version): StreamedResponse + { + $this->authorizeStaff(); + $path = $this->storedPath($version); + abort_unless(is_string($path), 404); + + return Storage::disk('media_derived')->response($path, basename($path), [ + 'Content-Disposition' => 'inline', + ]); + } + + public function fileUrl(ContentElementVersion $version): ?string + { + return $this->storedPath($version) === null ? null : route('content.file', $version); + } + + public function isPending(ContentElementVersion $version): bool + { + if ($this->storedPath($version) !== null) { + return false; + } + + $metadata = is_array($version->metadata) ? $version->metadata : []; + $incoming = $metadata['incoming'] ?? null; + + return (is_string($incoming) && $incoming !== '') || is_array($incoming); + } + + private function storedPath(ContentElementVersion $version): ?string + { + $file = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null; + + if (! is_string($file) || $file === '' || str_contains($file, '..') || ! str_starts_with($file, 'inhalte/')) { + return null; + } + + return Storage::disk('media_derived')->exists($file) ? $file : null; + } + + private function authorizeStaff(): void { $user = auth('staff')->user(); abort_unless( $user instanceof User && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)), 403, ); - - $version->loadMissing('element'); - $file = $version->metadata['file'] ?? null; - - if (is_string($file) && $file !== '' && ! str_contains($file, '..') && Storage::disk('media_derived')->exists($file)) { - return Storage::disk('media_derived')->response($file, basename($file), [ - 'Content-Disposition' => 'inline', - ]); - } - - return view('content.preview', [ - 'version' => $version, - ]); } } diff --git a/app/Http/Controllers/Member/LibraryController.php b/app/Http/Controllers/Member/LibraryController.php index 07d5c54..713eaf5 100644 --- a/app/Http/Controllers/Member/LibraryController.php +++ b/app/Http/Controllers/Member/LibraryController.php @@ -44,7 +44,7 @@ public function grants(Request $request): View public function show(Request $request, LicenseArticle $article): View { - $release = $article->currentRelease()->with('contents.elementVersion.element')->first(); + $release = $article->currentRelease()->with('contents.elementVersion.element.pillars')->first(); $entries = []; if ($release !== null) { @@ -66,6 +66,7 @@ public function show(Request $request, LicenseArticle $article): View ? (int) $metadata['decision_seconds'] : null, 'playable' => $decision->allowed && is_string($file) && $file !== '' && ($class === 'film' || $class === 'audio'), + 'pillars' => $version->element->pillars->pluck('name')->all(), 'url' => $decision->allowed ? SignedLink::temporary('member.media', now()->addMinutes(10), [ 'article' => $article->id, diff --git a/database/migrations/2026_11_15_150000_create_pillars.php b/database/migrations/2026_11_15_150000_create_pillars.php new file mode 100644 index 0000000..4034280 --- /dev/null +++ b/database/migrations/2026_11_15_150000_create_pillars.php @@ -0,0 +1,29 @@ +id(); + $table->string('name')->unique(); + $table->timestamps(); + }); + + Schema::create('content_element_pillar', function (Blueprint $table) { + $table->foreignId('content_element_id')->constrained()->cascadeOnDelete(); + $table->foreignId('pillar_id')->constrained()->restrictOnDelete(); + $table->primary(['content_element_id', 'pillar_id']); + }); + } + + public function down(): void + { + Schema::dropIfExists('content_element_pillar'); + Schema::dropIfExists('pillars'); + } +}; diff --git a/database/migrations/2026_11_15_160000_add_media_description.php b/database/migrations/2026_11_15_160000_add_media_description.php new file mode 100644 index 0000000..9af019f --- /dev/null +++ b/database/migrations/2026_11_15_160000_add_media_description.php @@ -0,0 +1,30 @@ +text('description')->nullable(); + }); + + Schema::table('content_element_versions', function (Blueprint $table) { + $table->text('block_reason')->nullable(); + }); + } + + public function down(): void + { + Schema::table('content_elements', function (Blueprint $table) { + $table->dropColumn('description'); + }); + + Schema::table('content_element_versions', function (Blueprint $table) { + $table->dropColumn('block_reason'); + }); + } +}; diff --git a/docs/betrieb/MVP-Stand.md b/docs/betrieb/MVP-Stand.md index 3913b5a..103ed04 100644 --- a/docs/betrieb/MVP-Stand.md +++ b/docs/betrieb/MVP-Stand.md @@ -9,7 +9,7 @@ ## Bedienbar - Lizenzartikel, verschachtelte Pakete, Rechteprofile und Angebote als Katalogverwalter. Die jeweilige Seite zeigt den Stand, die Bestandteile, die aufgelösten Artikel und die daraus entstehenden Berechtigungen. Ein neuer Stand zeigt Inhaber, Angebote und Inhaltszahl; ein Rückzug stellt den vorherigen Stand wieder her und nennt die Betroffenen. - Manuelle Vergabe als Kundenbetreuung, am Benutzer in der Verwaltung. - Registrierung, Anmeldung, kostenloser Abruf, Testkauf, Ablehnung und Widerruf im Mitgliederbereich. Die Verwaltung fragt den Authenticator-Code auf demselben Browser 30 Tage lang nicht erneut ab. In der Authenticator-App heißt der Eintrag „Lara&Felix“, außerhalb der Produktion „Lara&Felix (dev)“. Ein bestehender Eintrag übernimmt den Namen erst bei erneuter Einrichtung. -- Medien werden in der Verwaltung angelegt, mit Datei oder Text versehen und als neue Fassung fortgeschrieben. Eine Datei darf bis 2 GB groß sein. Die bisherige Fassung bleibt. Übungen, Kurse und fachliche Kombinationen sind getrennte Zusammenstellungen; ihre Bausteine lassen sich hinzufügen, tauschen und aus der neuen Fassung nehmen. +- Medien werden in der Verwaltung angelegt und geöffnet: die Datei oder der Text der gewählten Fassung ist dort sichtbar. Jede Fassung hat eine eigene Nummer. Beschreibung, Arbeitstitel und Säulen gehören zum Medium und ändern keine Fassung. Eine deaktivierte Fassung bleibt einsehbar, wird nicht mehr ausgeliefert und lässt sich nicht neu einbauen. Eine Datei darf bis 2 GB groß sein. Ein Medium kann mehreren fachlichen Säulen zugeordnet sein; weitere Säulen lassen sich anlegen. Übungen, Kurse und fachliche Kombinationen sind getrennte Zusammenstellungen; ihre Bausteine lassen sich hinzufügen, tauschen und aus der neuen Fassung nehmen. - Kurse im Mitgliederbereich zeigen den Namen der Übung, die Bausteine in Reihenfolge und einen Player. Ein Film mit Entscheidungsmarke lässt sich an dieser Stelle pausieren und von vorn starten. Die Verwaltung zeigt den Text einer Fassung und, sobald die Datei übernommen ist, die Datei selbst. - Bibliothek entscheidet je Abruf erneut. Filme mit Datei werden im Player geladen, Texte und PDF über einen kurz signierten Abruf. diff --git a/resources/views/content/player.blade.php b/resources/views/content/player.blade.php new file mode 100644 index 0000000..cb3a4e4 --- /dev/null +++ b/resources/views/content/player.blade.php @@ -0,0 +1,27 @@ +@php + $metadata = is_array($version->metadata) ? $version->metadata : []; + $class = $version->element->output_class; +@endphp + +@if ($fileUrl) + @if ($class === 'film') + + @elseif ($class === 'audio') + + @elseif ($class === 'bild') + {{ $version->element->working_title }} + @else + + @endif +

Datei öffnen

+@elseif ($pending) +

Die Datei wird noch übernommen.

+@elseif (is_string($metadata['file'] ?? null)) +

Für Fassung {{ $version->number }} ist eine Datei vorgemerkt, sie liegt aber nicht vor.

+@endif + +@if (filled($version->body)) +
+ {!! nl2br(e($version->body)) !!} +
+@endif diff --git a/resources/views/content/preview.blade.php b/resources/views/content/preview.blade.php index de2633d..81eb063 100644 --- a/resources/views/content/preview.blade.php +++ b/resources/views/content/preview.blade.php @@ -4,12 +4,9 @@ @section('content')

{{ $version->element->working_title }}

-

Fassung {{ $version->number }}, nur für die Redaktion.

- @if (filled($version->body)) -
- {!! nl2br(e($version->body)) !!} -
- @else +

Fassung {{ $version->number }}, nur für die Verwaltung.

+ @include('content.player', ['version' => $version, 'fileUrl' => $fileUrl, 'pending' => $pending]) + @if (! $fileUrl && ! $pending && blank($version->body))

Für diese Fassung liegt noch kein lesbarer Text und keine übernommene Datei vor.

diff --git a/resources/views/filament/media/viewer.blade.php b/resources/views/filament/media/viewer.blade.php new file mode 100644 index 0000000..8a3b7f7 --- /dev/null +++ b/resources/views/filament/media/viewer.blade.php @@ -0,0 +1,69 @@ +@php + use App\Domain\Catalog\ContentVersionStatus; +@endphp + +
+
+

{{ $element->working_title }}

+ @if (filled($element->description)) +

{{ $element->description }}

+ @else +

Noch keine Beschreibung. Beschreibung, Arbeitstitel und Säulen lassen sich ändern, ohne eine neue Fassung anzulegen.

+ @endif +

{{ $pillars === [] ? 'Keiner Säule zugeordnet.' : implode(' · ', $pillars) }}

+
+ +
+ @if ($shown === null) +

Noch keine Fassung.

+ @else +

Fassung {{ $shown->number }}

+ @include('content.player', ['version' => $shown, 'fileUrl' => $fileUrl, 'pending' => $pending]) + @if (! $fileUrl && ! $pending && blank($shown->body) && ! is_string((is_array($shown->metadata) ? $shown->metadata : [])['file'] ?? null)) +

Für diese Fassung liegt noch kein Text und keine Datei vor.

+ @endif + @endif +
+ +
+

Fassungen

+ @if ($versions->isEmpty()) +

Noch keine Fassung.

+ @else +
    + @foreach ($versions as $version) + @php + $status = match ($version->status) { + ContentVersionStatus::Gesperrt => 'deaktiviert', + ContentVersionStatus::Entwurf => 'Entwurf', + default => 'bereit', + }; + @endphp +
  • + Fassung {{ $version->number }} + {{ $status }}@if (filled($version->change_note)) · {{ $version->change_note }}@endif + @if (filled($version->block_reason)) + Begründung: {{ $version->block_reason }} + @endif + + + Im eigenen Tab + @if ($canRevise && $version->status === ContentVersionStatus::Bereit) + + @endif + +
  • + @endforeach +
+ @endif +
+ + @if ($usage !== []) +
+

Verwendung

+ @foreach ($usage as $line) +

{{ $line }}

+ @endforeach +
+ @endif +
diff --git a/resources/views/member/article.blade.php b/resources/views/member/article.blade.php index 5e2b65e..d917547 100644 --- a/resources/views/member/article.blade.php +++ b/resources/views/member/article.blade.php @@ -20,6 +20,12 @@ @foreach ($entries as $entry)
  • {{ $entry['role'] }}: {{ $entry['version']->element->working_title }}

    + @if (filled($entry['version']->element->description)) +

    {{ $entry['version']->element->description }}

    + @endif + @if ($entry['pillars'] !== []) +

    {{ implode(' · ', $entry['pillars']) }}

    + @endif @if ($entry['playable'])

    diff --git a/routes/web.php b/routes/web.php index e2f3fe9..99c1414 100644 --- a/routes/web.php +++ b/routes/web.php @@ -29,9 +29,12 @@ Route::post('/abmelden', [SessionController::class, 'destroy'])->middleware('auth')->name('logout'); -Route::get('/redaktion/inhalt/{version}', ContentPreviewController::class) +Route::get('/redaktion/inhalt/{version}', [ContentPreviewController::class, 'show']) ->middleware('auth:staff') ->name('content.preview'); +Route::get('/redaktion/inhalt/{version}/datei', [ContentPreviewController::class, 'file']) + ->middleware('auth:staff') + ->name('content.file'); Route::middleware('auth')->group(function () { Route::get('/email/bestaetigen', [EmailVerificationController::class, 'notice'])->name('verification.notice'); diff --git a/tests/Feature/CatalogAdministrationTest.php b/tests/Feature/CatalogAdministrationTest.php index ef65981..dffcc03 100644 --- a/tests/Feature/CatalogAdministrationTest.php +++ b/tests/Feature/CatalogAdministrationTest.php @@ -96,8 +96,10 @@ public function test_catalog_pages_show_contents_packages_and_resolved_rights(): $sheet->load('element'); $this->actingAs($editor, 'staff') - ->get(ContentElementResource::getUrl('edit', ['record' => $sheet->element])) + ->get(ContentElementResource::getUrl('view', ['record' => $sheet->element])) ->assertOk() + ->assertSee('Hinweis für die Prüfung.') + ->assertSee('Fassung 1') ->assertSee('Übung: Übung Alltag') ->assertSee('Lizenzartikel demo-merkblatt') ->assertSee('Neue Fassung anlegen'); diff --git a/tests/Feature/MediaAdministrationTest.php b/tests/Feature/MediaAdministrationTest.php index 419afb3..8e784e1 100644 --- a/tests/Feature/MediaAdministrationTest.php +++ b/tests/Feature/MediaAdministrationTest.php @@ -7,6 +7,7 @@ use App\Filament\Resources\Combinations\CombinationResource; use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Resources\ContentElements\Pages\EditContentElement; +use App\Filament\Resources\ContentElements\Pages\ViewContentElement; use App\Filament\Resources\Courses\CourseResource; use App\Filament\Resources\Exercises\ExerciseResource; use App\Filament\Resources\Exercises\Pages\EditExercise; @@ -39,15 +40,14 @@ public function test_a_medium_keeps_the_old_version_when_a_new_one_is_saved(): v $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); $this->actingAs($editor, 'staff'); - Livewire::test(EditContentElement::class, ['record' => $element->getKey()]) + Livewire::test(ViewContentElement::class, ['record' => $element->getKey()]) ->assertOk() ->assertSee('Erste Fassung') - ->fillForm([ - 'working_title' => 'Merkblatt', + ->assertSee('Fassung 1') + ->callAction('revise', [ 'body' => 'Zweite Fassung', 'change_note' => 'Korrektur', ]) - ->call('save') ->assertHasNoFormErrors(); $versions = $element->versions()->orderBy('number')->get(); @@ -69,14 +69,13 @@ public function test_an_uploaded_file_becomes_a_ready_version(): void $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); $this->actingAs($editor, 'staff'); - Livewire::test(EditContentElement::class, ['record' => $element->getKey()]) - ->fillForm([ + Livewire::test(ViewContentElement::class, ['record' => $element->getKey()]) + ->callAction('revise', [ 'working_title' => 'Übungsfilm', 'body' => 'Anleitung zum Film', 'incoming' => ['inhalte/film.mp4'], 'decision_seconds' => 12, ]) - ->call('save') ->assertHasNoFormErrors(); $version = $element->versions()->first(); @@ -150,5 +149,58 @@ public function test_a_catalog_keeper_cannot_edit_media(): void $this->actingAs($keeper, 'staff') ->get(ContentElementResource::getUrl('edit', ['record' => $element])) ->assertForbidden(); + + $version = app(ContentService::class)->publishElementVersion($element, 'Sichtbarer Text'); + + $this->actingAs($keeper, 'staff') + ->get(ContentElementResource::getUrl('view', ['record' => $element])) + ->assertOk() + ->assertSee('Fassung 1') + ->assertSee('Sichtbarer Text') + ->assertDontSee('Beschreibung ändern'); + } + + public function test_a_description_does_not_create_a_version_and_an_older_version_can_be_deactivated(): void + { + Storage::fake('media_derived'); + Storage::disk('media_derived')->put('inhalte/film.mp4', 'filmbytes'); + $content = app(ContentService::class); + $element = $content->createElement('film', 'film', 'Übungsfilm'); + $first = $content->publishElementVersion($element, 'Erste Fassung', ['file' => 'inhalte/film.mp4']); + $second = $content->publishElementVersion($element, 'Zweite Fassung', ['file' => 'inhalte/film.mp4']); + $editor = User::factory()->redakteur()->create(); + $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + $this->actingAs($editor, 'staff'); + + Livewire::test(EditContentElement::class, ['record' => $element->getKey()]) + ->fillForm([ + 'working_title' => 'Übungsfilm', + 'description' => 'Für die Gruppe', + 'pillars' => [], + ]) + ->call('save') + ->assertHasNoFormErrors(); + + $this->assertSame(2, $element->versions()->count()); + $this->assertSame('Für die Gruppe', $element->fresh()->description); + + Livewire::test(ViewContentElement::class, ['record' => $element->getKey()]) + ->assertSee('Fassung 1') + ->assertSee('Fassung 2') + ->assertSee('assertSee(route('content.file', $second), false) + ->callAction('deactivate', ['reason' => 'Veraltet'], ['version' => $first->id]) + ->assertHasNoFormErrors() + ->assertSee('deaktiviert'); + + $first->refresh(); + + $this->assertSame(ContentVersionStatus::Gesperrt, $first->status); + $this->assertSame('Veraltet', $first->block_reason); + $this->assertSame(ContentVersionStatus::Bereit, $element->versions()->where('number', 2)->first()->status); + + $this->actingAs($editor, 'staff') + ->get(route('content.file', $first)) + ->assertOk(); } } diff --git a/tests/Feature/PillarAssignmentTest.php b/tests/Feature/PillarAssignmentTest.php new file mode 100644 index 0000000..61a309d --- /dev/null +++ b/tests/Feature/PillarAssignmentTest.php @@ -0,0 +1,74 @@ +create('Grenzen'); + $hilfe = $pillars->create('Hilfe holen'); + $pillars->create('Alltag'); + $content = app(ContentService::class); + $filmElement = $content->createElement('film', 'film', 'Film'); + $film = $content->publishElementVersion($filmElement, 'Text'); + $sheet = $content->publishElementVersion($content->createElement('pdf', 'pdf', 'Blatt'), 'Hinweis'); + $pillars->assign($filmElement, [$hilfe->id, $grenzen->id]); + $pillars->assign($sheet->element, [$grenzen->id]); + + $this->assertSame(1, $filmElement->versions()->count()); + $this->assertSame(['Grenzen', 'Hilfe holen'], $filmElement->pillars()->pluck('name')->all()); + + $exercise = $content->publishComposition( + $content->createComposition('Übung Grenzen', CompositionKind::Uebung), + [ + ['role' => 'Film', 'target' => $film], + ['role' => 'Blatt', 'target' => $sheet], + ], + ); + $course = $content->publishComposition( + $content->createComposition('Kurs Alltag', CompositionKind::Kurs), + [['role' => 'Übung', 'target' => $exercise]], + ); + + $this->assertSame([ + 'Film — Grenzen, Hilfe holen', + 'Blatt — Grenzen', + ], app(CatalogReading::class)->memberPillars($course->composition)); + + $editor = User::factory()->redakteur()->create(); + $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + $this->actingAs($editor, 'staff') + ->get(PillarResource::getUrl('index')) + ->assertOk() + ->assertSee('Grenzen') + ->assertSee('Alltag') + ->assertSee('weitere hinzukommen'); + } + + public function test_a_pillar_with_media_cannot_be_deleted(): void + { + $pillars = app(PillarService::class); + $pillar = $pillars->create('Grenzen'); + $element = app(ContentService::class)->createElement('text', 'text', 'Hinweis'); + $pillars->assign($element, [$pillar->id]); + + $this->expectException(DomainRuleException::class); + + $pillars->delete($pillar); + } +}