Implement compliance exports and retention overrides
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DataExportResource\Pages;
|
||||
|
||||
use App\Enums\DataExportScope;
|
||||
use App\Filament\Resources\DataExportResource;
|
||||
use App\Filament\Resources\Pages\AuditedCreateRecord;
|
||||
use App\Jobs\GenerateDataExport;
|
||||
use App\Models\DataExport;
|
||||
use Filament\Facades\Filament;
|
||||
|
||||
class CreateDataExport extends AuditedCreateRecord
|
||||
{
|
||||
protected static string $resource = DataExportResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['user_id'] = Filament::auth()->id();
|
||||
$data['status'] = DataExport::STATUS_PENDING;
|
||||
|
||||
if (($data['scope'] ?? null) !== DataExportScope::EVENT->value) {
|
||||
$data['event_id'] = null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
parent::afterCreate();
|
||||
|
||||
GenerateDataExport::dispatch($this->record->id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DataExportResource\Pages;
|
||||
|
||||
use App\Filament\Resources\DataExportResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListDataExports extends ListRecords
|
||||
{
|
||||
protected static string $resource = DataExportResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()
|
||||
->label(__('admin.data_exports.actions.request')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DataExportResource\Schemas;
|
||||
|
||||
use App\Enums\DataExportScope;
|
||||
use App\Models\Event;
|
||||
use App\Models\Tenant;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class DataExportForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema->schema([
|
||||
Section::make(__('admin.data_exports.sections.request'))
|
||||
->schema([
|
||||
Select::make('scope')
|
||||
->label(__('admin.data_exports.fields.scope'))
|
||||
->options([
|
||||
DataExportScope::TENANT->value => __('admin.data_exports.scope.tenant'),
|
||||
DataExportScope::EVENT->value => __('admin.data_exports.scope.event'),
|
||||
])
|
||||
->default(DataExportScope::TENANT->value)
|
||||
->live()
|
||||
->required(),
|
||||
Select::make('tenant_id')
|
||||
->label(__('admin.data_exports.fields.tenant'))
|
||||
->options(Tenant::query()->orderBy('name')->pluck('name', 'id'))
|
||||
->searchable()
|
||||
->preload()
|
||||
->required()
|
||||
->live(),
|
||||
Select::make('event_id')
|
||||
->label(__('admin.data_exports.fields.event'))
|
||||
->options(function (Get $get): array {
|
||||
$tenantId = $get('tenant_id');
|
||||
if (! $tenantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Event::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->orderByDesc('date')
|
||||
->get()
|
||||
->mapWithKeys(function (Event $event): array {
|
||||
$name = $event->name['de'] ?? $event->name['en'] ?? $event->slug;
|
||||
|
||||
return [$event->id => $name];
|
||||
})
|
||||
->all();
|
||||
})
|
||||
->searchable()
|
||||
->preload()
|
||||
->visible(fn (Get $get): bool => $get('scope') === DataExportScope::EVENT->value)
|
||||
->required(fn (Get $get): bool => $get('scope') === DataExportScope::EVENT->value)
|
||||
->dehydrated(fn (Get $get): bool => $get('scope') === DataExportScope::EVENT->value),
|
||||
Toggle::make('include_media')
|
||||
->label(__('admin.data_exports.fields.include_media'))
|
||||
->helperText(__('admin.data_exports.help.include_media')),
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DataExportResource\Tables;
|
||||
|
||||
use App\Models\DataExport;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Number;
|
||||
|
||||
class DataExportTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label(__('admin.data_exports.fields.id'))
|
||||
->sortable(),
|
||||
TextColumn::make('tenant.name')
|
||||
->label(__('admin.data_exports.fields.tenant'))
|
||||
->searchable(),
|
||||
TextColumn::make('event.slug')
|
||||
->label(__('admin.data_exports.fields.event'))
|
||||
->toggleable()
|
||||
->placeholder('—'),
|
||||
TextColumn::make('scope')
|
||||
->label(__('admin.data_exports.fields.scope'))
|
||||
->badge()
|
||||
->formatStateUsing(fn (?string $state) => $state ? __('admin.data_exports.scope.'.$state) : '—'),
|
||||
TextColumn::make('status')
|
||||
->label(__('admin.data_exports.fields.status'))
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => __('admin.data_exports.status.'.$state))
|
||||
->color(fn (string $state) => match ($state) {
|
||||
DataExport::STATUS_READY => 'success',
|
||||
DataExport::STATUS_FAILED => 'danger',
|
||||
DataExport::STATUS_PROCESSING => 'warning',
|
||||
default => 'gray',
|
||||
}),
|
||||
IconColumn::make('include_media')
|
||||
->label(__('admin.data_exports.fields.include_media'))
|
||||
->boolean(),
|
||||
TextColumn::make('size_bytes')
|
||||
->label(__('admin.data_exports.fields.size'))
|
||||
->formatStateUsing(fn (?int $state) => $state ? Number::fileSize($state) : '—')
|
||||
->toggleable(),
|
||||
TextColumn::make('created_at')
|
||||
->label(__('admin.data_exports.fields.created_at'))
|
||||
->since()
|
||||
->sortable(),
|
||||
TextColumn::make('expires_at')
|
||||
->label(__('admin.data_exports.fields.expires_at'))
|
||||
->since()
|
||||
->toggleable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('scope')
|
||||
->label(__('admin.data_exports.fields.scope'))
|
||||
->options([
|
||||
'tenant' => __('admin.data_exports.scope.tenant'),
|
||||
'event' => __('admin.data_exports.scope.event'),
|
||||
'user' => __('admin.data_exports.scope.user'),
|
||||
]),
|
||||
SelectFilter::make('status')
|
||||
->label(__('admin.data_exports.fields.status'))
|
||||
->options([
|
||||
DataExport::STATUS_PENDING => __('admin.data_exports.status.pending'),
|
||||
DataExport::STATUS_PROCESSING => __('admin.data_exports.status.processing'),
|
||||
DataExport::STATUS_READY => __('admin.data_exports.status.ready'),
|
||||
DataExport::STATUS_FAILED => __('admin.data_exports.status.failed'),
|
||||
]),
|
||||
])
|
||||
->actions([
|
||||
Action::make('download')
|
||||
->label(__('admin.data_exports.actions.download'))
|
||||
->icon('heroicon-o-arrow-down-tray')
|
||||
->url(fn (DataExport $record) => route('superadmin.data-exports.download', $record))
|
||||
->openUrlInNewTab()
|
||||
->visible(fn (DataExport $record): bool => $record->isReady() && ! $record->hasExpired()),
|
||||
])
|
||||
->bulkActions([]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user