Files
breadcrumb-the-shire/modules/audit/pages/admin/api-audit/view(default).phtml
fs 0c351f6aff refactor(audit): extract audit domain into self-contained module
Move the entire audit subsystem (system audit, API audit, import audit,
user lifecycle audit, frontend telemetry) from core into modules/audit/.

Core decoupling via interface-based injection:
- AuditRecorderInterface replaces SystemAuditService in 10+ core services
- UserLifecycleAuditInterface / ImportAuditInterface for specialized flows
- NullAuditRecorder fallback when audit module is disabled
- ApiBootstrap/ApiResponse use null-safe callable resolvers

Module structure (modules/audit/):
- Manifest with routes, permissions, scheduler jobs, authorization policy
- 9 services, 8 repositories, 6 domain enums, 4 job handlers
- 33 page files, 4 JS files, 8 test files, migration scripts, i18n

Core cleanup:
- OperationsAuthorizationPolicy, UiCapabilityMap, PermissionService
  surgically cleaned of audit-specific constants
- Sidebar template cleared of hardcoded audit navigation
- AuditModuleIsolationContractTest ensures no future core→module coupling

All quality gates pass: 1346 tests (19,276 assertions), PHPStan level 5
clean, architecture contracts verified.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 21:12:49 +01:00

194 lines
6.3 KiB
PHTML

