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>
This commit is contained in:
45
modules/audit/pages/admin/system-audit/data().php
Normal file
45
modules/audit/pages/admin/system-audit/data().php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Module\Audit\AuditAuthorizationPolicy;
|
||||
use MintyPHP\Module\Audit\Domain\SystemAuditChannel;
|
||||
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
|
||||
use MintyPHP\Module\Audit\Service\SystemAuditService;
|
||||
use MintyPHP\Support\Guard;
|
||||
|
||||
Guard::requireLogin();
|
||||
Guard::requireAbilityOrForbidden(AuditAuthorizationPolicy::ABILITY_SYSTEM_AUDIT_VIEW);
|
||||
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));
|
||||
121
modules/audit/pages/admin/system-audit/filter-schema.php
Normal file
121
modules/audit/pages/admin/system-audit/filter-schema.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Module\Audit\Domain\SystemAuditChannel;
|
||||
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
|
||||
|
||||
$outcomeItems = array_map(
|
||||
static fn (SystemAuditOutcome $outcome): array => [
|
||||
'id' => $outcome->value,
|
||||
'description' => $outcome->labelToken(),
|
||||
],
|
||||
SystemAuditOutcome::cases()
|
||||
);
|
||||
$channelItems = array_map(
|
||||
static fn (SystemAuditChannel $channel): array => [
|
||||
'id' => $channel->value,
|
||||
'description' => $channel->labelToken(),
|
||||
'translate' => false,
|
||||
],
|
||||
SystemAuditChannel::cases()
|
||||
);
|
||||
|
||||
return gridFilterSchema([
|
||||
'query' => [
|
||||
'limit' => ['type' => 'int', 'default' => 20, 'min' => 1, 'max' => 200],
|
||||
'offset' => ['type' => 'int', 'default' => 0, 'min' => 0],
|
||||
'search' => ['type' => 'string'],
|
||||
'event_types' => [
|
||||
'type' => 'csv_strings',
|
||||
'max' => 200,
|
||||
'sanitizer' => static function (string $value): string {
|
||||
$value = strtolower(trim($value));
|
||||
if ($value === '' || strlen($value) > 64) {
|
||||
return '';
|
||||
}
|
||||
return preg_match('/^[a-z0-9._-]+$/', $value) === 1 ? $value : '';
|
||||
},
|
||||
],
|
||||
'outcome' => ['type' => 'enum', 'allowed' => SystemAuditOutcome::values(), 'default' => '', 'lowercase' => true],
|
||||
'channel' => ['type' => 'enum', 'allowed' => SystemAuditChannel::values(), 'default' => '', 'lowercase' => true],
|
||||
'created_from' => ['type' => 'date'],
|
||||
'created_to' => ['type' => 'date'],
|
||||
'actor_user_ids' => ['type' => 'csv_ids', 'max' => 200],
|
||||
'target_type' => ['type' => 'string'],
|
||||
'request_id' => ['type' => 'string'],
|
||||
'order' => ['type' => 'order', 'allowed' => ['id', 'created_at', 'event_type', 'outcome', 'channel', 'actor_user_id'], 'default' => 'created_at'],
|
||||
'dir' => ['type' => 'dir', 'default' => 'desc'],
|
||||
],
|
||||
'toolbar' => [
|
||||
[
|
||||
'key' => 'search',
|
||||
'type' => 'text',
|
||||
'label' => 'Search',
|
||||
'placeholder' => 'Search...',
|
||||
'input_id' => 'system-audit-search',
|
||||
'search' => true,
|
||||
'query' => ['type' => 'string'],
|
||||
],
|
||||
[
|
||||
'key' => 'outcome',
|
||||
'type' => 'select',
|
||||
'label' => 'Status',
|
||||
'input_id' => 'system-audit-outcome-filter',
|
||||
'default' => '',
|
||||
'allowed' => [
|
||||
['id' => '', 'description' => 'All outcomes'],
|
||||
...$outcomeItems,
|
||||
],
|
||||
],
|
||||
[
|
||||
'key' => 'channel',
|
||||
'type' => 'select',
|
||||
'label' => 'Channel',
|
||||
'input_id' => 'system-audit-channel-filter',
|
||||
'default' => '',
|
||||
'allowed' => [
|
||||
['id' => '', 'description' => 'All channels'],
|
||||
...$channelItems,
|
||||
],
|
||||
],
|
||||
[
|
||||
'key' => 'event_types',
|
||||
'type' => 'multi_csv',
|
||||
'label' => 'Event type',
|
||||
'placeholder' => 'Select event types',
|
||||
'input_id' => 'system-audit-event-types-filter',
|
||||
'options_key' => 'event_type_items',
|
||||
'default' => [],
|
||||
'query' => ['type' => 'csv_strings', 'max' => 200, 'return' => 'array'],
|
||||
],
|
||||
[
|
||||
'key' => 'created_from',
|
||||
'type' => 'date',
|
||||
'label' => 'Created from',
|
||||
'input_id' => 'system-audit-created-from',
|
||||
],
|
||||
[
|
||||
'key' => 'created_to',
|
||||
'type' => 'date',
|
||||
'label' => 'Created to',
|
||||
'input_id' => 'system-audit-created-to',
|
||||
],
|
||||
[
|
||||
'key' => 'actor_user_ids',
|
||||
'type' => 'multi_csv',
|
||||
'label' => 'Actor',
|
||||
'placeholder' => 'Select actor users',
|
||||
'input_id' => 'system-audit-actor-users-filter',
|
||||
'options_key' => 'actor_user_items',
|
||||
'default' => [],
|
||||
'query' => ['type' => 'csv_ids', 'max' => 200, 'return' => 'array'],
|
||||
],
|
||||
[
|
||||
'key' => 'request_id',
|
||||
'type' => 'text',
|
||||
'label' => 'Request ID',
|
||||
'input_id' => 'system-audit-request-id',
|
||||
'normalize' => 'trim_lower',
|
||||
'event' => 'input',
|
||||
],
|
||||
],
|
||||
]);
|
||||
15
modules/audit/pages/admin/system-audit/index($slug).php
Normal file
15
modules/audit/pages/admin/system-audit/index($slug).php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Http\Request;
|
||||
use MintyPHP\Router;
|
||||
use MintyPHP\Support\Guard;
|
||||
|
||||
Guard::requireLogin();
|
||||
|
||||
$slug = trim((string) ($slug ?? ''));
|
||||
if ($slug === '') {
|
||||
require __DIR__ . '/index().php';
|
||||
return;
|
||||
}
|
||||
|
||||
Router::redirect('error/not_found?url=' . urlencode(Request::pathWithQuery()));
|
||||
170
modules/audit/pages/admin/system-audit/index().php
Normal file
170
modules/audit/pages/admin/system-audit/index().php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Buffer;
|
||||
use MintyPHP\Http\SessionStoreInterface;
|
||||
use MintyPHP\Module\Audit\AuditAuthorizationPolicy;
|
||||
use MintyPHP\Module\Audit\Service\SystemAuditService;
|
||||
use MintyPHP\Service\Access\SettingsAuthorizationPolicy;
|
||||
use MintyPHP\Service\Access\UiAccessService;
|
||||
use MintyPHP\Support\Guard;
|
||||
|
||||
$session = app(SessionStoreInterface::class)->all();
|
||||
Guard::requireLogin();
|
||||
Guard::requireAbility(AuditAuthorizationPolicy::ABILITY_SYSTEM_AUDIT_VIEW);
|
||||
|
||||
$viewAuth['page'] = app(UiAccessService::class)->pageCapabilities(
|
||||
(int) ($session['user']['id'] ?? 0),
|
||||
['can_purge_system_audit' => AuditAuthorizationPolicy::ABILITY_SYSTEM_AUDIT_PURGE]
|
||||
);
|
||||
|
||||
Buffer::set('title', t('System audit logs'));
|
||||
Buffer::set('grid_lang', json_encode(gridLang(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
|
||||
$filterSchema = require __DIR__ . '/filter-schema.php';
|
||||
$filterState = gridParseFilters(requestInput()->queryAll(), [
|
||||
...gridSchemaQuery($filterSchema),
|
||||
'event_types' => [
|
||||
'type' => 'csv_strings',
|
||||
'max' => 200,
|
||||
'return' => 'array',
|
||||
'sanitizer' => static function (string $value): string {
|
||||
$value = strtolower(trim($value));
|
||||
if ($value === '' || strlen($value) > 64) {
|
||||
return '';
|
||||
}
|
||||
return preg_match('/^[a-z0-9._-]+$/', $value) === 1 ? $value : '';
|
||||
},
|
||||
],
|
||||
'actor_user_ids' => ['type' => 'csv_ids', 'max' => 200, 'return' => 'array'],
|
||||
]);
|
||||
$filterOptions = app(SystemAuditService::class)->filterOptions(200);
|
||||
|
||||
$activeEventTypes = is_array($filterState['event_types'] ?? null) ? $filterState['event_types'] : [];
|
||||
$activeActorUserIds = array_map('strval', is_array($filterState['actor_user_ids'] ?? null) ? $filterState['actor_user_ids'] : []);
|
||||
|
||||
$eventTypeItems = [];
|
||||
foreach ((array) ($filterOptions['event_types'] ?? []) as $eventType) {
|
||||
$eventType = strtolower(trim((string) $eventType));
|
||||
if ($eventType === '') {
|
||||
continue;
|
||||
}
|
||||
$eventTypeItems[$eventType] = [
|
||||
'id' => $eventType,
|
||||
'description' => $eventType,
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($activeEventTypes as $eventType) {
|
||||
if (!isset($eventTypeItems[$eventType])) {
|
||||
$eventTypeItems[$eventType] = [
|
||||
'id' => $eventType,
|
||||
'description' => $eventType,
|
||||
];
|
||||
}
|
||||
}
|
||||
$eventTypeItems = array_values($eventTypeItems);
|
||||
|
||||
$actorUserItems = [];
|
||||
foreach ((array) ($filterOptions['actors'] ?? []) as $actorOption) {
|
||||
if (!is_array($actorOption)) {
|
||||
continue;
|
||||
}
|
||||
$actorId = (int) ($actorOption['id'] ?? 0);
|
||||
if ($actorId <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$actorDisplayName = trim((string) ($actorOption['display_name'] ?? ''));
|
||||
$actorEmail = trim((string) ($actorOption['email'] ?? ''));
|
||||
$actorExists = (bool) ($actorOption['exists'] ?? false);
|
||||
|
||||
$label = $actorDisplayName !== '' ? $actorDisplayName : $actorEmail;
|
||||
if ($label === '') {
|
||||
$label = $actorExists
|
||||
? sprintf(t('User #%d'), $actorId)
|
||||
: sprintf(t('User #%d (deleted)'), $actorId);
|
||||
}
|
||||
|
||||
$id = (string) $actorId;
|
||||
$actorUserItems[$id] = [
|
||||
'id' => $id,
|
||||
'description' => $label,
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($activeActorUserIds as $actorId) {
|
||||
if (!isset($actorUserItems[$actorId])) {
|
||||
$actorUserItems[$actorId] = [
|
||||
'id' => $actorId,
|
||||
'description' => sprintf(t('User #%d (deleted)'), (int) $actorId),
|
||||
];
|
||||
}
|
||||
}
|
||||
$actorUserItems = array_values($actorUserItems);
|
||||
|
||||
$toolbarFilterState = [
|
||||
'search' => (string) ($filterState['search'] ?? ''),
|
||||
'event_types' => $activeEventTypes,
|
||||
'outcome' => (string) ($filterState['outcome'] ?? ''),
|
||||
'channel' => (string) ($filterState['channel'] ?? ''),
|
||||
'created_from' => (string) ($filterState['created_from'] ?? ''),
|
||||
'created_to' => (string) ($filterState['created_to'] ?? ''),
|
||||
'actor_user_ids' => $activeActorUserIds,
|
||||
'request_id' => (string) ($filterState['request_id'] ?? ''),
|
||||
];
|
||||
$toolbarOptionSets = [
|
||||
'event_type_items' => $eventTypeItems,
|
||||
'actor_user_items' => $actorUserItems,
|
||||
];
|
||||
$listFilterContext = gridBuildListFilterContext($filterSchema, [
|
||||
'filter_state' => $filterState,
|
||||
'search_keys' => ['search'],
|
||||
'toolbar_state_overrides' => $toolbarFilterState,
|
||||
'toolbar_option_sets' => $toolbarOptionSets,
|
||||
]);
|
||||
$toolbarFilterSchema = $listFilterContext['toolbarFilterSchema'];
|
||||
$toolbarFilterState = $listFilterContext['toolbarFilterState'];
|
||||
$searchToolbarFilterSchema = $listFilterContext['searchToolbarFilterSchema'];
|
||||
$drawerToolbarFilterSchema = $listFilterContext['drawerToolbarFilterSchema'];
|
||||
$schemaByKey = $listFilterContext['schemaByKey'];
|
||||
$toolbarOptionSets = $listFilterContext['toolbarOptionSets'];
|
||||
$filterChipMeta = [
|
||||
'search' => [
|
||||
'label' => t('Search'),
|
||||
'type' => 'text',
|
||||
],
|
||||
'outcome' => [
|
||||
'label' => t('Status'),
|
||||
'type' => 'select',
|
||||
'default' => (string) (($schemaByKey['outcome']['default'] ?? '')),
|
||||
'options' => gridOptionMapFromAllowed((array) ($schemaByKey['outcome'] ?? [])),
|
||||
],
|
||||
'channel' => [
|
||||
'label' => t('Channel'),
|
||||
'type' => 'select',
|
||||
'default' => (string) (($schemaByKey['channel']['default'] ?? '')),
|
||||
'options' => gridOptionMapFromAllowed((array) ($schemaByKey['channel'] ?? [])),
|
||||
],
|
||||
'event_types' => [
|
||||
'label' => t('Event type'),
|
||||
'type' => 'multi_csv',
|
||||
'options' => gridOptionMapFromItems($eventTypeItems),
|
||||
],
|
||||
'actor_user_ids' => [
|
||||
'label' => t('Actor'),
|
||||
'type' => 'multi_csv',
|
||||
'options' => gridOptionMapFromItems($actorUserItems),
|
||||
],
|
||||
'request_id' => [
|
||||
'label' => t('Request ID'),
|
||||
'type' => 'text',
|
||||
],
|
||||
'created_range' => [
|
||||
'label' => t('Created'),
|
||||
'type' => 'date_range',
|
||||
'from_param' => 'created_from',
|
||||
'to_param' => 'created_to',
|
||||
],
|
||||
];
|
||||
$clientFilterSchema = $listFilterContext['clientFilterSchema'];
|
||||
$searchConfig = $listFilterContext['searchConfig'];
|
||||
69
modules/audit/pages/admin/system-audit/index(default).phtml
Normal file
69
modules/audit/pages/admin/system-audit/index(default).phtml
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
$pageAuth = is_array($viewAuth['page'] ?? null) ? $viewAuth['page'] : [];
|
||||
$canPurgeSystemAudit = (bool) ($pageAuth['can_purge_system_audit'] ?? false);
|
||||
$toolbarFilterSchema = is_array($toolbarFilterSchema ?? null) ? $toolbarFilterSchema : [];
|
||||
$searchToolbarFilterSchema = is_array($searchToolbarFilterSchema ?? null) ? $searchToolbarFilterSchema : [];
|
||||
$drawerToolbarFilterSchema = is_array($drawerToolbarFilterSchema ?? null) ? $drawerToolbarFilterSchema : [];
|
||||
$toolbarFilterState = is_array($toolbarFilterState ?? null) ? $toolbarFilterState : [];
|
||||
$toolbarOptionSets = is_array($toolbarOptionSets ?? null) ? $toolbarOptionSets : [];
|
||||
$filterChipMeta = is_array($filterChipMeta ?? null) ? $filterChipMeta : [];
|
||||
$clientFilterSchema = is_array($clientFilterSchema ?? null) ? $clientFilterSchema : [];
|
||||
$searchConfig = is_array($searchConfig ?? null) ? $searchConfig : null;
|
||||
|
||||
?>
|
||||
<?php
|
||||
$breadcrumbs = [
|
||||
['label' => t('Home'), 'path' => 'admin'],
|
||||
['label' => t('System audit logs')],
|
||||
];
|
||||
require templatePath('partials/app-breadcrumb.phtml');
|
||||
?>
|
||||
<?php
|
||||
$listTitle = t('System audit logs');
|
||||
ob_start();
|
||||
?>
|
||||
<?php
|
||||
$listPurgeEnabled = $canPurgeSystemAudit;
|
||||
$listPurgeFormId = 'system-audit-purge-form';
|
||||
$listPurgeAction = 'admin/system-audit/purge';
|
||||
$listPurgeConfirmMessage = t('Purge expired system audit entries?');
|
||||
$listPurgeButtonLabel = t('Purge system audit logs');
|
||||
require templatePath('partials/app-list-purge-action.phtml');
|
||||
?>
|
||||
<?php
|
||||
$listTitleActionsHtml = ob_get_clean();
|
||||
require templatePath('partials/app-list-titlebar.phtml');
|
||||
?>
|
||||
<?php
|
||||
$filterUiNamespace = 'system-audit';
|
||||
require templatePath('partials/app-list-filters.phtml');
|
||||
?>
|
||||
<div class="app-list-table">
|
||||
<div id="system-audit-grid"></div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$gridLang = json_decode(appBufferValue('grid_lang'), true);
|
||||
if (!is_array($gridLang)) {
|
||||
$gridLang = [];
|
||||
}
|
||||
$pageConfig = [
|
||||
'gridSearch' => $searchConfig,
|
||||
'filterSchema' => $clientFilterSchema,
|
||||
'filterChipMeta' => $filterChipMeta,
|
||||
'gridLang' => $gridLang,
|
||||
'labels' => [
|
||||
'created' => t('Created'),
|
||||
'status' => t('Status'),
|
||||
'event' => t('Event'),
|
||||
'channel' => t('Channel'),
|
||||
'actor' => t('Actor'),
|
||||
'targetType' => t('Target type'),
|
||||
'requestId' => t('Request ID'),
|
||||
'errorCode' => t('Error code'),
|
||||
],
|
||||
];
|
||||
?>
|
||||
<script src="<?php e(assetVersion('vendor/gridjs/gridjs.umd.js')); ?>"></script>
|
||||
<script type="application/json" id="page-config-admin-system-audit-index"><?php gridJsonForJs($pageConfig); ?></script>
|
||||
<script type="module" src="<?php e(assetVersion('modules/audit/js/pages/admin-system-audit-index.js')); ?>"></script>
|
||||
32
modules/audit/pages/admin/system-audit/purge().php
Normal file
32
modules/audit/pages/admin/system-audit/purge().php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Module\Audit\AuditAuthorizationPolicy;
|
||||
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
|
||||
use MintyPHP\Module\Audit\Service\SystemAuditService;
|
||||
use MintyPHP\Router;
|
||||
use MintyPHP\Session;
|
||||
use MintyPHP\Support\Flash;
|
||||
use MintyPHP\Support\Guard;
|
||||
|
||||
Guard::requireLogin();
|
||||
Guard::requireAbility(AuditAuthorizationPolicy::ABILITY_SYSTEM_AUDIT_PURGE);
|
||||
|
||||
if (strtoupper((string) requestInput()->method()) !== 'POST') {
|
||||
Router::redirect('admin/system-audit');
|
||||
}
|
||||
|
||||
$errorBag = formErrors();
|
||||
if (!Session::checkCsrfToken()) {
|
||||
$errorBag->addGlobal(t('Form expired, please try again'));
|
||||
flashFormErrors($errorBag, 'admin/system-audit', 'system_audit');
|
||||
Router::redirect('admin/system-audit');
|
||||
}
|
||||
|
||||
$service = app(SystemAuditService::class);
|
||||
$deleted = $service->purgeExpired();
|
||||
$service->record('admin.system_audit.purge', SystemAuditOutcome::Success->value, [
|
||||
'metadata' => ['deleted_count' => $deleted],
|
||||
]);
|
||||
|
||||
Flash::success(sprintf(t('%d system audit entries purged'), $deleted), 'admin/system-audit', 'system_audit_purged');
|
||||
Router::redirect('admin/system-audit');
|
||||
20
modules/audit/pages/admin/system-audit/view($id).php
Normal file
20
modules/audit/pages/admin/system-audit/view($id).php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Buffer;
|
||||
use MintyPHP\Module\Audit\AuditAuthorizationPolicy;
|
||||
use MintyPHP\Module\Audit\Service\SystemAuditService;
|
||||
use MintyPHP\Router;
|
||||
use MintyPHP\Support\Flash;
|
||||
use MintyPHP\Support\Guard;
|
||||
|
||||
Guard::requireLogin();
|
||||
Guard::requireAbility(AuditAuthorizationPolicy::ABILITY_SYSTEM_AUDIT_VIEW);
|
||||
|
||||
$auditId = (int) ($id ?? 0);
|
||||
$auditLog = $auditId > 0 ? app(SystemAuditService::class)->find($auditId) : null;
|
||||
if (!$auditLog) {
|
||||
Flash::error(t('System audit entry not found'), 'admin/system-audit', 'system_audit_not_found');
|
||||
Router::redirect('admin/system-audit');
|
||||
}
|
||||
|
||||
Buffer::set('title', t('View system audit entry'));
|
||||
191
modules/audit/pages/admin/system-audit/view(default).phtml
Normal file
191
modules/audit/pages/admin/system-audit/view(default).phtml
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
use MintyPHP\Domain\Taxonomy\SystemAuditOutcome;
|
||||
|
||||
/**
|
||||
* @var array $auditLog
|
||||
*/
|
||||
|
||||
$auditLog = $auditLog ?? [];
|
||||
$outcome = SystemAuditOutcome::normalizeOr((string) ($auditLog['outcome'] ?? ''), SystemAuditOutcome::Success);
|
||||
$outcomeVariant = $outcome->badgeVariant();
|
||||
|
||||
$metadataJson = trim((string) ($auditLog['metadata_json'] ?? ''));
|
||||
$metadataPretty = '-';
|
||||
if ($metadataJson !== '') {
|
||||
$decoded = json_decode($metadataJson, true);
|
||||
if (is_array($decoded)) {
|
||||
$pretty = json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
$metadataPretty = is_string($pretty) ? $pretty : $metadataJson;
|
||||
} else {
|
||||
$metadataPretty = $metadataJson;
|
||||
}
|
||||
}
|
||||
|
||||
$requestId = trim((string) ($auditLog['request_id'] ?? ''));
|
||||
$eventType = trim((string) ($auditLog['event_type'] ?? ''));
|
||||
$channel = strtoupper(trim((string) ($auditLog['channel'] ?? '')));
|
||||
$errorCode = trim((string) ($auditLog['error_code'] ?? ''));
|
||||
$method = strtoupper(trim((string) ($auditLog['method'] ?? '')));
|
||||
$path = trim((string) ($auditLog['path'] ?? ''));
|
||||
$targetType = trim((string) ($auditLog['target_type'] ?? ''));
|
||||
$targetUuid = trim((string) ($auditLog['target_uuid'] ?? ''));
|
||||
$ipHash = trim((string) ($auditLog['ip_hash'] ?? ''));
|
||||
$userAgentHash = trim((string) ($auditLog['user_agent_hash'] ?? ''));
|
||||
|
||||
$actorLabel = trim((string) ($auditLog['actor_user_display_name'] ?? ''));
|
||||
$actorEmail = trim((string) ($auditLog['actor_user_email'] ?? ''));
|
||||
if ($actorLabel === '') {
|
||||
$actorLabel = $actorEmail !== '' ? $actorEmail : '-';
|
||||
}
|
||||
|
||||
$tenantLabel = trim((string) ($auditLog['actor_tenant_description'] ?? ''));
|
||||
if ($tenantLabel === '') {
|
||||
$tenantLabel = '-';
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="app-details-container">
|
||||
<section>
|
||||
<?php
|
||||
$breadcrumbs = [
|
||||
['label' => t('Home'), 'path' => 'admin'],
|
||||
['label' => t('System audit logs'), 'path' => 'admin/system-audit'],
|
||||
['label' => t('View')],
|
||||
];
|
||||
require templatePath('partials/app-breadcrumb.phtml');
|
||||
|
||||
$titlebar = [
|
||||
'title' => t('View system audit entry'),
|
||||
'backHref' => 'admin/system-audit',
|
||||
'backTitle' => t('Back'),
|
||||
];
|
||||
require templatePath('partials/app-details-titlebar.phtml');
|
||||
?>
|
||||
|
||||
<div class="app-details-content">
|
||||
<details open>
|
||||
<summary><?php e(t('Event details')); ?></summary>
|
||||
<hr>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<small><?php e(t('Event type')); ?></small>
|
||||
<p><code><?php e($eventType !== '' ? $eventType : '-'); ?></code></p>
|
||||
</div>
|
||||
<div>
|
||||
<small><?php e(t('Outcome')); ?></small>
|
||||
<p><span class="badge" data-variant="<?php e($outcomeVariant); ?>"><?php e(t($outcome->labelToken())); ?></span></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<small><?php e(t('Channel')); ?></small>
|
||||
<p><?php e($channel !== '' ? $channel : '-'); ?></p>
|
||||
</div>
|
||||
<div>
|
||||
<small><?php e(t('Error code')); ?></small>
|
||||
<p><?php e($errorCode !== '' ? $errorCode : '-'); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($method !== '' || $path !== ''): ?>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<small><?php e(t('Method')); ?></small>
|
||||
<p><?php e($method !== '' ? $method : '-'); ?></p>
|
||||
</div>
|
||||
<div>
|
||||
<small><?php e(t('Path')); ?></small>
|
||||
<p><code><?php e($path !== '' ? $path : '-'); ?></code></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</details>
|
||||
|
||||
<hr>
|
||||
<details>
|
||||
<summary><?php e(t('Scope')); ?></summary>
|
||||
<hr>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<small><?php e(t('Actor')); ?></small>
|
||||
<p>
|
||||
<?php if (!empty($auditLog['actor_user_uuid'])): ?>
|
||||
<a href="admin/users/edit/<?php e($auditLog['actor_user_uuid']); ?>"><?php e($actorLabel); ?></a>
|
||||
<?php else: ?>
|
||||
<?php e($actorLabel); ?>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<small><?php e(t('Actor tenant')); ?></small>
|
||||
<p>
|
||||
<?php if (!empty($auditLog['actor_tenant_uuid'])): ?>
|
||||
<a href="admin/tenants/edit/<?php e($auditLog['actor_tenant_uuid']); ?>"><?php e($tenantLabel); ?></a>
|
||||
<?php else: ?>
|
||||
<?php e($tenantLabel); ?>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<small><?php e(t('Target type')); ?></small>
|
||||
<p><?php e($targetType !== '' ? $targetType : '-'); ?></p>
|
||||
</div>
|
||||
<div>
|
||||
<small><?php e(t('Target UUID')); ?></small>
|
||||
<p><code><?php e($targetUuid !== '' ? $targetUuid : '-'); ?></code></p>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<?php if ($metadataPretty !== '-'): ?>
|
||||
<hr>
|
||||
<details>
|
||||
<summary><?php e(t('Metadata')); ?></summary>
|
||||
<hr>
|
||||
<textarea readonly rows="14"><?php e($metadataPretty); ?></textarea>
|
||||
</details>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<aside id="app-details-aside-section">
|
||||
<div class="app-details-aside-section">
|
||||
<hgroup>
|
||||
<strong><?php e(t('System 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('Created')); ?></small>
|
||||
<p><?php e(dt((string) ($auditLog['created_at'] ?? '')) ?: '-'); ?></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('IP hash')); ?></small>
|
||||
<p><code><?php e($ipHash !== '' ? substr($ipHash, 0, 16) . '...' : '-'); ?></code></p>
|
||||
</div>
|
||||
<div>
|
||||
<small><?php e(t('User agent hash')); ?></small>
|
||||
<p><code><?php e($userAgentHash !== '' ? substr($userAgentHash, 0, 16) . '...' : '-'); ?></code></p>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
Reference in New Issue
Block a user