## Summary - implement Spec 224 findings notifications and escalation v1 on top of the existing alerts and Filament database notification infrastructure - add finding assignment, reopen, due soon, and overdue event handling with direct recipient routing, dedupe, and optional external alert fan-out - extend alert rule and alert delivery surfaces plus add the Spec 224 planning bundle and candidate-list promotion cleanup ## Validation - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Findings/FindingsNotificationEventTest.php tests/Feature/Findings/FindingsNotificationRoutingTest.php` - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Alerts/FindingsAlertRuleIntegrationTest.php tests/Feature/Alerts/SlaDueAlertTest.php tests/Feature/Notifications/FindingNotificationLinkTest.php` ## Filament / Platform Notes - Livewire v4.0+ compliance is preserved - provider registration remains unchanged in `apps/platform/bootstrap/providers.php` - no globally searchable resource behavior changed in this feature - no new destructive action was introduced - asset strategy is unchanged and the existing `cd apps/platform && php artisan filament:assets` deploy step remains sufficient ## Manual Smoke Note - integrated-browser smoke testing confirmed the new alert rule event options, notification drawer entries, alert delivery history row, and tenant finding detail route on the active Sail host - local notification deep links currently resolve from `APP_URL`, so a local `localhost` vs `127.0.0.1:8081` host mismatch can break the browser session if the app is opened on a different host/port combination Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #261
94 lines
2.8 KiB
PHP
94 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Notifications\Findings;
|
|
|
|
use App\Filament\Resources\FindingResource;
|
|
use App\Models\Finding;
|
|
use App\Models\Tenant;
|
|
use Filament\Actions\Action;
|
|
use Filament\Notifications\Notification as FilamentNotification;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
final class FindingEventNotification extends Notification
|
|
{
|
|
use Queueable;
|
|
|
|
/**
|
|
* @param array<string, mixed> $event
|
|
*/
|
|
public function __construct(
|
|
private readonly Finding $finding,
|
|
private readonly Tenant $tenant,
|
|
private readonly array $event,
|
|
) {}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['database'];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toDatabase(object $notifiable): array
|
|
{
|
|
$message = FilamentNotification::make()
|
|
->title($this->title())
|
|
->body($this->body())
|
|
->actions([
|
|
Action::make('open_finding')
|
|
->label('Open finding')
|
|
->url(FindingResource::getUrl(
|
|
'view',
|
|
['record' => $this->finding],
|
|
panel: 'tenant',
|
|
tenant: $this->tenant,
|
|
)),
|
|
])
|
|
->getDatabaseMessage();
|
|
|
|
$message['finding_event'] = [
|
|
'event_type' => (string) ($this->event['event_type'] ?? ''),
|
|
'finding_id' => (int) $this->finding->getKey(),
|
|
'recipient_reason' => data_get($this->event, 'metadata.recipient_reason'),
|
|
'fingerprint_key' => (string) ($this->event['fingerprint_key'] ?? ''),
|
|
'due_cycle_key' => $this->event['due_cycle_key'] ?? null,
|
|
'tenant_name' => $this->tenant->getFilamentName(),
|
|
'severity' => (string) ($this->event['severity'] ?? ''),
|
|
];
|
|
|
|
return $message;
|
|
}
|
|
|
|
private function title(): string
|
|
{
|
|
$title = trim((string) ($this->event['title'] ?? 'Finding update'));
|
|
|
|
return $title !== '' ? $title : 'Finding update';
|
|
}
|
|
|
|
private function body(): string
|
|
{
|
|
$body = trim((string) ($this->event['body'] ?? 'A finding needs follow-up.'));
|
|
$recipientReason = $this->recipientReasonCopy((string) data_get($this->event, 'metadata.recipient_reason', ''));
|
|
|
|
return trim($body.' '.$recipientReason);
|
|
}
|
|
|
|
private function recipientReasonCopy(string $reason): string
|
|
{
|
|
return match ($reason) {
|
|
'new_assignee' => 'You are the new assignee.',
|
|
'current_assignee' => 'You are the current assignee.',
|
|
'current_owner' => 'You are the accountable owner.',
|
|
default => '',
|
|
};
|
|
}
|
|
}
|