<?php
/**
* @var array $auditLog
*/
$auditLog = $auditLog ?? [];
$statusCode = (int) ($auditLog['status_code'] ?? 0);
$statusVariant = 'neutral';
if ($statusCode >= 200 && $statusCode < 300) {
$statusVariant = 'success';
} elseif ($statusCode >= 400 && $statusCode < 500) {
$statusVariant = 'warning';
} elseif ($statusCode >= 500) {
$statusVariant = 'danger';
}
$queryJson = trim((string) ($auditLog['query_json'] ?? ''));
$queryPretty = '-';
if ($queryJson !== '') {
$decoded = json_decode($queryJson, true);
if (is_array($decoded)) {
$pretty = json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$queryPretty = is_string($pretty) ? $pretty : $queryJson;
} else {
$queryPretty = $queryJson;
}
}
$userLabel = trim((string) ($auditLog['user_display_name'] ?? ''));
$userEmail = trim((string) ($auditLog['user_email'] ?? ''));
if ($userLabel === '') {
$userLabel = $userEmail !== '' ? $userEmail : '-';
}
$tenantLabel = trim((string) ($auditLog['tenant_description'] ?? ''));
if ($tenantLabel === '') {
$tenantLabel = '-';
}
$requestId = trim((string) ($auditLog['request_id'] ?? ''));
$method = strtoupper(trim((string) ($auditLog['method'] ?? '')));
$path = trim((string) ($auditLog['path'] ?? ''));
$errorCode = trim((string) ($auditLog['error_code'] ?? ''));
$ip = trim((string) ($auditLog['ip'] ?? ''));
$userAgent = trim((string) ($auditLog['user_agent'] ?? ''));
$durationMs = (int) ($auditLog['duration_ms'] ?? 0);
$tokenId = (int) ($auditLog['api_token_id'] ?? 0);
$tokenTenantId = (int) ($auditLog['token_tenant_id'] ?? 0);
?>
<div class="app-details-container">
<section>
<?php
$breadcrumbs = [
['label' => t('Home'), 'path' => 'admin'],
['label' => t('API audit logs'), 'path' => 'admin/api-audit'],
['label' => t('View')],
];
require templatePath('partials/app-breadcrumb.phtml');
$titlebar = [
'title' => t('View API audit entry'),
'backHref' => 'admin/api-audit',
'backTitle' => t('Back'),
];
require templatePath('partials/app-details-titlebar.phtml');
?>
<div class="app-details-content">
<details open>
<summary><?php e(t('Request details')); ?></summary>
<hr>
<div class="grid">
<div>
<small><?php e(t('Method')); ?></small>
<p><span class="badge" data-variant="neutral"><?php e($method !== '' ? $method : '-'); ?></span></p>
</div>
<div>
<small><?php e(t('Path')); ?></small>
<p><code><?php e($path !== '' ? $path : '-'); ?></code></p>
</div>
</div>
<?php if ($errorCode !== '' || $ip !== ''): ?>
<div class="grid">
<div>
<small><?php e(t('Error code')); ?></small>
<p><?php e($errorCode !== '' ? $errorCode : '-'); ?></p>
</div>
<div>
<small><?php e(t('IP')); ?></small>
<p><?php e($ip !== '' ? $ip : '-'); ?></p>
</div>
</div>
<?php endif; ?>
<?php if ($userAgent !== ''): ?>
<div>
<small><?php e(t('User agent')); ?></small>
<textarea readonly rows="3"><?php e($userAgent); ?></textarea>
</div>
<?php endif; ?>
</details>
<hr>
<details open>
<summary><?php e(t('Scope')); ?></summary>
<hr>
<div class="grid">
<div>
<small><?php e(t('User')); ?></small>
<p>
<?php if (!empty($auditLog['user_uuid'])): ?>
<a href="admin/users/edit/<?php e($auditLog['user_uuid']); ?>"><?php e($userLabel); ?></a>
<?php else: ?>
<?php e($userLabel); ?>
<?php endif; ?>
</p>
</div>
<div>
<small><?php e(t('Tenant')); ?></small>
<p>
<?php if (!empty($auditLog['tenant_uuid'])): ?>
<a href="admin/tenants/edit/<?php e($auditLog['tenant_uuid']); ?>"><?php e($tenantLabel); ?></a>
<?php else: ?>
<?php e($tenantLabel); ?>
<?php endif; ?>
</p>
</div>
</div>
<?php if ($tokenId > 0 || $tokenTenantId > 0): ?>
<div class="grid">
<div>
<small><?php e(t('Token ID')); ?></small>
<p><?php e($tokenId > 0 ? (string) $tokenId : '-'); ?></p>
</div>
<div>
<small><?php e(t('Token tenant')); ?></small>
<p><?php e($tokenTenantId > 0 ? (string) $tokenTenantId : '-'); ?></p>
</div>
</div>
<?php endif; ?>
</details>
<?php if ($queryPretty !== '-'): ?>
<hr>
<details>
<summary><?php e(t('Query')); ?></summary>
<hr>
<textarea readonly rows="12"><?php e($queryPretty); ?></textarea>
</details>
<?php endif; ?>
</div>
</section>
<aside id="app-details-aside-section">
<div class="app-details-aside-section">
<hgroup>
<strong><?php e(t('API audit')); ?></strong>
<p><small><?php e($requestId !== '' ? $requestId : '-'); ?></small></p>
</hgroup>
<hr>
<div class="grid">
<div>
<small><?php e(t('ID')); ?></small>
<p>
<span class="badge" data-variant="neutral" data-copy="true" data-copy-value="<?php e((string) ($auditLog['id'] ?? '')); ?>">
<?php e((string) ($auditLog['id'] ?? '-')); ?>
</span>
</p>
</div>
<div>
<small><?php e(t('Status')); ?></small>
<p><span class="badge" data-variant="<?php e($statusVariant); ?>"><?php e((string) $statusCode); ?></span></p>
</div>
</div>
<div>
<small><?php e(t('Request ID')); ?></small>
<p>
<span class="badge" data-variant="neutral" data-copy="true" data-copy-value="<?php e($requestId); ?>">
<?php e($requestId !== '' ? substr($requestId, 0, 10) : '-'); ?>
</span>
</p>
</div>
<div>
<small><?php e(t('Created')); ?></small>
<p><?php e(dt((string) ($auditLog['created_at'] ?? '')) ?: '-'); ?></p>
</div>
<div>
<small><?php e(t('Duration (ms)')); ?></small>
<p><?php e($durationMs > 0 ? (string) $durationMs : '-'); ?></p>
</div>
</div>
</aside>
</div>