fix(filament): hide restore rerun when archived

This commit is contained in:
Ahmed Darrazi 2026-01-19 22:11:45 +01:00
parent b807a7bb96
commit 6737ba7d85
2 changed files with 36 additions and 4 deletions

View File

@ -741,7 +741,8 @@ public static function table(Table $table): Table
->visible(function (RestoreRun $record): bool {
$backupSet = $record->backupSet;
return $record->isDeletable()
return ! $record->trashed()
&& $record->isDeletable()
&& $backupSet !== null
&& ! $backupSet->trashed();
})
@ -754,10 +755,10 @@ public static function table(Table $table): Table
$tenant = $record->tenant;
$backupSet = $record->backupSet;
if (! $tenant || ! $backupSet || $backupSet->trashed()) {
if ($record->trashed() || ! $tenant || ! $backupSet || $backupSet->trashed()) {
Notification::make()
->title('Restore run cannot be rerun')
->body('Backup set is archived or unavailable.')
->body('Restore run or backup set is archived or unavailable.')
->warning()
->send();
@ -1019,7 +1020,6 @@ public static function table(Table $table): Table
return [
Forms\Components\TextInput::make('confirmation')
->label('Type DELETE to confirm')
->required()
->in(['DELETE'])
->validationMessages([
'in' => 'Please type DELETE to confirm.',

View File

@ -7,6 +7,7 @@
use App\Models\Tenant;
use App\Models\User;
use Filament\Facades\Filament;
use Filament\Tables\Filters\TrashedFilter;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
@ -71,3 +72,34 @@
expect($newRun->is_dry_run)->toBeTrue();
expect($newRun->requested_by)->toBe('tester@example.com');
});
test('rerun action is hidden for archived restore runs', function () {
$tenant = Tenant::factory()->create();
$backupSet = BackupSet::factory()->for($tenant)->create([
'status' => 'completed',
'item_count' => 0,
]);
$run = RestoreRun::create([
'tenant_id' => $tenant->id,
'backup_set_id' => $backupSet->id,
'status' => 'completed',
'is_dry_run' => true,
'requested_by' => 'tester@example.com',
]);
$run->delete();
$user = User::factory()->create();
$user->tenants()->syncWithoutDetaching([
$tenant->getKey() => ['role' => 'owner'],
]);
Filament::setTenant($tenant, true);
Livewire::actingAs($user)
->test(ListRestoreRuns::class)
->filterTable(TrashedFilter::class, false)
->assertTableActionHidden('rerun', $run);
});