Zeige im Katalog, wie Inhalte, Pakete und Rechte zusammenhängen.
Deploy Test / test (push) Successful in 13s
Deploy Test / deploy (push) Successful in 23s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-15 10:03:19 +01:00
1 parent fa706e5080
commit cd79fb99d7
22 files changed
+1066 -200

No files matched your search

@@ -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}'),
];
}
}
@@ -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.');
}),
];
}
}
@@ -0,0 +1,83 @@
<?php
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\ViewRecord;
class ViewLicenseArticle extends ViewRecord
{
use ReportsDomainRules;
protected static string $resource = LicenseArticleResource::class;
protected function getHeaderActions(): array
{
return [
Action::make('release')
->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();
}
}