57 lines
1.6 KiB
PHP
57 lines
1.6 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\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;
|
|
|
|
$policyTypes = $data['scope_jsonb']['policy_types'] ?? [];
|
|
$data['scope_jsonb'] = ['policy_types' => is_array($policyTypes) ? array_values($policyTypes) : []];
|
|
|
|
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' => (string) $record->status,
|
|
]);
|
|
|
|
Notification::make()
|
|
->title('Baseline profile created')
|
|
->success()
|
|
->send();
|
|
}
|
|
}
|