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
122 lines
5.3 KiB
PHP
122 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\PolicyResource\Pages;
|
|
|
|
use App\Filament\Resources\PolicyResource;
|
|
use App\Jobs\CapturePolicySnapshotJob;
|
|
use App\Services\OperationRunService;
|
|
use App\Services\Operations\BulkSelectionIdentity;
|
|
use App\Support\OperationRunLinks;
|
|
use App\Support\OpsUx\OperationUxPresenter;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\ViewRecord;
|
|
use Filament\Support\Enums\Width;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ViewPolicy extends ViewRecord
|
|
{
|
|
protected static string $resource = PolicyResource::class;
|
|
|
|
protected Width|string|null $maxContentWidth = Width::Full;
|
|
|
|
protected function getActions(): array
|
|
{
|
|
return [
|
|
Action::make('capture_snapshot')
|
|
->label('Capture snapshot')
|
|
->requiresConfirmation()
|
|
->modalHeading('Capture snapshot now')
|
|
->modalSubheading('This queues a background job that fetches the latest configuration from Microsoft Graph and stores a new policy version.')
|
|
->form([
|
|
Forms\Components\Checkbox::make('include_assignments')
|
|
->label('Include assignments')
|
|
->default(true)
|
|
->helperText('Captures assignment include/exclude targeting and filters.'),
|
|
Forms\Components\Checkbox::make('include_scope_tags')
|
|
->label('Include scope tags')
|
|
->default(true)
|
|
->helperText('Captures policy scope tag IDs.'),
|
|
])
|
|
->action(function (array $data) {
|
|
$policy = $this->record;
|
|
|
|
$tenant = $policy->tenant;
|
|
$user = auth()->user();
|
|
|
|
if (! $tenant || ! $user) {
|
|
Notification::make()
|
|
->title('Missing tenant or user context.')
|
|
->danger()
|
|
->send();
|
|
|
|
return;
|
|
}
|
|
|
|
/** @var BulkSelectionIdentity $selection */
|
|
$selection = app(BulkSelectionIdentity::class);
|
|
$selectionIdentity = $selection->fromIds([(string) $policy->getKey()]);
|
|
|
|
/** @var OperationRunService $runs */
|
|
$runs = app(OperationRunService::class);
|
|
|
|
$opRun = $runs->enqueueBulkOperation(
|
|
tenant: $tenant,
|
|
type: 'policy.capture_snapshot',
|
|
targetScope: [
|
|
'entra_tenant_id' => (string) ($tenant->tenant_id ?? $tenant->external_id),
|
|
],
|
|
selectionIdentity: $selectionIdentity,
|
|
dispatcher: function ($operationRun) use ($tenant, $policy, $user, $data): void {
|
|
CapturePolicySnapshotJob::dispatch(
|
|
tenantId: (int) $tenant->getKey(),
|
|
userId: (int) $user->getKey(),
|
|
policyId: (int) $policy->getKey(),
|
|
includeAssignments: (bool) ($data['include_assignments'] ?? false),
|
|
includeScopeTags: (bool) ($data['include_scope_tags'] ?? false),
|
|
createdBy: $user->email ? Str::limit($user->email, 255, '') : null,
|
|
operationRun: $operationRun,
|
|
context: [],
|
|
);
|
|
},
|
|
initiator: $user,
|
|
extraContext: [
|
|
'policy_id' => (int) $policy->getKey(),
|
|
'include_assignments' => (bool) ($data['include_assignments'] ?? false),
|
|
'include_scope_tags' => (bool) ($data['include_scope_tags'] ?? false),
|
|
],
|
|
emitQueuedNotification: false,
|
|
);
|
|
|
|
if (! $opRun->wasRecentlyCreated) {
|
|
Notification::make()
|
|
->title('Snapshot already in progress')
|
|
->body('An active run already exists for this policy. Opening run details.')
|
|
->actions([
|
|
\Filament\Actions\Action::make('view_run')
|
|
->label('View run')
|
|
->url(OperationRunLinks::view($opRun, $tenant)),
|
|
])
|
|
->info()
|
|
->send();
|
|
|
|
$this->redirect(OperationRunLinks::view($opRun, $tenant));
|
|
|
|
return;
|
|
}
|
|
OperationUxPresenter::queuedToast('policy.capture_snapshot')
|
|
->actions([
|
|
\Filament\Actions\Action::make('view_run')
|
|
->label('View run')
|
|
->url(OperationRunLinks::view($opRun, $tenant)),
|
|
])
|
|
->send();
|
|
|
|
$this->redirect(OperationRunLinks::view($opRun, $tenant));
|
|
})
|
|
->color('primary'),
|
|
];
|
|
}
|
|
}
|