Kurzbeschreibung Versteckt die Rerun-Row-Action für archivierte (soft-deleted) RestoreRuns und verhindert damit fehlerhafte Neu-Starts aus dem Archiv; ergänzt einen Regressionstest. Änderungen Code: RestoreRunResource.php — Sichtbarkeit der rerun-Action geprüft auf ! $record->trashed() und defensive Abbruchprüfung im Action-Handler. Tests: RestoreRunRerunTest.php — neuer Test rerun action is hidden for archived restore runs. Warum Archivierte RestoreRuns durften nicht neu gestartet werden; UI zeigte trotzdem die Option. Das führte zu verwirrendem Verhalten und möglichen Fehlern beim Enqueueing. Verifikation / QA Unit/Feature: ./vendor/bin/sail artisan test tests/Feature/RestoreRunRerunTest.php Stil/format: ./vendor/bin/pint --dirty Manuell (UI): Als Tenant-Admin Filament → Restore Runs öffnen. Filter Archived aktivieren (oder Trashed filter auswählen). Sicherstellen, dass für archivierte Einträge die Rerun-Action nicht sichtbar ist. Auf einem aktiven (nicht-archivierten) Run prüfen, dass Rerun sichtbar bleibt und wie erwartet eine neue RestoreRun erzeugt. Wichtige Hinweise Kein DB-Migration required. Diese PR enthält nur den UI-/Filament-Fix; die zuvor gemachten operative Fixes für Queue/adapter-Reconciliation bleiben ebenfalls auf dem Branch (z. B. frühere commits während der Debugging-Session). T055 (Schema squash) wurde bewusst zurückgestellt und ist nicht Teil dieses PRs. Merge-Checklist Tests lokal laufen (RestoreRunRerunTest grünt) Pint läuft ohne ungepatchte Fehler Branch gepusht: 056-remove-legacy-bulkops (PR-URL: https://git.cloudarix.de/ahmido/TenantAtlas/compare/dev...056-remove-legacy-bulkops) Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local> Reviewed-on: #65
144 lines
4.9 KiB
PHP
144 lines
4.9 KiB
PHP
<?php
|
|
|
|
use App\Models\AuditLog;
|
|
use App\Models\BackupItem;
|
|
use App\Models\BackupSchedule;
|
|
use App\Models\BackupScheduleRun;
|
|
use App\Models\BackupSet;
|
|
use App\Models\OperationRun;
|
|
use App\Models\Policy;
|
|
use App\Models\PolicyVersion;
|
|
use App\Models\RestoreRun;
|
|
use App\Models\SettingsCatalogCategory;
|
|
use App\Models\SettingsCatalogDefinition;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('purges non-persistent tenant data without touching persistent catalog data', function () {
|
|
$tenantA = Tenant::factory()->create(['name' => 'Tenant A']);
|
|
$tenantB = Tenant::factory()->create(['name' => 'Tenant B']);
|
|
|
|
SettingsCatalogCategory::create([
|
|
'category_id' => 'cat-1',
|
|
'display_name' => 'Account Management',
|
|
'description' => null,
|
|
]);
|
|
|
|
SettingsCatalogDefinition::create([
|
|
'definition_id' => 'def-1',
|
|
'display_name' => 'Deletion Policy',
|
|
'description' => null,
|
|
'help_text' => null,
|
|
'category_id' => 'cat-1',
|
|
'ux_behavior' => null,
|
|
'raw' => [],
|
|
]);
|
|
|
|
$user = User::factory()->create();
|
|
|
|
$policyA = Policy::factory()->create(['tenant_id' => $tenantA->id]);
|
|
$policyB = Policy::factory()->create(['tenant_id' => $tenantB->id]);
|
|
|
|
PolicyVersion::factory()->create([
|
|
'tenant_id' => $tenantA->id,
|
|
'policy_id' => $policyA->id,
|
|
'version_number' => 1,
|
|
]);
|
|
|
|
PolicyVersion::factory()->create([
|
|
'tenant_id' => $tenantB->id,
|
|
'policy_id' => $policyB->id,
|
|
'version_number' => 1,
|
|
]);
|
|
|
|
$backupSetA = BackupSet::factory()->create(['tenant_id' => $tenantA->id]);
|
|
BackupItem::factory()->create([
|
|
'tenant_id' => $tenantA->id,
|
|
'backup_set_id' => $backupSetA->id,
|
|
'policy_id' => $policyA->id,
|
|
]);
|
|
|
|
RestoreRun::factory()->create([
|
|
'tenant_id' => $tenantA->id,
|
|
'backup_set_id' => $backupSetA->id,
|
|
]);
|
|
|
|
AuditLog::create([
|
|
'tenant_id' => $tenantA->id,
|
|
'actor_id' => null,
|
|
'actor_email' => null,
|
|
'actor_name' => null,
|
|
'action' => 'test.action',
|
|
'resource_type' => null,
|
|
'resource_id' => null,
|
|
'status' => 'success',
|
|
'metadata' => null,
|
|
'recorded_at' => now(),
|
|
]);
|
|
|
|
OperationRun::factory()->create([
|
|
'tenant_id' => $tenantA->id,
|
|
'user_id' => $user->id,
|
|
'status' => 'completed',
|
|
]);
|
|
|
|
$scheduleA = BackupSchedule::create([
|
|
'tenant_id' => $tenantA->id,
|
|
'name' => 'Schedule A',
|
|
'is_enabled' => true,
|
|
'timezone' => 'UTC',
|
|
'frequency' => 'daily',
|
|
'time_of_day' => '10:00:00',
|
|
'days_of_week' => null,
|
|
'policy_types' => ['deviceConfiguration'],
|
|
'include_foundations' => true,
|
|
'retention_keep_last' => 30,
|
|
'last_run_at' => null,
|
|
'last_run_status' => null,
|
|
'next_run_at' => now()->addHour(),
|
|
]);
|
|
|
|
BackupScheduleRun::create([
|
|
'backup_schedule_id' => $scheduleA->id,
|
|
'tenant_id' => $tenantA->id,
|
|
'scheduled_for' => now()->startOfMinute(),
|
|
'started_at' => null,
|
|
'finished_at' => null,
|
|
'status' => BackupScheduleRun::STATUS_SUCCESS,
|
|
'summary' => null,
|
|
'error_code' => null,
|
|
'error_message' => null,
|
|
'backup_set_id' => $backupSetA->id,
|
|
]);
|
|
|
|
expect(Policy::query()->where('tenant_id', $tenantA->id)->count())->toBeGreaterThan(0);
|
|
expect(BackupSet::withTrashed()->where('tenant_id', $tenantA->id)->count())->toBeGreaterThan(0);
|
|
expect(BackupScheduleRun::query()->where('tenant_id', $tenantA->id)->count())->toBeGreaterThan(0);
|
|
|
|
$this->artisan('tenantpilot:purge-nonpersistent', [
|
|
'tenant' => $tenantA->id,
|
|
'--force' => true,
|
|
'--no-interaction' => true,
|
|
])->assertSuccessful();
|
|
|
|
expect(Policy::query()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(PolicyVersion::withTrashed()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(BackupItem::withTrashed()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(BackupSet::withTrashed()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(RestoreRun::withTrashed()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(AuditLog::query()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(OperationRun::query()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(BackupScheduleRun::query()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
|
|
expect(BackupSchedule::query()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
|
|
expect(Policy::query()->where('tenant_id', $tenantB->id)->count())->toBe(1);
|
|
expect(PolicyVersion::withTrashed()->where('tenant_id', $tenantB->id)->count())->toBe(1);
|
|
|
|
expect(SettingsCatalogCategory::query()->count())->toBe(1);
|
|
expect(SettingsCatalogDefinition::query()->count())->toBe(1);
|
|
});
|