Zeige vor der Freigabe die enthaltene Struktur und gib Entwürfe nur mit Zustimmung frei.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1168c04228
commit
d12ba67b45
9 files changed
+934
-88
No files matched your search
@@ -5,6 +5,7 @@
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionRelease;
|
||||
use App\Domain\Catalog\CompositionStructureReader;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
@@ -19,6 +20,7 @@
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Filament\Support\MediumForm;
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
@@ -93,6 +95,10 @@ abstract class EditComposition extends EditRecord
|
||||
|
||||
public bool $releaseArmed = false;
|
||||
|
||||
public bool $releaseConsent = false;
|
||||
|
||||
public bool $returnAfterRelease = false;
|
||||
|
||||
public string $returnUrl = '';
|
||||
|
||||
public ?int $templateNumber = null;
|
||||
@@ -448,12 +454,51 @@ public function armRelease(): void
|
||||
return;
|
||||
}
|
||||
|
||||
$this->releaseConsent = false;
|
||||
$this->releaseArmed = true;
|
||||
}
|
||||
|
||||
public function cancelRelease(): void
|
||||
{
|
||||
$this->releaseArmed = false;
|
||||
$this->releaseConsent = false;
|
||||
$this->returnAfterRelease = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function releaseReview(): array
|
||||
{
|
||||
/** @var Composition $composition */
|
||||
$composition = $this->getRecord();
|
||||
$review = app(CompositionRelease::class)->review($composition, $this->members);
|
||||
|
||||
foreach ($review['blocked'] as $index => $item) {
|
||||
$review['blocked'][$index]['edit_url'] = $this->releaseEditUrl($item['edit'] ?? null);
|
||||
}
|
||||
|
||||
return $review;
|
||||
}
|
||||
|
||||
public function releaseFollowUp(): string
|
||||
{
|
||||
$version = $this->currentReadyVersion();
|
||||
|
||||
if ($version === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/** @var Composition $composition */
|
||||
$composition = $this->getRecord();
|
||||
$library = app(CompositionDisplayRelease::class)->isReleased($version)
|
||||
? 'In der Mitgliederbibliothek ist Fassung '.$version->number.' sichtbar.'
|
||||
: 'In der Mitgliederbibliothek ist noch keine Fassung sichtbar. „In Mitgliederbibliothek anzeigen“ wählt die letzte freigegebene Fassung. Das veröffentlicht weder die Website noch ein Angebot.';
|
||||
$draft = is_array($composition->working_draft) && $composition->working_draft !== []
|
||||
? ' Es gibt einen gespeicherten Entwurf neben der freigegebenen Fassung.'
|
||||
: ' Es gibt keinen offenen Entwurf. Änderungen hältst du mit „Entwurf speichern“ fest.';
|
||||
|
||||
return $library.$draft;
|
||||
}
|
||||
|
||||
public function discardDraft(): void
|
||||
@@ -621,6 +666,23 @@ public function selectedAlternatives(): array
|
||||
|
||||
public function childrenOf(string $target): string
|
||||
{
|
||||
if (preg_match('/^composition-draft:(\d+)$/', $target, $match) === 1) {
|
||||
$composition = Composition::query()->find($match[1]);
|
||||
$draft = $composition instanceof Composition && is_array($composition->working_draft) ? $composition->working_draft : [];
|
||||
$lines = [];
|
||||
|
||||
foreach ($draft['members'] ?? [] as $member) {
|
||||
if (! is_array($member)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = app(EditorialCatalog::class)->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true, allowDraft: true);
|
||||
$lines[] = trim((string) ($member['role'] ?? '')).': '.($row['title'] ?? 'Bestandteil');
|
||||
}
|
||||
|
||||
return implode(' · ', $lines);
|
||||
}
|
||||
|
||||
if (preg_match('/^composition:(\d+)$/', $target, $match) !== 1) {
|
||||
return '';
|
||||
}
|
||||
@@ -681,7 +743,7 @@ public function addPart(string $target): void
|
||||
|
||||
private function includePart(string $target, bool $allowDraft): bool
|
||||
{
|
||||
if (preg_match('/^(element|composition):\d+$/', $target) !== 1) {
|
||||
if (preg_match('/^(element:\d+|composition:\d+|composition-draft:\d+)$/', $target) !== 1) {
|
||||
$this->feedback = 'Dieser Bestandteil ist nicht verfügbar.';
|
||||
|
||||
return false;
|
||||
@@ -1307,42 +1369,25 @@ private function writePartText(): string|false
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array{role: string, target: ContentElementVersion|CompositionVersion, note: string}> $payload
|
||||
* @param array{type: string, id: int}|null $edit
|
||||
*/
|
||||
private function promoteDraftElements(array $payload): bool
|
||||
private function releaseEditUrl(?array $edit): ?string
|
||||
{
|
||||
foreach ($payload as $member) {
|
||||
$target = $member['target'];
|
||||
|
||||
if (! $target instanceof ContentElementVersion || $target->status !== ContentVersionStatus::Entwurf) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$meta = is_array($target->metadata) ? $target->metadata : [];
|
||||
|
||||
if (isset($meta['incoming']) && ! isset($meta['file'])) {
|
||||
$this->feedback = 'Eine Datei wird noch übernommen. Gib den Aufbau frei, sobald die Datei bereitsteht.';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($meta['error'])) {
|
||||
$this->feedback = (string) $meta['error'];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
unset($meta['held']);
|
||||
$target->metadata = $meta === [] ? null : $meta;
|
||||
$target->content_hash = hash('sha256', json_encode([
|
||||
'body' => $target->body,
|
||||
'metadata' => $meta,
|
||||
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
$target->status = ContentVersionStatus::Bereit;
|
||||
$target->save();
|
||||
if ($edit === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return true;
|
||||
if ($edit['type'] === 'element') {
|
||||
$element = ContentElement::query()->find($edit['id']);
|
||||
|
||||
return $element instanceof ContentElement
|
||||
? ContentElementResource::getUrl('view', ['record' => $element])
|
||||
: null;
|
||||
}
|
||||
|
||||
$composition = Composition::query()->find($edit['id']);
|
||||
|
||||
return $composition instanceof Composition ? EditorialCatalog::editUrl($composition) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1428,47 +1473,14 @@ public function publishRevision(): bool
|
||||
return false;
|
||||
}
|
||||
|
||||
$payload = [];
|
||||
|
||||
foreach (array_values($this->members) as $member) {
|
||||
$role = trim((string) ($member['role'] ?? ''));
|
||||
$target = (string) ($member['target'] ?? '');
|
||||
|
||||
if ($role === '' || preg_match('/^(element|composition):(\d+)$/', $target, $match) !== 1) {
|
||||
$this->feedback = 'Jeder Bestandteil braucht eine Rolle und eine vorhandene Fassung.';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$model = $match[1] === 'composition'
|
||||
? CompositionVersion::query()->find($match[2])
|
||||
: ContentElementVersion::query()->find($match[2]);
|
||||
|
||||
if ($model === null) {
|
||||
$this->feedback = 'Ein Bestandteil ist nicht mehr vorhanden.';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$payload[] = [
|
||||
'role' => $role,
|
||||
'target' => $model,
|
||||
'note' => trim((string) ($member['note'] ?? '')),
|
||||
];
|
||||
}
|
||||
|
||||
if (! $this->promoteDraftElements($payload)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var Composition $record */
|
||||
$record = $this->getRecord();
|
||||
$note = trim($this->revisionNote);
|
||||
|
||||
try {
|
||||
app(ContentService::class)->publishComposition(
|
||||
app(CompositionRelease::class)->publish(
|
||||
$record,
|
||||
$payload,
|
||||
$this->members,
|
||||
$this->actor(),
|
||||
$note !== '' ? $note : null,
|
||||
[
|
||||
@@ -1476,9 +1488,11 @@ public function publishRevision(): bool
|
||||
'duration_minutes' => $minutes,
|
||||
'material_note' => $this->blank($this->materialNote),
|
||||
],
|
||||
$this->releaseConsent,
|
||||
);
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->feedback = $exception->getMessage();
|
||||
$this->releaseArmed = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1486,9 +1500,17 @@ public function publishRevision(): bool
|
||||
$this->revisionNote = '';
|
||||
$this->templateNumber = null;
|
||||
$this->releaseArmed = false;
|
||||
$this->releaseConsent = false;
|
||||
app(EditorialWorkingDraft::class)->clear($record);
|
||||
$this->loadEditor();
|
||||
$this->feedback = 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.';
|
||||
$released = $this->currentReadyVersion();
|
||||
$number = $released instanceof CompositionVersion ? $released->number : '';
|
||||
$this->feedback = 'Fassung '.$number.' ist freigegeben. Der Entwurf ist geschlossen und die bisherige Fassung bleibt erhalten. Die Mitgliederbibliothek ändert sich dadurch nicht.';
|
||||
|
||||
if ($this->returnAfterRelease) {
|
||||
$this->returnAfterRelease = false;
|
||||
$this->finishReturn();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1500,11 +1522,17 @@ public function returnAndInclude(): void
|
||||
}
|
||||
|
||||
if ($this->needsRevision()) {
|
||||
if (! $this->publishRevision()) {
|
||||
return;
|
||||
}
|
||||
$this->returnAfterRelease = true;
|
||||
$this->armRelease();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->finishReturn();
|
||||
}
|
||||
|
||||
private function finishReturn(): void
|
||||
{
|
||||
$version = $this->currentReadyVersion();
|
||||
$url = $this->returnUrl;
|
||||
|
||||
|
||||
@@ -276,6 +276,23 @@ protected function getHeaderActions(): array
|
||||
}, 'Die Beschreibung ist gespeichert.');
|
||||
$this->getRecord()->refresh();
|
||||
}),
|
||||
Action::make('releaseVersion')
|
||||
->label('Fassung freigeben')
|
||||
->modalHeading('Fassung freigeben')
|
||||
->modalDescription('Diese Fassung wird freigegeben. Sie erscheint dadurch nicht in der Mitgliederbibliothek, nicht auf der Website und nicht in einem Angebot. Eine deaktivierte Fassung bleibt unverändert.')
|
||||
->modalSubmitActionLabel('Freigeben')
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
->action(function (array $arguments): void {
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
$this->report(function () use ($arguments): string {
|
||||
$version = $this->ownedVersion((int) ($arguments['version'] ?? 0));
|
||||
abort_unless($version instanceof ContentElementVersion, 404);
|
||||
$released = app(ContentService::class)->releaseElementVersion($version);
|
||||
|
||||
return 'Fassung '.$released->number.' ist freigegeben.';
|
||||
}, 'Die Fassung ist freigegeben.');
|
||||
$this->getRecord()->unsetRelation('versions');
|
||||
}),
|
||||
Action::make('revise')
|
||||
->label('Neue Fassung anlegen')
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
|
||||
@@ -59,6 +59,10 @@ public function rows(CompositionVersion $version, int $exceptCompositionId): arr
|
||||
*/
|
||||
public function rowForTarget(string $target, int $exceptCompositionId, bool $allowSelf = false, bool $allowDraft = false): ?array
|
||||
{
|
||||
if (preg_match('/^composition-draft:(\d+)$/', $target, $draftMatch) === 1) {
|
||||
return $this->draftCompositionRow((int) $draftMatch[1], $exceptCompositionId, $allowSelf);
|
||||
}
|
||||
|
||||
if (preg_match('/^(element|composition):(\d+)$/', $target, $match) !== 1) {
|
||||
return null;
|
||||
}
|
||||
@@ -134,6 +138,39 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string|null>|null
|
||||
*/
|
||||
private function draftCompositionRow(int $compositionId, int $exceptCompositionId, bool $allowSelf): ?array
|
||||
{
|
||||
if (! $allowSelf && $compositionId === $exceptCompositionId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$composition = Composition::query()->with('editorialContentKind')->find($compositionId);
|
||||
|
||||
if (! $composition instanceof Composition) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$kind = $composition->editorialContentKind?->label
|
||||
?: ($composition->kind instanceof CompositionKind ? $composition->kind->deskLabel() : 'Zusammenstellung');
|
||||
|
||||
return [
|
||||
'target' => 'composition-draft:'.$composition->id,
|
||||
'title' => $this->compositionTitle($composition),
|
||||
'kind' => $kind,
|
||||
'summary' => (string) ($composition->summary ?? ''),
|
||||
'tone' => $this->tone('', $kind),
|
||||
'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path),
|
||||
'version_label' => 'Entwurf',
|
||||
'identity' => 'zusammenstellung:'.$composition->id,
|
||||
'open_url' => route('editorial.draft-preview', ['composition' => $composition]),
|
||||
'open_label' => 'Entwurf ansehen',
|
||||
'edit_url' => self::editUrl($composition),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, string|null>>
|
||||
*/
|
||||
@@ -280,6 +317,43 @@ public function browse(string $query, string $kind, string $dimension, int $exce
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$unreleased = Composition::query()
|
||||
->where('id', '!=', $exceptCompositionId)
|
||||
->whereNotNull('working_draft')
|
||||
->whereDoesntHave('versions', function ($builder): void {
|
||||
$builder->where('status', ContentVersionStatus::Bereit);
|
||||
})
|
||||
->when($kind === 'modul', function ($builder): void {
|
||||
$builder->where('kind', CompositionKind::Uebung);
|
||||
})
|
||||
->orderByDesc('id')
|
||||
->get();
|
||||
|
||||
foreach ($unreleased as $composition) {
|
||||
$draft = is_array($composition->working_draft) ? $composition->working_draft : [];
|
||||
$draftMembers = is_array($draft['members'] ?? null) ? $draft['members'] : [];
|
||||
|
||||
if ($draftMembers === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($dimensionId > 0 && ! in_array($composition->id, $this->dimensionSubjectIds(Composition::class, $dimensionId), true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$title = $this->compositionTitle($composition);
|
||||
|
||||
if ($query !== '' && ! str_contains(mb_strtolower($title.' '.(string) ($composition->summary ?? '')), mb_strtolower($query))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = $this->rowForTarget('composition-draft:'.$composition->id, $exceptCompositionId);
|
||||
|
||||
if ($row !== null) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
Reference in new issue
Block a user