- Implement Spec 116 baseline capture/compare + coverage guard\n- Add UI surfaces and widgets for baseline compare\n- Add tests and research report
92 lines
3.0 KiB
PHP
92 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\BaselineProfileResource\Pages;
|
|
|
|
use App\Filament\Resources\BaselineProfileResource;
|
|
use App\Models\BaselineProfile;
|
|
use App\Support\Audit\AuditActionId;
|
|
use App\Support\Baselines\BaselineProfileStatus;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
|
|
class EditBaselineProfile extends EditRecord
|
|
{
|
|
protected static string $resource = BaselineProfileResource::class;
|
|
|
|
public function getSubHeading(): string
|
|
{
|
|
$record = $this->getRecord();
|
|
$status = $record->status instanceof BaselineProfileStatus
|
|
? $record->status
|
|
: (BaselineProfileStatus::tryFrom((string) $record->status) ?? BaselineProfileStatus::Draft);
|
|
|
|
return $status->label();
|
|
}
|
|
|
|
public function getSubHeadingBadgeColor(): string
|
|
{
|
|
$record = $this->getRecord();
|
|
$status = $record->status instanceof BaselineProfileStatus
|
|
? $record->status
|
|
: (BaselineProfileStatus::tryFrom((string) $record->status) ?? BaselineProfileStatus::Draft);
|
|
|
|
return $status->color();
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected function mutateFormDataBeforeSave(array $data): array
|
|
{
|
|
$record = $this->getRecord();
|
|
$currentStatus = $record->status instanceof BaselineProfileStatus
|
|
? $record->status
|
|
: (BaselineProfileStatus::tryFrom((string) $record->status) ?? BaselineProfileStatus::Draft);
|
|
|
|
if ($currentStatus === BaselineProfileStatus::Archived) {
|
|
unset($data['status']);
|
|
}
|
|
|
|
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 afterSave(): void
|
|
{
|
|
$record = $this->record;
|
|
|
|
if (! $record instanceof BaselineProfile) {
|
|
return;
|
|
}
|
|
|
|
BaselineProfileResource::audit($record, AuditActionId::BaselineProfileUpdated, [
|
|
'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 updated')
|
|
->success()
|
|
->send();
|
|
}
|
|
|
|
protected function getRedirectUrl(): string
|
|
{
|
|
return $this->getResource()::getUrl('view', ['record' => $this->getRecord()]);
|
|
}
|
|
}
|