diff --git a/app/Filament/Resources/Bundles/BundleResource.php b/app/Filament/Resources/Bundles/BundleResource.php index 58bfba2..977ef02 100644 --- a/app/Filament/Resources/Bundles/BundleResource.php +++ b/app/Filament/Resources/Bundles/BundleResource.php @@ -4,11 +4,17 @@ use App\Domain\Catalog\Bundle; use App\Filament\Resources\Bundles\Pages\ListBundles; +use App\Filament\Resources\Bundles\Pages\ViewBundle; use App\Filament\Resources\LicenseArticles\LicenseArticleResource; +use App\Filament\Support\CatalogReading; +use Filament\Infolists\Components\TextEntry; use Filament\Resources\Resource; +use Filament\Schemas\Components\Section; use Filament\Schemas\Schema; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; +use Illuminate\Auth\Access\Response; +use Illuminate\Database\Eloquent\Model; class BundleResource extends Resource { @@ -24,11 +30,32 @@ class BundleResource extends Resource protected static ?string $recordTitleAttribute = 'name'; + protected static ?int $navigationSort = 2; + public static function canViewAny(): bool { return LicenseArticleResource::keeper(); } + public static function getViewAuthorizationResponse(Model $record): Response + { + return LicenseArticleResource::keeper() ? Response::allow() : Response::deny(); + } + + public static function infolist(Schema $schema): Schema + { + return $schema->components([ + Section::make('Bestandteile')->description('Was diese Fassung direkt enthält.')->schema([ + TextEntry::make('parts')->hiddenLabel()->listWithLineBreaks() + ->state(fn (Bundle $record): array => app(CatalogReading::class)->bundleParts($record)), + ]), + Section::make('Aufgelöste Lizenzartikel')->description('Darauf werden beim Erwerb die Berechtigungen vergeben.')->schema([ + TextEntry::make('articles')->hiddenLabel()->listWithLineBreaks() + ->state(fn (Bundle $record): array => app(CatalogReading::class)->bundleArticles($record)), + ]), + ]); + } + public static function form(Schema $schema): Schema { return $schema; @@ -39,13 +66,14 @@ public static function table(Table $table): Table return $table->columns([ TextColumn::make('name')->label('Name')->searchable(), TextColumn::make('versions_count')->counts('versions')->label('Fassungen'), - ])->recordUrl(null); + ]); } public static function getPages(): array { return [ 'index' => ListBundles::route('/'), + 'view' => ViewBundle::route('/{record}'), ]; } } diff --git a/app/Filament/Resources/Bundles/Pages/ListBundles.php b/app/Filament/Resources/Bundles/Pages/ListBundles.php index 573d480..513b39d 100644 --- a/app/Filament/Resources/Bundles/Pages/ListBundles.php +++ b/app/Filament/Resources/Bundles/Pages/ListBundles.php @@ -2,17 +2,13 @@ namespace App\Filament\Resources\Bundles\Pages; -use App\Domain\Catalog\Bundle; use App\Domain\Catalog\BundleService; -use App\Domain\Catalog\LicenseArticle; use App\Filament\Resources\Bundles\BundleResource; -use App\Filament\Support\CatalogOptions; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; -use Filament\Forms\Components\CheckboxList; -use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Resources\Pages\ListRecords; +use Illuminate\Contracts\Support\Htmlable; class ListBundles extends ListRecords { @@ -20,6 +16,11 @@ class ListBundles extends ListRecords protected static string $resource = BundleResource::class; + public function getSubheading(): string|Htmlable|null + { + return 'Ein Paket stellt Lizenzartikel und andere Pakete zusammen. Öffne es, um Bestandteile und die aufgelösten Artikel zu sehen.'; + } + protected function getHeaderActions(): array { return [ @@ -30,29 +31,6 @@ protected function getHeaderActions(): array app(BundleService::class)->create($data['name']); }, 'Das Paket ist angelegt.'); }), - Action::make('publish')->label('Fassung veröffentlichen')->schema([ - Select::make('bundle_id')->label('Paket')->options(fn (): array => CatalogOptions::bundles())->required(), - CheckboxList::make('articles')->label('Lizenzartikel')->options(fn (): array => CatalogOptions::articles()), - CheckboxList::make('bundles')->label('Enthaltene Pakete')->options(fn (): array => CatalogOptions::bundles()), - ])->action(function (array $data): void { - $this->report(function () use ($data): void { - $items = []; - - foreach ($data['articles'] ?? [] as $id) { - $items[] = LicenseArticle::query()->findOrFail($id); - } - - foreach ($data['bundles'] ?? [] as $id) { - if ((int) $id === (int) $data['bundle_id']) { - continue; - } - - $items[] = Bundle::query()->findOrFail($id); - } - - app(BundleService::class)->publish(Bundle::query()->findOrFail($data['bundle_id']), $items); - }, 'Die Paketfassung ist veröffentlicht.'); - }), ]; } } diff --git a/app/Filament/Resources/Bundles/Pages/ViewBundle.php b/app/Filament/Resources/Bundles/Pages/ViewBundle.php new file mode 100644 index 0000000..f42fcee --- /dev/null +++ b/app/Filament/Resources/Bundles/Pages/ViewBundle.php @@ -0,0 +1,57 @@ +label('Fassung veröffentlichen') + ->schema([ + CheckboxList::make('articles')->label('Lizenzartikel')->options(fn (): array => CatalogOptions::articles()), + CheckboxList::make('bundles')->label('Enthaltene Pakete') + ->options(function (): array { + $options = CatalogOptions::bundles(); + unset($options[$this->getRecord()->getKey()]); + + return $options; + }), + ]) + ->action(function (array $data): void { + $this->report(function () use ($data): void { + /** @var Bundle $bundle */ + $bundle = $this->getRecord(); + $items = []; + + foreach ($data['articles'] ?? [] as $id) { + $items[] = LicenseArticle::query()->findOrFail($id); + } + + foreach ($data['bundles'] ?? [] as $id) { + $items[] = Bundle::query()->findOrFail($id); + } + + app(BundleService::class)->publish($bundle, $items); + }, 'Die Paketfassung ist veröffentlicht.'); + $this->getRecord()->unsetRelations(); + $this->getRecord()->refresh(); + }), + ]; + } +} diff --git a/app/Filament/Resources/Compositions/CompositionResource.php b/app/Filament/Resources/Compositions/CompositionResource.php index 71fc92b..910c3ed 100644 --- a/app/Filament/Resources/Compositions/CompositionResource.php +++ b/app/Filament/Resources/Compositions/CompositionResource.php @@ -4,17 +4,23 @@ use App\Domain\Catalog\Composition; use App\Filament\Resources\Compositions\Pages\ListCompositions; +use App\Filament\Resources\Compositions\Pages\ViewComposition; use App\Filament\Resources\ContentElements\ContentElementResource; +use App\Filament\Support\CatalogReading; +use Filament\Infolists\Components\TextEntry; use Filament\Resources\Resource; +use Filament\Schemas\Components\Section; use Filament\Schemas\Schema; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; +use Illuminate\Auth\Access\Response; +use Illuminate\Database\Eloquent\Model; class CompositionResource extends Resource { protected static ?string $model = Composition::class; - protected static string|\UnitEnum|null $navigationGroup = 'Redaktion'; + protected static string|\UnitEnum|null $navigationGroup = 'Inhalte'; protected static ?string $navigationLabel = 'Kompositionen'; @@ -24,11 +30,32 @@ class CompositionResource extends Resource protected static ?string $recordTitleAttribute = 'designation'; + protected static ?int $navigationSort = 2; + public static function canViewAny(): bool { return ContentElementResource::editor(); } + public static function getViewAuthorizationResponse(Model $record): Response + { + return ContentElementResource::editor() ? Response::allow() : Response::deny(); + } + + public static function infolist(Schema $schema): Schema + { + return $schema->components([ + Section::make('Mitglieder')->description('Geordnete Fassungen, keine Kopie der Dateien.')->schema([ + TextEntry::make('members')->hiddenLabel()->listWithLineBreaks() + ->state(fn (Composition $record): array => app(CatalogReading::class)->compositionMembers($record)), + ]), + Section::make('Verwendung')->schema([ + TextEntry::make('usage')->hiddenLabel()->listWithLineBreaks() + ->state(fn (Composition $record): array => app(CatalogReading::class)->compositionUsage($record)), + ]), + ]); + } + public static function form(Schema $schema): Schema { return $schema; @@ -39,13 +66,14 @@ public static function table(Table $table): Table return $table->columns([ TextColumn::make('designation')->label('Bezeichnung')->searchable(), TextColumn::make('versions_count')->counts('versions')->label('Fassungen'), - ])->recordUrl(null); + ]); } public static function getPages(): array { return [ 'index' => ListCompositions::route('/'), + 'view' => ViewComposition::route('/{record}'), ]; } } diff --git a/app/Filament/Resources/Compositions/Pages/ListCompositions.php b/app/Filament/Resources/Compositions/Pages/ListCompositions.php index 1bd265c..6449e77 100644 --- a/app/Filament/Resources/Compositions/Pages/ListCompositions.php +++ b/app/Filament/Resources/Compositions/Pages/ListCompositions.php @@ -2,19 +2,14 @@ namespace App\Filament\Resources\Compositions\Pages; -use App\Domain\Catalog\Composition; -use App\Domain\Catalog\CompositionVersion; -use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentService; use App\Filament\Resources\Compositions\CompositionResource; use App\Filament\Resources\ContentElements\ContentElementResource; -use App\Filament\Support\CatalogOptions; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; -use Filament\Forms\Components\Repeater; -use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Resources\Pages\ListRecords; +use Illuminate\Contracts\Support\Htmlable; class ListCompositions extends ListRecords { @@ -22,6 +17,11 @@ class ListCompositions extends ListRecords protected static string $resource = CompositionResource::class; + public function getSubheading(): string|Htmlable|null + { + return 'Eine freie Zusammenstellung fertiger Fassungen, zum Beispiel Übung oder Programm. Verkauf und Rechte entstehen erst am Lizenzartikel und am Angebot.'; + } + protected function getHeaderActions(): array { return [ @@ -36,37 +36,6 @@ protected function getHeaderActions(): array app(ContentService::class)->createComposition($data['designation']); }, 'Die Komposition ist angelegt.'); }), - Action::make('publish') - ->label('Fassung veröffentlichen') - ->visible(fn (): bool => ContentElementResource::editor()) - ->schema([ - Select::make('composition_id')->label('Komposition')->options(fn (): array => CatalogOptions::compositions())->required(), - Repeater::make('members')->label('Mitglieder')->schema([ - TextInput::make('role')->label('Rolle')->required(), - Select::make('target')->label('Fassung')->options(fn (): array => CatalogOptions::readyTargets())->required(), - ])->minItems(1), - TextInput::make('note')->label('Bestätigungsnotiz'), - ]) - ->action(function (array $data): void { - $this->report(function () use ($data): void { - $members = []; - - foreach ($data['members'] as $member) { - [$type, $id] = explode(':', $member['target'], 2); - $target = $type === 'composition' - ? CompositionVersion::query()->findOrFail($id) - : ContentElementVersion::query()->findOrFail($id); - $members[] = ['role' => $member['role'], 'target' => $target]; - } - - app(ContentService::class)->publishComposition( - Composition::query()->findOrFail($data['composition_id']), - $members, - auth()->user(), - $data['note'] ?? null, - ); - }, 'Die Kompositionsfassung ist bestätigt und bereit.'); - }), ]; } } diff --git a/app/Filament/Resources/Compositions/Pages/ViewComposition.php b/app/Filament/Resources/Compositions/Pages/ViewComposition.php new file mode 100644 index 0000000..b5425db --- /dev/null +++ b/app/Filament/Resources/Compositions/Pages/ViewComposition.php @@ -0,0 +1,62 @@ +label('Fassung veröffentlichen') + ->schema([ + Repeater::make('members')->label('Mitglieder')->schema([ + TextInput::make('role')->label('Rolle')->required(), + Select::make('target')->label('Fassung')->options(fn (): array => CatalogOptions::readyTargets())->required(), + ])->minItems(1), + TextInput::make('note')->label('Bestätigungsnotiz'), + ]) + ->action(function (array $data): void { + $this->report(function () use ($data): void { + /** @var Composition $composition */ + $composition = $this->getRecord(); + $members = []; + + foreach ($data['members'] as $member) { + [$type, $id] = explode(':', $member['target'], 2); + $target = $type === 'composition' + ? CompositionVersion::query()->findOrFail($id) + : ContentElementVersion::query()->findOrFail($id); + $members[] = ['role' => $member['role'], 'target' => $target]; + } + + app(ContentService::class)->publishComposition( + $composition, + $members, + auth()->user(), + $data['note'] ?? null, + ); + }, 'Die Kompositionsfassung ist bestätigt und bereit.'); + $this->getRecord()->unsetRelations(); + $this->getRecord()->refresh(); + }), + ]; + } +} diff --git a/app/Filament/Resources/ContentElements/ContentElementResource.php b/app/Filament/Resources/ContentElements/ContentElementResource.php index 310827c..ea20482 100644 --- a/app/Filament/Resources/ContentElements/ContentElementResource.php +++ b/app/Filament/Resources/ContentElements/ContentElementResource.php @@ -5,18 +5,24 @@ use App\Domain\Catalog\ContentElement; use App\Domain\Identity\StaffRole; use App\Filament\Resources\ContentElements\Pages\ListContentElements; +use App\Filament\Resources\ContentElements\Pages\ViewContentElement; +use App\Filament\Support\CatalogReading; use App\Models\User; use Filament\Facades\Filament; +use Filament\Infolists\Components\TextEntry; use Filament\Resources\Resource; +use Filament\Schemas\Components\Section; use Filament\Schemas\Schema; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; +use Illuminate\Auth\Access\Response; +use Illuminate\Database\Eloquent\Model; class ContentElementResource extends Resource { protected static ?string $model = ContentElement::class; - protected static string|\UnitEnum|null $navigationGroup = 'Redaktion'; + protected static string|\UnitEnum|null $navigationGroup = 'Inhalte'; protected static ?string $navigationLabel = 'Inhaltselemente'; @@ -26,6 +32,8 @@ class ContentElementResource extends Resource protected static ?string $recordTitleAttribute = 'working_title'; + protected static ?int $navigationSort = 1; + public static function canViewAny(): bool { return self::editor(); @@ -38,6 +46,25 @@ public static function editor(): bool return $user instanceof User && $user->hasStaffRole(StaffRole::Redakteur); } + public static function getViewAuthorizationResponse(Model $record): Response + { + return self::editor() ? Response::allow() : Response::deny(); + } + + public static function infolist(Schema $schema): Schema + { + return $schema->components([ + Section::make('Fassungen')->schema([ + TextEntry::make('versions')->hiddenLabel()->listWithLineBreaks() + ->state(fn (ContentElement $record): array => app(CatalogReading::class)->elementVersions($record)), + ]), + Section::make('Verwendung')->description('Kompositionen und Lizenzartikel, die auf dieses Material zeigen.')->schema([ + TextEntry::make('usage')->hiddenLabel()->listWithLineBreaks() + ->state(fn (ContentElement $record): array => app(CatalogReading::class)->elementUsage($record)), + ]), + ]); + } + public static function form(Schema $schema): Schema { return $schema; @@ -50,13 +77,14 @@ public static function table(Table $table): Table TextColumn::make('kind')->label('Art'), TextColumn::make('output_class')->label('Ausgabeklasse'), TextColumn::make('versions_count')->counts('versions')->label('Fassungen'), - ])->recordUrl(null); + ]); } public static function getPages(): array { return [ 'index' => ListContentElements::route('/'), + 'view' => ViewContentElement::route('/{record}'), ]; } } diff --git a/app/Filament/Resources/ContentElements/Pages/ListContentElements.php b/app/Filament/Resources/ContentElements/Pages/ListContentElements.php index 1b38b98..c011f8e 100644 --- a/app/Filament/Resources/ContentElements/Pages/ListContentElements.php +++ b/app/Filament/Resources/ContentElements/Pages/ListContentElements.php @@ -2,17 +2,14 @@ namespace App\Filament\Resources\ContentElements\Pages; -use App\Domain\Catalog\ContentElement; use App\Domain\Catalog\ContentService; use App\Filament\Resources\ContentElements\ContentElementResource; -use App\Filament\Support\CatalogOptions; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; -use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Select; -use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Filament\Resources\Pages\ListRecords; +use Illuminate\Contracts\Support\Htmlable; class ListContentElements extends ListRecords { @@ -20,6 +17,11 @@ class ListContentElements extends ListRecords protected static string $resource = ContentElementResource::class; + public function getSubheading(): string|Htmlable|null + { + return 'Das Material selbst: Film, Text, PDF. Kompositionen und Lizenzartikel verweisen darauf.'; + } + protected function getHeaderActions(): array { return [ @@ -49,26 +51,6 @@ protected function getHeaderActions(): array app(ContentService::class)->createElement($data['kind'], $data['output_class'], $data['working_title']); }, 'Das Inhaltselement ist angelegt.'); }), - Action::make('version') - ->label('Fassung veröffentlichen') - ->visible(fn (): bool => ContentElementResource::editor()) - ->schema([ - Select::make('element_id')->label('Element')->options(fn (): array => CatalogOptions::elements())->required(), - Textarea::make('body')->label('Text'), - FileUpload::make('incoming')->label('Datei')->disk('cms_incoming')->directory('inhalte'), - TextInput::make('change_note')->label('Änderungsnotiz'), - ]) - ->action(function (array $data): void { - $this->report(function () use ($data): void { - $metadata = filled($data['incoming'] ?? null) ? ['incoming' => $data['incoming']] : []; - app(ContentService::class)->publishElementVersion( - ContentElement::query()->findOrFail($data['element_id']), - $data['body'] ?? null, - $metadata, - $data['change_note'] ?? null, - ); - }, 'Die Fassung ist gespeichert.'); - }), ]; } } diff --git a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php new file mode 100644 index 0000000..4f5a9e2 --- /dev/null +++ b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php @@ -0,0 +1,48 @@ +label('Fassung veröffentlichen') + ->schema([ + Textarea::make('body')->label('Text'), + FileUpload::make('incoming')->label('Datei')->disk('cms_incoming')->directory('inhalte'), + TextInput::make('change_note')->label('Änderungsnotiz'), + ]) + ->action(function (array $data): void { + $this->report(function () use ($data): void { + /** @var ContentElement $element */ + $element = $this->getRecord(); + $metadata = filled($data['incoming'] ?? null) ? ['incoming' => $data['incoming']] : []; + app(ContentService::class)->publishElementVersion( + $element, + $data['body'] ?? null, + $metadata, + $data['change_note'] ?? null, + ); + }, 'Die Fassung ist gespeichert.'); + $this->getRecord()->unsetRelations(); + $this->getRecord()->refresh(); + }), + ]; + } +} diff --git a/app/Filament/Resources/LicenseArticles/LicenseArticleResource.php b/app/Filament/Resources/LicenseArticles/LicenseArticleResource.php index afa0862..33b5da1 100644 --- a/app/Filament/Resources/LicenseArticles/LicenseArticleResource.php +++ b/app/Filament/Resources/LicenseArticles/LicenseArticleResource.php @@ -5,12 +5,18 @@ use App\Domain\Catalog\LicenseArticle; use App\Domain\Identity\StaffRole; use App\Filament\Resources\LicenseArticles\Pages\ListLicenseArticles; +use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle; +use App\Filament\Support\CatalogReading; use App\Models\User; use Filament\Facades\Filament; +use Filament\Infolists\Components\TextEntry; use Filament\Resources\Resource; +use Filament\Schemas\Components\Section; use Filament\Schemas\Schema; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; +use Illuminate\Auth\Access\Response; +use Illuminate\Database\Eloquent\Model; class LicenseArticleResource extends Resource { @@ -26,6 +32,8 @@ class LicenseArticleResource extends Resource protected static ?string $recordTitleAttribute = 'code'; + protected static ?int $navigationSort = 1; + public static function canViewAny(): bool { return self::keeper(); @@ -38,6 +46,25 @@ public static function keeper(): bool return $user instanceof User && $user->hasStaffRole(StaffRole::Katalogverwalter); } + public static function getViewAuthorizationResponse(Model $record): Response + { + return self::keeper() ? Response::allow() : Response::deny(); + } + + public static function infolist(Schema $schema): Schema + { + return $schema->components([ + Section::make('Aktueller Stand')->schema([ + TextEntry::make('stand')->hiddenLabel()->listWithLineBreaks() + ->state(fn (LicenseArticle $record): array => app(CatalogReading::class)->articleStand($record)), + ]), + Section::make('Pakete und Angebote')->description('Wo dieser Artikel lizenziert wird.')->schema([ + TextEntry::make('context')->hiddenLabel()->listWithLineBreaks() + ->state(fn (LicenseArticle $record): array => app(CatalogReading::class)->articleContext($record)), + ]), + ]); + } + public static function form(Schema $schema): Schema { return $schema; @@ -49,13 +76,14 @@ public static function table(Table $table): Table TextColumn::make('code')->label('Kennung')->searchable(), TextColumn::make('product_line')->label('Produktlinie'), TextColumn::make('currentRelease.number')->label('Aktueller Stand'), - ])->recordUrl(null); + ]); } public static function getPages(): array { return [ 'index' => ListLicenseArticles::route('/'), + 'view' => ViewLicenseArticle::route('/{record}'), ]; } } diff --git a/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php b/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php index daf55b5..111bd20 100644 --- a/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php +++ b/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php @@ -3,17 +3,12 @@ namespace App\Filament\Resources\LicenseArticles\Pages; use App\Domain\Catalog\ArticleService; -use App\Domain\Catalog\CompositionVersion; -use App\Domain\Catalog\ContentElementVersion; -use App\Domain\Catalog\LicenseArticle; use App\Filament\Resources\LicenseArticles\LicenseArticleResource; -use App\Filament\Support\CatalogOptions; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; -use Filament\Forms\Components\Select; -use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Filament\Resources\Pages\ListRecords; +use Illuminate\Contracts\Support\Htmlable; class ListLicenseArticles extends ListRecords { @@ -21,6 +16,11 @@ class ListLicenseArticles extends ListRecords protected static string $resource = LicenseArticleResource::class; + public function getSubheading(): string|Htmlable|null + { + return 'Kleinste lizenzierbare Einheit. Der Stand hält fest, welche Inhalte dazugehören. Pakete und Angebote verweisen auf den Artikel, sie kopieren ihn nicht.'; + } + protected function getHeaderActions(): array { return [ @@ -35,54 +35,6 @@ protected function getHeaderActions(): array app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null); }, 'Der Lizenzartikel ist angelegt.'); }), - Action::make('release') - ->label('Stand veröffentlichen') - ->schema([ - Select::make('article_id')->label('Artikel')->options(fn (): array => CatalogOptions::articles())->required(), - Select::make('root')->label('Wurzel')->options(fn (): array => CatalogOptions::readyTargets())->required(), - Textarea::make('classification')->label('Einordnung')->required(), - TextInput::make('change_note')->label('Änderungshinweis'), - ]) - ->action(function (array $data): void { - $this->report(function () use ($data): string { - [$type, $id] = explode(':', $data['root'], 2); - $root = $type === 'composition' - ? CompositionVersion::query()->findOrFail($id) - : ContentElementVersion::query()->findOrFail($id); - $release = app(ArticleService::class)->publishRelease( - LicenseArticle::query()->findOrFail($data['article_id']), - $root, - $data['classification'], - $data['change_note'] ?? null, - ); - $report = $release->impact_report ?? []; - $offers = $report['offers'] ?? []; - - return 'Stand '.$release->number.' ist veröffentlicht. Inhalte: '.($report['contents'] ?? 0) - .', Inhaber: '.($report['holders'] ?? 0) - .', Angebote: '.(implode(', ', $offers) !== '' ? implode(', ', $offers) : 'keins').'.'; - }, 'Der Artikel-Stand ist veröffentlicht.'); - }), - Action::make('withdraw') - ->label('Stand zurückziehen') - ->schema([ - Select::make('article_id')->label('Artikel')->options(fn (): array => CatalogOptions::articles())->required(), - Textarea::make('reason')->label('Begründung')->required(), - ]) - ->action(function (array $data): void { - $this->report(function () use ($data): string { - $result = app(ArticleService::class)->withdraw( - LicenseArticle::query()->findOrFail($data['article_id']), - $data['reason'], - ); - $current = $result['fallback_number'] === null - ? 'Es gibt keinen früheren Stand.' - : 'Aktuell ist wieder Stand '.$result['fallback_number'].'.'; - $holders = $result['holders'] === [] ? 'niemand' : implode(', ', $result['holders']); - - return 'Der Stand ist zurückgezogen. '.$current.' Betroffen: '.$holders.'.'; - }, 'Der Stand ist zurückgezogen.'); - }), ]; } } diff --git a/app/Filament/Resources/LicenseArticles/Pages/ViewLicenseArticle.php b/app/Filament/Resources/LicenseArticles/Pages/ViewLicenseArticle.php new file mode 100644 index 0000000..b9d69b0 --- /dev/null +++ b/app/Filament/Resources/LicenseArticles/Pages/ViewLicenseArticle.php @@ -0,0 +1,83 @@ +label('Stand veröffentlichen') + ->schema([ + Select::make('root')->label('Wurzel')->options(fn (): array => CatalogOptions::readyTargets())->required(), + Textarea::make('classification')->label('Einordnung')->required() + ->helperText('Warum dies derselbe Lizenzartikel bleibt und kein neues Produkt ist.'), + TextInput::make('change_note')->label('Änderungshinweis'), + ]) + ->action(function (array $data): void { + $this->report(function () use ($data): string { + /** @var LicenseArticle $article */ + $article = $this->getRecord(); + [$type, $id] = explode(':', $data['root'], 2); + $root = $type === 'composition' + ? CompositionVersion::query()->findOrFail($id) + : ContentElementVersion::query()->findOrFail($id); + $release = app(ArticleService::class)->publishRelease( + $article, + $root, + $data['classification'], + $data['change_note'] ?? null, + ); + $report = $release->impact_report ?? []; + $offers = $report['offers'] ?? []; + + return 'Stand '.$release->number.' ist veröffentlicht. Inhalte: '.($report['contents'] ?? 0) + .', Inhaber: '.($report['holders'] ?? 0) + .', Angebote: '.(implode(', ', $offers) !== '' ? implode(', ', $offers) : 'keins').'.'; + }, 'Der Artikel-Stand ist veröffentlicht.'); + $this->refreshRecord(); + }), + Action::make('withdraw') + ->label('Stand zurückziehen') + ->schema([ + Textarea::make('reason')->label('Begründung')->required(), + ]) + ->action(function (array $data): void { + $this->report(function () use ($data): string { + $result = app(ArticleService::class)->withdraw($this->getRecord(), $data['reason']); + $current = $result['fallback_number'] === null + ? 'Es gibt keinen früheren Stand.' + : 'Aktuell ist wieder Stand '.$result['fallback_number'].'.'; + $holders = $result['holders'] === [] ? 'niemand' : implode(', ', $result['holders']); + + return 'Der Stand ist zurückgezogen. '.$current.' Betroffen: '.$holders.'.'; + }, 'Der Stand ist zurückgezogen.'); + $this->refreshRecord(); + }), + ]; + } + + private function refreshRecord(): void + { + $this->getRecord()->unsetRelations(); + $this->getRecord()->refresh(); + } +} diff --git a/app/Filament/Resources/Offers/OfferResource.php b/app/Filament/Resources/Offers/OfferResource.php index 096c676..c68cd4d 100644 --- a/app/Filament/Resources/Offers/OfferResource.php +++ b/app/Filament/Resources/Offers/OfferResource.php @@ -5,10 +5,16 @@ use App\Domain\Catalog\Offer; use App\Filament\Resources\LicenseArticles\LicenseArticleResource; use App\Filament\Resources\Offers\Pages\ListOffers; +use App\Filament\Resources\Offers\Pages\ViewOffer; +use App\Filament\Support\CatalogReading; +use Filament\Infolists\Components\TextEntry; use Filament\Resources\Resource; +use Filament\Schemas\Components\Section; use Filament\Schemas\Schema; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; +use Illuminate\Auth\Access\Response; +use Illuminate\Database\Eloquent\Model; class OfferResource extends Resource { @@ -24,11 +30,32 @@ class OfferResource extends Resource protected static ?string $recordTitleAttribute = 'name'; + protected static ?int $navigationSort = 4; + public static function canViewAny(): bool { return LicenseArticleResource::keeper(); } + public static function getViewAuthorizationResponse(Model $record): Response + { + return LicenseArticleResource::keeper() ? Response::allow() : Response::deny(); + } + + public static function infolist(Schema $schema): Schema + { + return $schema->components([ + Section::make('Positionen')->description('Was angeboten wird, mit welchem Rechteprofil.')->schema([ + TextEntry::make('positions')->hiddenLabel()->listWithLineBreaks() + ->state(fn (Offer $record): array => app(CatalogReading::class)->offerPositions($record)), + ]), + Section::make('Aufgelöste Berechtigungen')->description('Diese Artikel-Rechte entstehen beim Erwerb.')->schema([ + TextEntry::make('grants')->hiddenLabel()->listWithLineBreaks() + ->state(fn (Offer $record): array => app(CatalogReading::class)->offerGrants($record)), + ]), + ]); + } + public static function form(Schema $schema): Schema { return $schema; @@ -39,13 +66,14 @@ public static function table(Table $table): Table return $table->columns([ TextColumn::make('name')->label('Name')->searchable(), TextColumn::make('versions.status')->label('Fassungen')->badge(), - ])->recordUrl(null); + ]); } public static function getPages(): array { return [ 'index' => ListOffers::route('/'), + 'view' => ViewOffer::route('/{record}'), ]; } } diff --git a/app/Filament/Resources/Offers/Pages/ListOffers.php b/app/Filament/Resources/Offers/Pages/ListOffers.php index 2c9a129..bddef5e 100644 --- a/app/Filament/Resources/Offers/Pages/ListOffers.php +++ b/app/Filament/Resources/Offers/Pages/ListOffers.php @@ -2,20 +2,13 @@ namespace App\Filament\Resources\Offers\Pages; -use App\Domain\Catalog\BundleVersion; -use App\Domain\Catalog\LicenseArticle; -use App\Domain\Catalog\Offer; use App\Domain\Catalog\OfferService; -use App\Domain\Catalog\RightsProfileVersion; use App\Filament\Resources\Offers\OfferResource; -use App\Filament\Support\CatalogOptions; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; -use Filament\Forms\Components\Repeater; -use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Resources\Pages\ListRecords; -use Filament\Schemas\Components\Utilities\Get; +use Illuminate\Contracts\Support\Htmlable; class ListOffers extends ListRecords { @@ -23,6 +16,11 @@ class ListOffers extends ListRecords protected static string $resource = OfferResource::class; + public function getSubheading(): string|Htmlable|null + { + return 'Ein Angebot verbindet Artikel oder eine Paketfassung mit einem Rechteprofil. Die aufgelösten Berechtigungen stehen auf der Angebotsseite.'; + } + protected function getHeaderActions(): array { return [ @@ -33,46 +31,6 @@ protected function getHeaderActions(): array app(OfferService::class)->create($data['name']); }, 'Das Angebot ist angelegt.'); }), - Action::make('activate')->label('Fassung aktivieren')->schema([ - Select::make('offer_id')->label('Angebot')->options(fn (): array => CatalogOptions::offers())->required(), - Select::make('grant_kind')->label('Vergabe')->options([ - 'kauf' => 'Kauf', - 'auf_abruf' => 'Auf Abruf', - 'bei_registrierung' => 'Bei Registrierung', - ])->required(), - TextInput::make('price_cents')->label('Preis in Cent')->numeric(), - Repeater::make('lines')->label('Positionen')->schema([ - Select::make('kind')->label('Ziel')->options([ - 'article' => 'Lizenzartikel', - 'bundle' => 'Paketfassung', - ])->required()->live(), - Select::make('article_id')->label('Artikel')->options(fn (): array => CatalogOptions::articles()) - ->visible(fn (Get $get): bool => $get('kind') === 'article'), - Select::make('bundle_version_id')->label('Paketfassung')->options(fn (): array => CatalogOptions::bundleVersions()) - ->visible(fn (Get $get): bool => $get('kind') === 'bundle'), - Select::make('rights_id')->label('Rechte')->options(fn (): array => CatalogOptions::rights())->required(), - ])->minItems(1), - ])->action(function (array $data): void { - $this->report(function () use ($data): void { - $lines = []; - - foreach ($data['lines'] as $line) { - $target = $line['kind'] === 'bundle' - ? BundleVersion::query()->findOrFail($line['bundle_version_id']) - : LicenseArticle::query()->findOrFail($line['article_id']); - $lines[] = [ - 'target' => $target, - 'rights' => RightsProfileVersion::query()->findOrFail($line['rights_id']), - ]; - } - - app(OfferService::class)->activate(Offer::query()->findOrFail($data['offer_id']), $lines, [ - 'grant_kind' => $data['grant_kind'], - 'price_cents' => $data['price_cents'] === null || $data['price_cents'] === '' ? null : (int) $data['price_cents'], - 'holder_kind' => 'person', - ]); - }, 'Die Angebotsfassung ist aktiv.'); - }), ]; } } diff --git a/app/Filament/Resources/Offers/Pages/ViewOffer.php b/app/Filament/Resources/Offers/Pages/ViewOffer.php new file mode 100644 index 0000000..4b21668 --- /dev/null +++ b/app/Filament/Resources/Offers/Pages/ViewOffer.php @@ -0,0 +1,75 @@ +label('Fassung aktivieren')->schema([ + Select::make('grant_kind')->label('Vergabe')->options([ + 'kauf' => 'Kauf', + 'auf_abruf' => 'Auf Abruf', + 'bei_registrierung' => 'Bei Registrierung', + ])->required(), + TextInput::make('price_cents')->label('Preis in Cent')->numeric() + ->helperText('Nur bei einem Kauf. 500 bedeutet 5,00 €.'), + Repeater::make('lines')->label('Positionen')->schema([ + Select::make('kind')->label('Ziel')->options([ + 'article' => 'Lizenzartikel', + 'bundle' => 'Paketfassung', + ])->required()->live(), + Select::make('article_id')->label('Artikel')->options(fn (): array => CatalogOptions::articles()) + ->visible(fn (Get $get): bool => $get('kind') === 'article'), + Select::make('bundle_version_id')->label('Paketfassung')->options(fn (): array => CatalogOptions::bundleVersions()) + ->visible(fn (Get $get): bool => $get('kind') === 'bundle'), + Select::make('rights_id')->label('Rechte')->options(fn (): array => CatalogOptions::rights())->required(), + ])->minItems(1), + ])->action(function (array $data): void { + $this->report(function () use ($data): void { + /** @var Offer $offer */ + $offer = $this->getRecord(); + $lines = []; + + foreach ($data['lines'] as $line) { + $target = $line['kind'] === 'bundle' + ? BundleVersion::query()->findOrFail($line['bundle_version_id']) + : LicenseArticle::query()->findOrFail($line['article_id']); + $lines[] = [ + 'target' => $target, + 'rights' => RightsProfileVersion::query()->findOrFail($line['rights_id']), + ]; + } + + app(OfferService::class)->activate($offer, $lines, [ + 'grant_kind' => $data['grant_kind'], + 'price_cents' => $data['price_cents'] === null || $data['price_cents'] === '' ? null : (int) $data['price_cents'], + 'holder_kind' => 'person', + ]); + }, 'Die Angebotsfassung ist aktiv.'); + $this->getRecord()->unsetRelations(); + $this->getRecord()->refresh(); + }), + ]; + } +} diff --git a/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php b/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php index ec17ef8..bbc2ce1 100644 --- a/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php +++ b/app/Filament/Resources/RightsProfiles/Pages/ListRightsProfiles.php @@ -10,6 +10,7 @@ use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Resources\Pages\ListRecords; +use Illuminate\Contracts\Support\Htmlable; class ListRightsProfiles extends ListRecords { @@ -17,6 +18,11 @@ class ListRightsProfiles extends ListRecords protected static string $resource = RightsProfileResource::class; + public function getSubheading(): string|Htmlable|null + { + return 'Ein Rechteprofil beschreibt den Zweck und die erlaubten Handlungen. Es wird nicht verkauft; ein Angebot verbindet es mit Artikeln.'; + } + protected function getHeaderActions(): array { return [ diff --git a/app/Filament/Resources/RightsProfiles/Pages/ViewRightsProfile.php b/app/Filament/Resources/RightsProfiles/Pages/ViewRightsProfile.php new file mode 100644 index 0000000..71ea83c --- /dev/null +++ b/app/Filament/Resources/RightsProfiles/Pages/ViewRightsProfile.php @@ -0,0 +1,11 @@ +components([ + Section::make('Fähigkeiten')->description('Zweck und erlaubte Handlungen. Angebote verwenden diese Fassung.')->schema([ + TextEntry::make('rights')->hiddenLabel()->listWithLineBreaks() + ->state(fn (RightsProfile $record): array => app(CatalogReading::class)->rights($record)), + ]), + ]); + } + public static function form(Schema $schema): Schema { return $schema; @@ -39,13 +62,14 @@ public static function table(Table $table): Table return $table->columns([ TextColumn::make('name')->label('Name')->searchable(), TextColumn::make('versions.purpose')->label('Zwecke')->badge(), - ])->recordUrl(null); + ]); } public static function getPages(): array { return [ 'index' => ListRightsProfiles::route('/'), + 'view' => ViewRightsProfile::route('/{record}'), ]; } } diff --git a/app/Filament/Support/CatalogReading.php b/app/Filament/Support/CatalogReading.php new file mode 100644 index 0000000..c2ea45b --- /dev/null +++ b/app/Filament/Support/CatalogReading.php @@ -0,0 +1,410 @@ + + */ + public function articleStand(LicenseArticle $article): array + { + $release = $article->currentRelease()->with(['contents.elementVersion.element'])->first(); + + if ($release === null) { + return ['Noch kein Stand veröffentlicht. Ein Lizenzartikel ohne Stand vergibt keine Inhalte.']; + } + + $lines = [ + 'Stand '.$release->number.' · '.$this->status($release->status).' · '.$release->classification_note, + ]; + + foreach ($release->contents as $content) { + $title = $content->elementVersion?->element?->working_title ?? 'Inhalt fehlt'; + $lines[] = $content->path.' — '.$title; + } + + if ($release->contents->isEmpty()) { + $lines[] = 'Dieser Stand hat keine festgeschriebenen Inhalte.'; + } + + return $lines; + } + + /** + * @return list + */ + public function articleContext(LicenseArticle $article): array + { + $lines = []; + + foreach (BundleVersion::query()->where('status', BundleStatus::Veroeffentlicht)->with('bundle')->orderBy('id')->get() as $version) { + try { + $ids = app(BundleService::class)->articleIds($version); + } catch (DomainRuleException $exception) { + continue; + } + + if (in_array($article->id, $ids, true)) { + $lines[] = 'Paket '.$version->bundle->name.' · Fassung '.$version->number; + } + } + + $scopes = ResolvedScope::query() + ->where('license_article_id', $article->id) + ->with(['offerVersion.offer', 'rights.profile']) + ->orderBy('id') + ->get(); + + foreach ($scopes as $scope) { + $version = $scope->offerVersion; + $lines[] = 'Angebot '.$version->offer->name + .' · Fassung '.$version->number + .' · '.$this->status($version->status) + .' · '.$this->grant($version) + .' · '.$scope->rights->profile->name + .' ('.$this->capabilities($scope->rights).')'; + } + + return $lines === [] + ? ['Dieser Artikel ist noch in keinem veröffentlichten Paket und in keiner Angebotsfassung aufgelöst.'] + : $lines; + } + + /** + * @return list + */ + public function bundleParts(Bundle $bundle): array + { + $version = $this->publishedBundle($bundle); + + if ($version === null) { + return ['Noch keine veröffentlichte Fassung. Bestandteile werden mit der Fassung festgeschrieben.']; + } + + $lines = ['Fassung '.$version->number]; + + foreach ($version->items as $item) { + if ($item->article !== null) { + $lines[] = 'Lizenzartikel '.$item->article->code; + + continue; + } + + $lines[] = 'Paket '.($item->nestedBundle->name ?? 'fehlt'); + } + + $older = $bundle->versions()->where('status', BundleStatus::Veroeffentlicht)->count() - 1; + + if ($older > 0) { + $lines[] = $older.' ältere Fassung'.($older === 1 ? '' : 'en').' bleibt unverändert.'; + } + + return $lines; + } + + /** + * @return list + */ + public function bundleArticles(Bundle $bundle): array + { + $version = $this->publishedBundle($bundle); + + if ($version === null) { + return ['Ohne Fassung gibt es nichts aufzulösen.']; + } + + try { + $ids = app(BundleService::class)->articleIds($version); + } catch (DomainRuleException $exception) { + return [$exception->getMessage()]; + } + + $codes = LicenseArticle::query()->whereIn('id', $ids)->orderBy('code')->pluck('code')->all(); + + return $codes === [] + ? ['Die Fassung löst keinen Lizenzartikel auf.'] + : $codes; + } + + /** + * @return list + */ + public function offerPositions(Offer $offer): array + { + $version = $this->activeOffer($offer); + + if ($version === null) { + return ['Noch keine aktive Fassung. Ein Angebot ohne Fassung kann niemand erwerben.']; + } + + $lines = [ + 'Fassung '.$version->number.' · '.$this->status($version->status).' · '.$this->grant($version), + ]; + + foreach ($version->lines as $line) { + $target = $line->article !== null + ? 'Lizenzartikel '.$line->article->code + : 'Paket '.($line->bundleVersion->bundle->name ?? 'fehlt').' · Fassung '.($line->bundleVersion->number ?? '–'); + $lines[] = $target.' · Rechte '.$line->rights->profile->name; + } + + return $lines; + } + + /** + * @return list + */ + public function offerGrants(Offer $offer): array + { + $version = $this->activeOffer($offer); + + if ($version === null) { + return ['Der Leistungsumfang wird erst beim Aktivieren aufgelöst.']; + } + + $lines = []; + + foreach ($version->resolvedScopes as $scope) { + $lines[] = $scope->article->code.' · '.$scope->rights->profile->name.' · '.$this->capabilities($scope->rights); + } + + return $lines === [] + ? ['Diese Fassung hat keinen aufgelösten Leistungsumfang.'] + : $lines; + } + + /** + * @return list + */ + public function rights(RightsProfile $profile): array + { + $version = $profile->versions()->orderByDesc('number')->first(); + + if ($version === null) { + return ['Noch keine Fassung.']; + } + + return [ + 'Fassung '.$version->number.' · '.$this->purpose($version->purpose), + $this->capabilities($version), + ]; + } + + /** + * @return list + */ + public function elementVersions(ContentElement $element): array + { + $versions = $element->versions()->orderByDesc('number')->get(); + + if ($versions->isEmpty()) { + return ['Noch keine Fassung.']; + } + + return $versions->map(function ($version): string { + $note = filled($version->change_note) ? ' · '.$version->change_note : ''; + + return 'Fassung '.$version->number.' · '.$this->status($version->status).$note; + })->all(); + } + + /** + * @return list + */ + public function elementUsage(ContentElement $element): array + { + $versionIds = $element->versions()->pluck('id'); + $lines = []; + + $members = CompositionMember::query() + ->whereIn('content_element_version_id', $versionIds) + ->with(['compositionVersion.composition', 'contentElementVersion']) + ->orderBy('id') + ->get(); + + foreach ($members as $member) { + $lines[] = 'Komposition '.$member->compositionVersion->composition->designation + .' · Fassung '.$member->compositionVersion->number + .' · Rolle '.$member->role; + } + + $contents = ReleaseContent::query() + ->whereIn('content_element_version_id', $versionIds) + ->with(['release.article', 'elementVersion']) + ->orderBy('id') + ->get(); + + foreach ($contents as $content) { + $lines[] = 'Lizenzartikel '.$content->release->article->code + .' · Stand '.$content->release->number + .' · '.$content->path; + } + + return $lines === [] + ? ['Noch in keiner Komposition und in keinem Artikel-Stand verwendet.'] + : $lines; + } + + /** + * @return list + */ + public function compositionMembers(Composition $composition): array + { + $version = $composition->versions() + ->where('status', ContentVersionStatus::Bereit) + ->orderByDesc('number') + ->with(['members.contentElementVersion.element', 'members.nestedCompositionVersion.composition']) + ->first(); + + if ($version === null) { + return ['Noch keine bestätigte Fassung.']; + } + + $lines = ['Fassung '.$version->number]; + + foreach ($version->members as $member) { + if ($member->contentElementVersion !== null) { + $lines[] = $member->role.' — '.$member->contentElementVersion->element->working_title; + + continue; + } + + $nested = $member->nestedCompositionVersion; + $lines[] = $member->role.' — Komposition '.($nested->composition->designation ?? 'fehlt'); + } + + return $lines; + } + + /** + * @return list + */ + public function compositionUsage(Composition $composition): array + { + $versionIds = $composition->versions()->pluck('id'); + $lines = []; + + $parents = CompositionMember::query() + ->whereIn('nested_composition_version_id', $versionIds) + ->with('compositionVersion.composition') + ->orderBy('id') + ->get(); + + foreach ($parents as $member) { + $lines[] = 'Komposition '.$member->compositionVersion->composition->designation + .' · Fassung '.$member->compositionVersion->number + .' · Rolle '.$member->role; + } + + $articles = LicenseArticle::query() + ->whereHas('releases', function ($query) use ($versionIds): void { + $query->whereIn('root_composition_version_id', $versionIds); + }) + ->orderBy('code') + ->pluck('code'); + + foreach ($articles as $code) { + $lines[] = 'Wurzel des Lizenzartikels '.$code; + } + + return $lines === [] + ? ['Noch nicht in einer anderen Komposition und nicht als Wurzel eines Artikels verwendet.'] + : $lines; + } + + private function publishedBundle(Bundle $bundle): ?BundleVersion + { + return $bundle->versions() + ->where('status', BundleStatus::Veroeffentlicht) + ->orderByDesc('number') + ->with(['items.article', 'items.nestedBundle']) + ->first(); + } + + private function activeOffer(Offer $offer): ?OfferVersion + { + return $offer->versions() + ->where('status', OfferStatus::Aktiv) + ->orderByDesc('number') + ->with([ + 'lines.article', + 'lines.bundleVersion.bundle', + 'lines.rights.profile', + 'resolvedScopes.article', + 'resolvedScopes.rights.profile', + ]) + ->first(); + } + + private function grant(OfferVersion $version): string + { + $kind = match ($version->grant_kind) { + 'kauf' => 'Kauf', + 'auf_abruf' => 'Auf Abruf', + 'bei_registrierung' => 'Bei Registrierung', + default => (string) $version->grant_kind, + }; + + if ($version->price_cents === null) { + return $kind; + } + + return $kind.' · '.number_format($version->price_cents / 100, 2, ',', '.').' €'; + } + + private function capabilities(RightsProfileVersion $version): string + { + $parts = []; + + foreach ($version->capabilities ?? [] as $class => $actions) { + $actions = is_array($actions) ? implode(', ', $actions) : (string) $actions; + $parts[] = $class.': '.$actions; + } + + return $parts === [] ? 'keine Fähigkeiten' : implode('; ', $parts); + } + + private function purpose(string $purpose): string + { + return match ($purpose) { + 'ehrenamtlich' => 'Ehrenamtlich', + 'kommerziell' => 'Kommerziell', + 'institutionell' => 'Institutionell', + default => $purpose, + }; + } + + private function status(mixed $status): string + { + return match (StatusValue::of($status)) { + 'veroeffentlicht' => 'veröffentlicht', + 'abgeloest_verfuegbar' => 'abgelöst, weiterhin verfügbar', + 'gesperrt' => 'gesperrt', + 'bereit' => 'bereit', + 'entwurf' => 'Entwurf', + 'aktiv' => 'aktiv', + 'beendet' => 'beendet', + default => StatusValue::of($status) ?? 'unbekannt', + }; + } +} diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 2a158d4..66090b9 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -63,6 +63,13 @@ public function unverified(): static ]); } + public function katalogverwalter(): static + { + return $this->afterCreating(function (User $user): void { + $user->staffRoles()->create(['role' => StaffRole::Katalogverwalter]); + }); + } + public function redakteur(): static { return $this->afterCreating(function (User $user): void { diff --git a/docs/betrieb/MVP-Stand.md b/docs/betrieb/MVP-Stand.md index a037d48..0434703 100644 --- a/docs/betrieb/MVP-Stand.md +++ b/docs/betrieb/MVP-Stand.md @@ -6,7 +6,7 @@ ## Bedienbar - Öffentliche Seiten unter `/verwaltung` als Redakteur: Entwurf, Veröffentlichung, Wiederherstellung. - Inhaltselemente, Fassungen und Kompositionen als Redakteur. Eine Datei wird von der Queue nach `derived/` kopiert. -- Lizenzartikel, verschachtelte Pakete, Rechteprofile und Angebote als Katalogverwalter. Ein neuer Stand zeigt Inhaber, Angebote und Inhaltszahl; ein Rückzug stellt den vorherigen Stand wieder her und nennt die Betroffenen. +- 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. - Bibliothek entscheidet je Abruf erneut. Filme mit Datei werden im Player geladen, Texte und PDF über einen kurz signierten Abruf. diff --git a/tests/Feature/CatalogAdministrationTest.php b/tests/Feature/CatalogAdministrationTest.php new file mode 100644 index 0000000..9aba3a4 --- /dev/null +++ b/tests/Feature/CatalogAdministrationTest.php @@ -0,0 +1,104 @@ +publishElementVersion( + $content->createElement('pdf', 'pdf', 'Merkblatt Alltag'), + 'Hinweis für die Prüfung.', + ); + $exercise = $content->publishComposition( + $content->createComposition('Übung Alltag'), + [['role' => 'Merkblatt', 'target' => $sheet]], + ); + $sheetArticle = $articles->create('demo-merkblatt', 'Erprobung'); + $articles->publishRelease($sheetArticle, $sheet, 'Eigenständiges Merkblatt.'); + $exerciseArticle = $articles->create('demo-uebung', 'Erprobung'); + $articles->publishRelease($exerciseArticle, $exercise, 'Übung aus dem Merkblatt.'); + + $basis = $bundles->create('Demo Basis'); + $bundles->publish($basis, [$sheetArticle->fresh()]); + $program = $bundles->create('Demo Programm'); + $programVersion = $bundles->publish($program, [$basis, $exerciseArticle->fresh()]); + + $rights = $offers->createRightsProfile('Erprobung lesen und ansehen', 'ehrenamtlich', [ + 'pdf' => ['ansehen', 'laden'], + ]); + $free = $offers->create('Kostenloses Merkblatt'); + $offers->activate($free, [ + ['target' => $sheetArticle->fresh(), 'rights' => $rights], + ], ['grant_kind' => 'auf_abruf']); + $paid = $offers->create('Testkauf Programm'); + $offers->activate($paid, [ + ['target' => $programVersion, 'rights' => $rights], + ], ['grant_kind' => 'kauf', 'price_cents' => 500]); + + $keeper = User::factory()->katalogverwalter()->create(); + $keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + $editor = User::factory()->redakteur()->create(); + $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + $this->actingAs($editor, 'staff') + ->get(BundleResource::getUrl('view', ['record' => $program])) + ->assertForbidden(); + + $this->actingAs($keeper, 'staff') + ->get(BundleResource::getUrl('index')) + ->assertOk() + ->assertSee('aufgelösten Artikel'); + + $this->actingAs($keeper, 'staff') + ->get(BundleResource::getUrl('view', ['record' => $program])) + ->assertOk() + ->assertSee('Paket Demo Basis') + ->assertSee('Lizenzartikel demo-uebung') + ->assertSee('demo-merkblatt') + ->assertSee('demo-uebung'); + + $this->actingAs($keeper, 'staff') + ->get(LicenseArticleResource::getUrl('view', ['record' => $sheetArticle])) + ->assertOk() + ->assertSee('Merkblatt Alltag') + ->assertSee('Paket Demo Basis') + ->assertSee('Angebot Kostenloses Merkblatt') + ->assertSee('pdf: ansehen, laden'); + + $this->actingAs($keeper, 'staff') + ->get(OfferResource::getUrl('view', ['record' => $paid])) + ->assertOk() + ->assertSee('Kauf · 5,00 €') + ->assertSee('demo-merkblatt') + ->assertSee('demo-uebung') + ->assertSee('Erprobung lesen und ansehen'); + + $sheet->load('element'); + + $this->actingAs($editor, 'staff') + ->get(ContentElementResource::getUrl('view', ['record' => $sheet->element])) + ->assertOk() + ->assertSee('Komposition Übung Alltag') + ->assertSee('Lizenzartikel demo-merkblatt'); + } +}