Files
breadcrumb-the-shire/modules/audit/pages/admin/system-audit/data().php

46 lines
1.8 KiB
PHP
Raw Normal View History

2026-03-04 15:56:58 +01:00
<?php
use MintyPHP\Module\Audit\AuditAuthorizationPolicy;
use MintyPHP\Module\Audit\Domain\SystemAuditChannel;
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
use MintyPHP\Module\Audit\Service\SystemAuditService;
2026-03-04 15:56:58 +01:00
use MintyPHP\Support\Guard;
Guard::requireLogin();
Guard::requireAbilityOrForbidden(AuditAuthorizationPolicy::ABILITY_SYSTEM_AUDIT_VIEW);
2026-03-04 15:56:58 +01:00
gridRequireGetRequest();
$filters = gridParseFiltersFromSchemaFile(__DIR__ . '/filter-schema.php');
$result = app(SystemAuditService::class)->listPaged($filters);
$rows = [];
foreach ((array) ($result['rows'] ?? []) as $row) {
$outcome = SystemAuditOutcome::normalizeOr((string) ($row['outcome'] ?? ''), SystemAuditOutcome::Success);
$channel = SystemAuditChannel::normalizeOr((string) ($row['channel'] ?? ''), SystemAuditChannel::Web);
$actorLabel = trim((string) ($row['actor_user_display_name'] ?? ''));
if ($actorLabel === '') {
$actorLabel = trim((string) ($row['actor_user_email'] ?? ''));
}
$rows[] = [
'id' => (int) ($row['id'] ?? 0),
'created_at' => dt((string) ($row['created_at'] ?? '')),
'event_type' => (string) ($row['event_type'] ?? ''),
'outcome' => $outcome->value,
'outcome_badge' => $outcome->badgeVariant(),
'outcome_label' => t($outcome->labelToken()),
'channel' => strtoupper($channel->labelToken()),
'actor_user_id' => (int) ($row['actor_user_id'] ?? 0),
'actor_user_uuid' => (string) ($row['actor_user_uuid'] ?? ''),
'actor_user_label' => $actorLabel !== '' ? $actorLabel : '-',
'target_type' => (string) ($row['target_type'] ?? ''),
'target_uuid' => (string) ($row['target_uuid'] ?? ''),
'request_id' => (string) ($row['request_id'] ?? ''),
'error_code' => (string) ($row['error_code'] ?? ''),
];
}
gridJsonDataResult($rows, (int) ($result['total'] ?? 0));