2026-08-25 09:33:03 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Modules\Core\Privacy\RelationManagers;
|
|
|
|
|
|
2026-09-16 00:24:18 +03:00
|
|
|
use Filament\Actions\ViewAction;
|
|
|
|
|
use Filament\Actions\Action;
|
2026-08-25 09:33:03 +03:00
|
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
|
|
|
use Filament\Tables\Columns\TextColumn;
|
|
|
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
|
|
|
use Filament\Tables\Table;
|
2026-09-16 01:21:22 +03:00
|
|
|
use Modules\Core\Privacy\Enums\ErasureRequestStatus;
|
2026-08-25 09:33:03 +03:00
|
|
|
use Modules\Core\Privacy\Filament\Resources\DataErasureRequestResource;
|
|
|
|
|
use Modules\Core\Privacy\Models\DataErasureRequest;
|
2026-09-16 01:21:22 +03:00
|
|
|
use Modules\Core\Privacy\Services\PrivacyService;
|
2026-08-25 09:33:03 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Lists erasure requests where the record being viewed (Customer or User) is the
|
|
|
|
|
* subject — scoped via the Customer::erasureRequests()/{User}::erasureRequests()
|
|
|
|
|
* morphMany macros registered in CorePlugin. Read-mostly, same as
|
|
|
|
|
* DataErasureRequestResource itself — no create here either, requests are opened
|
|
|
|
|
* via PrivacyService (see CustomerErasureActionsExtension for the Customer-page
|
|
|
|
|
* entry point).
|
|
|
|
|
*/
|
|
|
|
|
class ErasureRequestsRelationManager extends RelationManager
|
|
|
|
|
{
|
|
|
|
|
protected static string $relationship = 'erasureRequests';
|
|
|
|
|
|
|
|
|
|
protected static ?string $title = 'Erasure Requests';
|
|
|
|
|
|
|
|
|
|
public function table(Table $table): Table
|
|
|
|
|
{
|
|
|
|
|
return $table
|
|
|
|
|
->recordTitleAttribute('id')
|
|
|
|
|
->columns([
|
|
|
|
|
TextColumn::make('id')
|
|
|
|
|
->label('#'),
|
|
|
|
|
TextColumn::make('status')
|
|
|
|
|
->badge()
|
|
|
|
|
->formatStateUsing(fn (ErasureRequestStatus $state) => ucfirst($state->value))
|
|
|
|
|
->color(fn (ErasureRequestStatus $state) => match ($state) {
|
|
|
|
|
ErasureRequestStatus::Pending => 'warning',
|
|
|
|
|
ErasureRequestStatus::Cancelled => 'gray',
|
|
|
|
|
ErasureRequestStatus::Completed => 'success',
|
|
|
|
|
}),
|
|
|
|
|
TextColumn::make('requestedBy')
|
|
|
|
|
->label('Requested by')
|
|
|
|
|
->state(fn (DataErasureRequest $record) => DataErasureRequest::displayNameFor($record->requestedBy)),
|
|
|
|
|
TextColumn::make('scheduled_for')
|
|
|
|
|
->label('Scheduled for')
|
|
|
|
|
->dateTime(),
|
|
|
|
|
TextColumn::make('caused_by_request_id')
|
|
|
|
|
->label('Cascade')
|
|
|
|
|
->formatStateUsing(fn (?int $state) => $state ? "from #{$state}" : '—'),
|
|
|
|
|
TextColumn::make('created_at')
|
|
|
|
|
->label('Requested at')
|
|
|
|
|
->dateTime(),
|
|
|
|
|
])
|
|
|
|
|
->defaultSort('created_at', 'desc')
|
|
|
|
|
->filters([
|
|
|
|
|
SelectFilter::make('status')
|
|
|
|
|
->options([
|
|
|
|
|
ErasureRequestStatus::Pending->value => 'Pending',
|
|
|
|
|
ErasureRequestStatus::Cancelled->value => 'Cancelled',
|
|
|
|
|
ErasureRequestStatus::Completed->value => 'Completed',
|
|
|
|
|
]),
|
|
|
|
|
])
|
|
|
|
|
->headerActions([])
|
2026-09-16 00:24:18 +03:00
|
|
|
->recordActions([
|
2026-08-25 09:33:03 +03:00
|
|
|
ViewAction::make()
|
|
|
|
|
->url(fn (DataErasureRequest $record) => DataErasureRequestResource::getUrl('view', ['record' => $record])),
|
|
|
|
|
Action::make('cancel')
|
|
|
|
|
->label('Cancel')
|
|
|
|
|
->icon('heroicon-o-x-circle')
|
|
|
|
|
->color('danger')
|
|
|
|
|
->requiresConfirmation()
|
|
|
|
|
->visible(fn (DataErasureRequest $record) => $record->isPending())
|
|
|
|
|
->action(fn (DataErasureRequest $record, PrivacyService $privacyService) => $privacyService->cancelErasure($record)),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|