## Summary - add the Evidence Snapshot domain with immutable tenant-scoped snapshots, per-dimension items, queued generation, audit actions, badge mappings, and Filament list/detail surfaces - add the workspace evidence overview, capability and policy wiring, Livewire update-path hardening, and review-pack integration through explicit evidence snapshot resolution - add spec 153 artifacts, migrations, factories, and focused Pest coverage for evidence, review-pack reuse, authorization, action-surface regressions, and audit behavior ## Testing - `vendor/bin/sail artisan test --compact --stop-on-failure` - `CI=1 vendor/bin/sail artisan test --compact` - `vendor/bin/sail bin pint --dirty --format agent` ## Notes - branch: `153-evidence-domain-foundation` - commit: `b7dfa279` - spec: `specs/153-evidence-domain-foundation/` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #183
65 lines
2.5 KiB
PHP
65 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Evidence\Sources;
|
|
|
|
use App\Models\Finding;
|
|
use App\Models\Tenant;
|
|
use App\Services\Evidence\Contracts\EvidenceSourceProvider;
|
|
use App\Support\Evidence\EvidenceCompletenessState;
|
|
|
|
final class FindingsSummarySource implements EvidenceSourceProvider
|
|
{
|
|
public function key(): string
|
|
{
|
|
return 'findings_summary';
|
|
}
|
|
|
|
public function collect(Tenant $tenant): array
|
|
{
|
|
$findings = Finding::query()
|
|
->where('tenant_id', (int) $tenant->getKey())
|
|
->orderByDesc('updated_at')
|
|
->get();
|
|
|
|
$latest = $findings->max('updated_at') ?? $findings->max('created_at');
|
|
|
|
$summary = [
|
|
'count' => $findings->count(),
|
|
'open_count' => $findings->filter(fn (Finding $finding): bool => $finding->hasOpenStatus())->count(),
|
|
'severity_counts' => [
|
|
'critical' => $findings->where('severity', Finding::SEVERITY_CRITICAL)->count(),
|
|
'high' => $findings->where('severity', Finding::SEVERITY_HIGH)->count(),
|
|
'medium' => $findings->where('severity', Finding::SEVERITY_MEDIUM)->count(),
|
|
'low' => $findings->where('severity', Finding::SEVERITY_LOW)->count(),
|
|
],
|
|
'entries' => $findings->map(static fn (Finding $finding): array => [
|
|
'id' => (int) $finding->getKey(),
|
|
'finding_type' => (string) $finding->finding_type,
|
|
'severity' => (string) $finding->severity,
|
|
'status' => (string) $finding->status,
|
|
'title' => $finding->title,
|
|
'description' => $finding->description,
|
|
'created_at' => $finding->created_at?->toIso8601String(),
|
|
'updated_at' => $finding->updated_at?->toIso8601String(),
|
|
])->all(),
|
|
];
|
|
|
|
return [
|
|
'dimension_key' => $this->key(),
|
|
'state' => $findings->isEmpty() ? EvidenceCompletenessState::Missing->value : EvidenceCompletenessState::Complete->value,
|
|
'required' => true,
|
|
'source_kind' => 'model_summary',
|
|
'source_record_type' => 'finding',
|
|
'source_record_id' => null,
|
|
'source_fingerprint' => $findings->max('fingerprint'),
|
|
'measured_at' => $latest,
|
|
'freshness_at' => $latest,
|
|
'summary_payload' => $summary,
|
|
'fingerprint_payload' => $summary + ['latest' => $latest?->format(DATE_ATOM)],
|
|
'sort_order' => 10,
|
|
];
|
|
}
|
|
}
|