Implements Spec 116 baseline drift engine v1 (meta fidelity) with coverage guard, stable finding identity, and Filament UI surfaces. Highlights - Baseline capture/compare jobs and supporting services (meta contract hashing via InventoryMetaContract + DriftHasher) - Coverage proof parsing + compare partial outcome behavior - Filament pages/resources/widgets for baseline compare + drift landing improvements - Pest tests for capture/compare/coverage guard and UI start surfaces - Research report: docs/research/golden-master-baseline-drift-deep-analysis.md Validation - `vendor/bin/sail bin pint --dirty` - `vendor/bin/sail artisan test --compact --filter="Baseline"` Notes - No destructive user actions added; compare/capture remain queued jobs. - Provider registration unchanged (Laravel 11+/12 uses bootstrap/providers.php for panel providers; not touched here). Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #141
66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\BaselineProfileResource\Pages;
|
|
|
|
use App\Filament\Resources\BaselineProfileResource;
|
|
use App\Models\BaselineProfile;
|
|
use App\Models\User;
|
|
use App\Support\Audit\AuditActionId;
|
|
use App\Support\Baselines\BaselineProfileStatus;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
|
|
class CreateBaselineProfile extends CreateRecord
|
|
{
|
|
protected static string $resource = BaselineProfileResource::class;
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected function mutateFormDataBeforeCreate(array $data): array
|
|
{
|
|
$workspaceId = app(WorkspaceContext::class)->currentWorkspaceId(request());
|
|
$data['workspace_id'] = (int) $workspaceId;
|
|
|
|
$user = auth()->user();
|
|
$data['created_by_user_id'] = $user instanceof User ? $user->getKey() : null;
|
|
|
|
if (isset($data['scope_jsonb'])) {
|
|
$policyTypes = $data['scope_jsonb']['policy_types'] ?? [];
|
|
$foundationTypes = $data['scope_jsonb']['foundation_types'] ?? [];
|
|
$data['scope_jsonb'] = [
|
|
'policy_types' => is_array($policyTypes) ? array_values(array_filter($policyTypes, 'is_string')) : [],
|
|
'foundation_types' => is_array($foundationTypes) ? array_values(array_filter($foundationTypes, 'is_string')) : [],
|
|
];
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function afterCreate(): void
|
|
{
|
|
$record = $this->record;
|
|
|
|
if (! $record instanceof BaselineProfile) {
|
|
return;
|
|
}
|
|
|
|
BaselineProfileResource::audit($record, AuditActionId::BaselineProfileCreated, [
|
|
'baseline_profile_id' => (int) $record->getKey(),
|
|
'name' => (string) $record->name,
|
|
'status' => $record->status instanceof BaselineProfileStatus
|
|
? $record->status->value
|
|
: (string) $record->status,
|
|
]);
|
|
|
|
Notification::make()
|
|
->title('Baseline profile created')
|
|
->success()
|
|
->send();
|
|
}
|
|
}
|