From ef56befc0eaf83a22047ba5fd7ffc10ad002541e Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 23 Nov 2026 16:39:31 +0100 Subject: [PATCH] =?UTF-8?q?Sch=C3=BCtze=20den=20vorherigen=20Programmstand?= =?UTF-8?q?=20vor=20Kompositionen=20unbekannter=20Art?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eine Komposition mit einem kind-Wert, den erst ein neuerer Stand schreibt, gilt als nicht vorhanden (globaler Bereichsfilter statt Absturz im Enum-Cast). Aufbauten mit solchen Bestandteilen werden hier weder veröffentlicht noch als Angebot aktiviert, der Editor bleibt schreibgeschützt, die Mitgliederansicht zeigt den Bestandteil nicht. Grundlage für die Übungsverwaltung, damit ein Rückfall nichts verliert oder offenlegt. Co-Authored-By: Claude Sonnet 5.5 --- app/Domain/Catalog/ArticleService.php | 4 + app/Domain/Catalog/Composition.php | 5 + app/Domain/Catalog/CompositionKind.php | 8 + app/Domain/Catalog/CompositionRelease.php | 6 + .../Catalog/CompositionStructureReader.php | 5 + app/Domain/Catalog/ContentResolver.php | 8 + app/Domain/Catalog/ContentService.php | 4 + app/Domain/Catalog/ForeignCompositions.php | 93 ++++++ app/Domain/Catalog/OfferService.php | 4 + app/Domain/Catalog/SupportedKindScope.php | 21 ++ .../Compositions/Pages/EditComposition.php | 57 ++++ app/Filament/Support/CatalogOptions.php | 4 +- app/Filament/Support/CatalogReading.php | 16 +- app/Filament/Support/EditorialCatalog.php | 10 + .../views/filament/editorial/editor.blade.php | 1 + tests/Feature/RueckfallschutzTest.php | 272 ++++++++++++++++++ 16 files changed, 513 insertions(+), 5 deletions(-) create mode 100644 app/Domain/Catalog/ForeignCompositions.php create mode 100644 app/Domain/Catalog/SupportedKindScope.php create mode 100644 tests/Feature/RueckfallschutzTest.php diff --git a/app/Domain/Catalog/ArticleService.php b/app/Domain/Catalog/ArticleService.php index 4232704..e43f46c 100644 --- a/app/Domain/Catalog/ArticleService.php +++ b/app/Domain/Catalog/ArticleService.php @@ -141,6 +141,10 @@ private function checkedRows(ContentElementVersion|CompositionVersion $root): ar { $root->refresh(); + if (app(ForeignCompositions::class)->reaches($root)) { + throw new DomainRuleException('Der Aufbau enthält einen Bestandteil, den dieser Programmstand nicht kennt. Er wird hier nicht veröffentlicht, damit nichts fehlt oder zu viel ausgegeben wird.'); + } + if ($root->status !== ContentVersionStatus::Bereit) { throw new DomainRuleException('Ein Artikel-Stand kann nur eine bereitgestellte Fassung festschreiben.'); } diff --git a/app/Domain/Catalog/Composition.php b/app/Domain/Catalog/Composition.php index 0d5068a..4bd54c1 100644 --- a/app/Domain/Catalog/Composition.php +++ b/app/Domain/Catalog/Composition.php @@ -36,6 +36,11 @@ protected function casts(): array ]; } + protected static function booted(): void + { + static::addGlobalScope(new SupportedKindScope); + } + public function editorialContentKind(): BelongsTo { return $this->belongsTo(EditorialContentKind::class); diff --git a/app/Domain/Catalog/CompositionKind.php b/app/Domain/Catalog/CompositionKind.php index b84b275..c96daee 100644 --- a/app/Domain/Catalog/CompositionKind.php +++ b/app/Domain/Catalog/CompositionKind.php @@ -8,6 +8,14 @@ enum CompositionKind: string case Uebung = 'uebung'; case Kurs = 'kurs'; + /** + * @return list + */ + public static function values(): array + { + return array_map(fn (self $case): string => $case->value, self::cases()); + } + public function label(): string { return match ($this) { diff --git a/app/Domain/Catalog/CompositionRelease.php b/app/Domain/Catalog/CompositionRelease.php index d44b2b6..56527dd 100644 --- a/app/Domain/Catalog/CompositionRelease.php +++ b/app/Domain/Catalog/CompositionRelease.php @@ -220,6 +220,12 @@ private function inspectReleasedComposition( ): void { $version = CompositionVersion::query()->with('composition', 'members')->find($id); + if ($version instanceof CompositionVersion && $version->composition === null && app(ForeignCompositions::class)->isForeignVersion($version->id)) { + $blocked[] = $this->block('Bestandteil', 'Dieser Bestandteil stammt aus einer neueren Programmversion und kann hier nicht freigegeben werden.', $depth, null); + + return; + } + if (! $version instanceof CompositionVersion || $version->composition === null) { $blocked[] = $this->block('Modul', 'Ein Bestandteil ist nicht mehr vorhanden.', $depth, null); diff --git a/app/Domain/Catalog/CompositionStructureReader.php b/app/Domain/Catalog/CompositionStructureReader.php index d2ccf94..5705dca 100644 --- a/app/Domain/Catalog/CompositionStructureReader.php +++ b/app/Domain/Catalog/CompositionStructureReader.php @@ -60,6 +60,11 @@ private function members(CompositionVersion $version, array $stack = []): array $nested->loadMissing('composition.editorialContentKind', 'composition'); $composition = $nested->composition; + // Bestandteil einer Art, die dieser Programmstand nicht kennt: nicht anzeigen (Rückfallschutz). + if ($composition === null) { + continue; + } + $nodes[] = new StructureNode( role: $member->role, position: $member->position, diff --git a/app/Domain/Catalog/ContentResolver.php b/app/Domain/Catalog/ContentResolver.php index 4ed1470..0a6e1a2 100644 --- a/app/Domain/Catalog/ContentResolver.php +++ b/app/Domain/Catalog/ContentResolver.php @@ -45,6 +45,14 @@ public function expand(ContentElementVersion|CompositionVersion $node, string $p throw new DomainRuleException('Ein Kompositionsmitglied braucht genau ein Ziel.'); } + // Bestandteil einer Art, die dieser Programmstand nicht kennt: nicht auflösen (Rückfallschutz). + // Veröffentlichen verweigern die aufrufenden Stellen über ForeignCompositions. + $nested->loadMissing('composition'); + + if ($nested->composition === null) { + continue; + } + $rows = array_merge($rows, $this->expand($nested, $segment, $stack)); } diff --git a/app/Domain/Catalog/ContentService.php b/app/Domain/Catalog/ContentService.php index e00e812..66f74e5 100644 --- a/app/Domain/Catalog/ContentService.php +++ b/app/Domain/Catalog/ContentService.php @@ -345,6 +345,10 @@ private function assertAcyclic(int $compositionId, array $members, array $stack private function assertReadyMember(ContentElementVersion|CompositionVersion $target): void { + if (app(ForeignCompositions::class)->reaches($target)) { + throw new DomainRuleException('Dieser Bestandteil stammt aus einer neueren Programmversion und wird hier nicht in eine Fassung aufgenommen.'); + } + if ($target->status !== ContentVersionStatus::Bereit) { throw new DomainRuleException('Eine Komposition darf nur bereitgestellte Fassungen enthalten.'); } diff --git a/app/Domain/Catalog/ForeignCompositions.php b/app/Domain/Catalog/ForeignCompositions.php new file mode 100644 index 0000000..2e882cf --- /dev/null +++ b/app/Domain/Catalog/ForeignCompositions.php @@ -0,0 +1,93 @@ +join('compositions as c', 'c.id', '=', 'v.composition_id') + ->where('v.id', $compositionVersionId) + ->whereNotIn('c.kind', CompositionKind::values()) + ->exists(); + } + + /** + * @param string $target „composition:ID“ (Fassung) oder „composition-draft:ID“ (Komposition) + */ + public function isForeignTarget(string $target): bool + { + if (preg_match('/^composition:(\d+)$/', $target, $match) === 1) { + return $this->isForeignVersion((int) $match[1]); + } + + if (preg_match('/^composition-draft:(\d+)$/', $target, $match) === 1) { + return DB::table('compositions') + ->where('id', (int) $match[1]) + ->whereNotIn('kind', CompositionKind::values()) + ->exists(); + } + + return false; + } + + /** + * Ist die Fassung selbst unbekannt oder erreicht sie, auch verschachtelt, einen unbekannten Bestandteil? + */ + public function reaches(ContentElementVersion|CompositionVersion $node): bool + { + return $node instanceof CompositionVersion && $this->reachesVersion($node->id, []); + } + + /** + * Enthält irgendeine Fassung dieser Komposition einen unbekannten Bestandteil? + */ + public function compositionHasForeignMembers(int $compositionId): bool + { + return DB::table('composition_members as m') + ->join('composition_versions as host', 'host.id', '=', 'm.composition_version_id') + ->join('composition_versions as nested', 'nested.id', '=', 'm.nested_composition_version_id') + ->join('compositions as c', 'c.id', '=', 'nested.composition_id') + ->where('host.composition_id', $compositionId) + ->whereNotIn('c.kind', CompositionKind::values()) + ->exists(); + } + + /** + * @param list $seen + */ + private function reachesVersion(int $versionId, array $seen): bool + { + if (in_array($versionId, $seen, true)) { + return false; + } + + if ($this->isForeignVersion($versionId)) { + return true; + } + + $seen[] = $versionId; + + foreach (DB::table('composition_members') + ->where('composition_version_id', $versionId) + ->whereNotNull('nested_composition_version_id') + ->pluck('nested_composition_version_id') as $nestedId) { + if ($this->reachesVersion((int) $nestedId, $seen)) { + return true; + } + } + + return false; + } +} diff --git a/app/Domain/Catalog/OfferService.php b/app/Domain/Catalog/OfferService.php index 064c091..f2d4680 100644 --- a/app/Domain/Catalog/OfferService.php +++ b/app/Domain/Catalog/OfferService.php @@ -277,6 +277,10 @@ private function assertCoverage(array $lines, array $attributes): void } $version = CompositionVersion::query()->findOrFail($versionId); + + if (app(ForeignCompositions::class)->reaches($version)) { + throw new DomainRuleException('Der Aufbau enthält einen Bestandteil, den dieser Programmstand nicht kennt. Das Angebot wird hier nicht aktiviert.'); + } $articles = []; foreach ($lines as $line) { diff --git a/app/Domain/Catalog/SupportedKindScope.php b/app/Domain/Catalog/SupportedKindScope.php new file mode 100644 index 0000000..93c8893 --- /dev/null +++ b/app/Domain/Catalog/SupportedKindScope.php @@ -0,0 +1,21 @@ +whereIn($model->qualifyColumn('kind'), CompositionKind::values()); + } +} diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index 31d4f0c..cf943d1 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -15,6 +15,7 @@ use App\Domain\Catalog\DomainRuleException; use App\Domain\Catalog\EditorialVocabulary; use App\Domain\Catalog\EditorialWorkingDraft; +use App\Domain\Catalog\ForeignCompositions; use App\Domain\Catalog\IdentityDimension; use App\Domain\Catalog\IdentityDimensionValue; use App\Domain\Catalog\IdentityProfile; @@ -489,8 +490,39 @@ public function cancelText(): void $this->newTextBody = ''; } + /** + * Rückfallschutz: Enthält dieser Aufbau (in einer Fassung oder im Entwurf) einen Bestandteil, den dieser Programmstand + * nicht kennt, bleibt er schreibgeschützt. Der Editor könnte den Bestandteil sonst nicht laden und würde ihn beim + * Speichern oder Freigeben still weglassen. + */ + public function schreibschutz(): ?string + { + $foreign = app(ForeignCompositions::class); + $reason = 'Dieser Aufbau enthält einen Bestandteil aus einer neueren Programmversion. Er kann hier nur angesehen werden, damit nichts verloren geht.'; + + if ($foreign->compositionHasForeignMembers((int) $this->getRecord()->getKey())) { + return $reason; + } + + $draft = app(EditorialWorkingDraft::class)->read($this->getRecord()); + + foreach (is_array($draft['members'] ?? null) ? $draft['members'] : [] as $member) { + if (is_array($member) && $foreign->isForeignTarget((string) ($member['target'] ?? ''))) { + return $reason; + } + } + + return null; + } + public function saveDraft(): void { + if (($reason = $this->schreibschutz()) !== null) { + $this->feedback = $reason; + + return; + } + $this->commitRoleDraft(); $minutes = $this->minutes($this->durationMinutes); @@ -508,6 +540,13 @@ public function saveDraft(): void public function armRelease(): void { + if (($reason = $this->schreibschutz()) !== null) { + $this->releaseArmed = false; + $this->feedback = $reason; + + return; + } + $this->commitRoleDraft(); if ($this->members === []) { @@ -585,6 +624,12 @@ protected function selectFirstPart(): void public function discardDraft(): void { + if (($reason = $this->schreibschutz()) !== null) { + $this->feedback = $reason; + + return; + } + /** @var Composition $record */ $record = $this->getRecord(); app(EditorialWorkingDraft::class)->clear($record); @@ -1521,6 +1566,12 @@ public function presentationChips(): array public function publishRevision(): bool { + if (($reason = $this->schreibschutz()) !== null) { + $this->feedback = $reason; + + return false; + } + $this->commitRoleDraft(); if ($this->members === []) { @@ -1929,6 +1980,12 @@ protected function persistRedaktion(): bool protected function persistDraft(): bool { + if (($reason = $this->schreibschutz()) !== null) { + $this->feedback = $reason; + + return false; + } + if ($this->minutes($this->durationMinutes) === false) { $this->feedback = 'Der Zeitbedarf ist eine Zahl von Minuten oder bleibt leer.'; diff --git a/app/Filament/Support/CatalogOptions.php b/app/Filament/Support/CatalogOptions.php index 6c0a9f8..b863f47 100644 --- a/app/Filament/Support/CatalogOptions.php +++ b/app/Filament/Support/CatalogOptions.php @@ -37,7 +37,7 @@ public static function assignmentTargets(?int $exceptCompositionId = null): arra $media['element:'.$version->id] = self::elementLabel($version); } - foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->with('composition.editorialContentKind')->orderBy('id')->get() as $version) { + foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->whereHas('composition')->with('composition.editorialContentKind')->orderBy('id')->get() as $version) { if ($exceptCompositionId !== null && (int) $version->composition_id === $exceptCompositionId) { continue; } @@ -94,7 +94,7 @@ public static function readyTargets(): array $options['element:'.$version->id] = self::elementLabel($version); } - foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->with('composition.editorialContentKind')->orderBy('id')->get() as $version) { + foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->whereHas('composition')->with('composition.editorialContentKind')->orderBy('id')->get() as $version) { $options['composition:'.$version->id] = self::compositionLabel($version); } diff --git a/app/Filament/Support/CatalogReading.php b/app/Filament/Support/CatalogReading.php index d9ca6f1..b6084ed 100644 --- a/app/Filament/Support/CatalogReading.php +++ b/app/Filament/Support/CatalogReading.php @@ -266,7 +266,7 @@ public function elementUsage(ContentElement $element): array ->get(); foreach ($members as $member) { - $lines[] = self::compositionLabel($member->compositionVersion->composition) + $lines[] = self::compositionLabelOf($member->compositionVersion->composition) .' · Fassung '.$member->compositionVersion->number .' · Rolle '.$member->role; } @@ -313,7 +313,7 @@ public function compositionMembers(Composition $composition): array } $nested = $member->nestedCompositionVersion; - $lines[] = $member->role.' — '.($nested === null ? 'fehlt' : self::compositionLabel($nested->composition)); + $lines[] = $member->role.' — '.($nested === null ? 'fehlt' : self::compositionLabelOf($nested->composition)); } return $lines; @@ -365,7 +365,7 @@ public function compositionUsage(Composition $composition): array ->get(); foreach ($parents as $member) { - $lines[] = self::compositionLabel($member->compositionVersion->composition) + $lines[] = self::compositionLabelOf($member->compositionVersion->composition) .' · Fassung '.$member->compositionVersion->number .' · Rolle '.$member->role; } @@ -448,6 +448,16 @@ private function purpose(string $purpose): string }; } + /** + * Eine Zusammenstellung, die dieser Programmstand nicht kennt, erscheint nur als Hinweis ohne Namen und Inhalt. + */ + private static function compositionLabelOf(?Composition $composition): string + { + return $composition === null + ? 'Zusammenstellung einer neueren Programmversion' + : self::compositionLabel($composition); + } + private static function compositionLabel(Composition $composition): string { $kind = $composition->kind; diff --git a/app/Filament/Support/EditorialCatalog.php b/app/Filament/Support/EditorialCatalog.php index 36ef686..bfa401c 100644 --- a/app/Filament/Support/EditorialCatalog.php +++ b/app/Filament/Support/EditorialCatalog.php @@ -140,6 +140,12 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all } $composition = $version->composition; + + // Art, die dieser Programmstand nicht kennt: nicht anbieten und nicht laden (Rückfallschutz). + if ($composition === null) { + return null; + } + $kind = $composition->editorialContentKind?->label ?: ($composition->kind instanceof CompositionKind ? $composition->kind->deskLabel() : 'Zusammenstellung'); @@ -1028,6 +1034,10 @@ private function suggestPicture(array $members, array $seen = []): ?array $nested = $version->composition; + if ($nested === null) { + continue; + } + if ($this->cardUrl('komposition', $nested->id, $nested->thumbnail_path) !== null) { return [ 'kind' => 'komposition', diff --git a/resources/views/filament/editorial/editor.blade.php b/resources/views/filament/editorial/editor.blade.php index 9fa8d99..6d80dbc 100644 --- a/resources/views/filament/editorial/editor.blade.php +++ b/resources/views/filament/editorial/editor.blade.php @@ -34,6 +34,7 @@ 'titel' => $titel, 'typ' => $this->hostLabel().' · '.$typ, 'status' => [ + ($schutz = $this->schreibschutz()) !== null ? ['text' => $schutz, 'ton' => 'offen'] : null, ['text' => $aufbauOffen ? 'Änderungen am Aufbau nicht gespeichert' : $statusSatz, 'ton' => $aufbauOffen ? 'offen' : ($bereit !== null ? 'gut' : 'neutral')], $redaktionOffen ? ['text' => 'Die Redaktion hat ungespeicherte Änderungen.', 'ton' => 'offen', 'aktion' => ['label' => 'Zur Redaktion', 'wire' => "openRedaktion('".$this->redaktionTab."')"]] : null, ], diff --git a/tests/Feature/RueckfallschutzTest.php b/tests/Feature/RueckfallschutzTest.php new file mode 100644 index 0000000..0905284 --- /dev/null +++ b/tests/Feature/RueckfallschutzTest.php @@ -0,0 +1,272 @@ +buildProduct(); + } + + public function test_the_kind_values_are_the_ones_this_program_state_knows(): void + { + $this->assertSame(['kombination', 'uebung', 'kurs'], CompositionKind::values()); + } + + public function test_a_composition_of_an_unknown_kind_does_not_crash_loading_and_stays_hidden(): void + { + $this->assertSame( + ['Modul mit Übung'], + Composition::query()->orderBy('designation')->pluck('designation')->all(), + ); + $this->assertNull(CompositionVersion::query()->with('composition')->findOrFail($this->exercise->id)->composition); + $this->assertNull(Composition::query()->find($this->exercise->composition_id)); + $this->assertSame(1, DB::table('compositions')->where('kind', self::FOREIGN)->count(), 'Die Zeile bleibt unverändert erhalten.'); + } + + public function test_the_member_area_neither_crashes_nor_shows_what_it_cannot_present(): void + { + $this->actingAs($this->member) + ->get(route('member.library')) + ->assertOk() + ->assertSee('Modul mit Übung'); + + $this->actingAs($this->member) + ->get(route('member.program', $this->module->composition_id)) + ->assertOk() + ->assertSee('Modul mit Übung') + ->assertDontSee('Übung neuerer Stand') + ->assertDontSee('Einstiegsfilm') + ->assertDontSee('Alternativfilm') + ->assertDontSee('Durchführungstext'); + + $this->actingAs($this->member) + ->get(route('member.program', $this->exercise->composition_id)) + ->assertNotFound(); + } + + public function test_only_the_selected_variant_is_delivered_from_the_frozen_stand(): void + { + $this->actingAs($this->member) + ->get(route('member.article', $this->article)) + ->assertOk() + ->assertSee('Einstiegsfilm') + ->assertDontSee('Alternativfilm'); + + $link = fn (ContentElementVersion $version): string => SignedLink::temporary('member.media', now()->addMinutes(10), [ + 'article' => $this->article->id, + 'release' => $this->release->id, + 'version' => $version->id, + 'action' => 'ansehen', + 'reader' => $this->member->id, + ]); + + $this->actingAs($this->member)->get($link($this->filmB))->assertForbidden(); + } + + public function test_the_previous_state_refuses_to_publish_what_it_cannot_resolve(): void + { + try { + app(ArticleService::class)->publishRelease($this->article->fresh(), $this->module, 'Neuer Stand im alten Programmstand.'); + $this->fail('Ein Stand mit unbekanntem Bestandteil darf hier nicht entstehen.'); + } catch (DomainRuleException $exception) { + $this->assertStringContainsString('Programmstand', $exception->getMessage()); + } + + $this->assertSame(1, $this->article->releases()->count()); + + $other = app(ContentService::class)->createComposition('Anderes Modul', CompositionKind::Uebung); + + $this->expectException(DomainRuleException::class); + app(ContentService::class)->publishComposition($other, [['role' => 'Übung', 'target' => $this->exercise]]); + } + + public function test_an_offer_is_not_activated_for_a_structure_with_an_unknown_part(): void + { + $offers = app(OfferService::class); + $rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']]); + $offer = $offers->create('Angebot mit Übung'); + + $this->expectException(DomainRuleException::class); + $this->expectExceptionMessage('Programmstand'); + $offers->activate($offer, [['target' => $this->article->fresh(), 'rights' => $rights]], [ + 'grant_kind' => 'auf_abruf', + 'composition_version_id' => $this->module->id, + ]); + } + + public function test_the_editor_of_a_structure_with_an_unknown_part_is_read_only_and_loses_nothing(): void + { + $module = Composition::query()->findOrFail($this->module->composition_id); + $versions = $module->versions()->count(); + $members = DB::table('composition_members')->where('composition_version_id', $this->module->id)->count(); + + $component = Livewire::actingAs($this->editor(), 'staff') + ->test(EditExercise::class, ['record' => $module->getKey()]) + ->assertOk() + ->assertSee('neueren Programmversion'); + + $this->assertNotNull($component->instance()->schreibschutz()); + + $component->call('saveDraft'); + $this->assertNull($module->fresh()->working_draft, 'Es wird kein Entwurf geschrieben, der den Bestandteil auslässt.'); + + $component->call('armRelease')->assertSet('releaseArmed', false); + $this->assertFalse($component->instance()->publishRevision()); + $component->call('discardDraft'); + + $this->assertSame($versions, $module->versions()->count()); + $this->assertSame($members, DB::table('composition_members')->where('composition_version_id', $this->module->id)->count()); + } + + public function test_an_editor_with_only_known_parts_still_saves(): void + { + $content = app(ContentService::class); + $film = $content->publishElementVersion($content->createElement('film', 'film', 'Kurzfilm'), null, ['file' => 'inhalte/kurz.mp4']); + $plain = $content->createComposition('Normales Modul', CompositionKind::Uebung); + $content->publishComposition($plain, [['role' => 'Film', 'target' => $film]]); + + $component = Livewire::actingAs($this->editor(), 'staff') + ->test(EditExercise::class, ['record' => $plain->getKey()]) + ->assertOk(); + + $this->assertNull($component->instance()->schreibschutz()); + $component->call('saveDraft'); + $this->assertNotNull($plain->fresh()->working_draft); + } + + public function test_the_staff_pages_around_the_structure_render_without_naming_the_unknown_part(): void + { + Livewire::actingAs($this->editor(), 'staff') + ->test(ViewContentElement::class, ['record' => $this->filmA->content_element_id]) + ->assertOk() + ->assertDontSee('Übung neuerer Stand'); + + $keeper = User::factory()->katalogverwalter()->create(); + $keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + Livewire::actingAs($keeper, 'staff') + ->test(ViewLicenseArticle::class, ['record' => $this->article->getKey()]) + ->assertOk() + ->assertDontSee('Übung neuerer Stand'); + } + + public function test_the_public_site_does_not_know_the_unknown_composition(): void + { + $this->get(route('public.program', $this->exercise->composition_id))->assertNotFound(); + $this->get(route('public.programs'))->assertOk()->assertDontSee('Übung neuerer Stand'); + } + + /** + * Ein Modul mit einer verschachtelten Übung, deren Fassung zwei Filmvarianten und einen Text enthält. Veröffentlicht + * wird nur die Variante A samt Text. Danach bekommt die Übung den Wert, den erst der neue Stand schreibt. + */ + private function buildProduct(): void + { + $content = app(ContentService::class); + $this->filmA = $content->publishElementVersion($content->createElement('film', 'film', 'Einstiegsfilm'), null, ['file' => 'inhalte/a.mp4']); + $this->filmB = $content->publishElementVersion($content->createElement('film', 'film', 'Alternativfilm'), null, ['file' => 'inhalte/b.mp4']); + $this->text = $content->publishElementVersion($content->createElement('text', 'text', 'Durchführungstext'), 'Erst aufwärmen, dann üben.'); + + $this->exercise = $content->publishComposition( + $content->createComposition('Übung neuerer Stand', CompositionKind::Kombination), + [ + ['role' => 'Einstieg Variante A', 'target' => $this->filmA], + ['role' => 'Einstieg Variante B', 'target' => $this->filmB], + ['role' => 'Durchführung', 'target' => $this->text], + ], + null, + null, + ['learning_goal' => 'Nein sagen üben'], + ); + + $kind = EditorialContentKind::query()->where('slug', 'modul')->firstOrFail(); + $module = $content->createComposition('Modul mit Übung', CompositionKind::Uebung); + $module->editorial_content_kind_id = $kind->id; + $module->save(); + $this->module = $content->publishComposition($module, [['role' => 'Übung', 'target' => $this->exercise]]); + + $articles = app(ArticleService::class); + $this->article = $articles->create('modul-mit-uebung'); + $this->release = $articles->publishRelease($this->article, $this->module, 'Modul mit Übung.'); + + // Gewählt ist nur Variante A: Der Stand schreibt Film B nicht fest. + DB::table('release_contents') + ->where('article_release_id', $this->release->id) + ->where('content_element_version_id', $this->filmB->id) + ->delete(); + + $offers = app(OfferService::class); + $rights = $offers->createRightsProfile('Film und Text', 'ehrenamtlich', ['film' => ['streamen', 'laden'], 'text' => ['ansehen']]); + $offer = $offers->create('Zugang'); + $offers->activate($offer, [['target' => $this->article->fresh(), 'rights' => $rights]], ['grant_kind' => 'auf_abruf']); + + $this->member = User::factory()->create(); + app(GrantIssuer::class)->claim($this->member, $offer); + app(CompositionDisplayRelease::class)->release($this->module, $this->member); + + DB::table('compositions')->where('id', $this->exercise->composition_id)->update(['kind' => self::FOREIGN]); + } + + private function editor(): User + { + $editor = User::factory()->redakteur()->create(); + $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + return $editor; + } +}