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:
2026-03-25 21:12:49 +01:00
parent 12a837bda9
commit 0c351f6aff
176 changed files with 2157 additions and 834 deletions

View File

@@ -1,147 +0,0 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { warnOnce } from '../core/app-dom.js';
import { getAppBase, withCurrentListReturn } from './app-list-utils.js';
const config = readPageConfig('admin-api-audit-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const initApiAuditGrid = () => {
const gridOptions = {
gridjs: window.gridjs,
container: '#api-audit-grid',
dataUrl: 'admin/api-audit/data',
appBase,
columns: [
{
name: labels.created || 'Created',
sort: true,
},
{
name: labels.statusCode || 'Status code',
sort: true,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('');
}
return gridjs.html(`<span class="badge" data-variant="${cell.variant || 'neutral'}">${cell.label || ''}</span>`);
},
},
{
name: labels.method || 'Method',
sort: true,
formatter: (cell) => {
const method = String(cell || '').toUpperCase();
return gridjs.html(`<span class="badge" data-variant="neutral">${method}</span>`);
},
},
{
name: labels.path || 'Path',
sort: true,
},
{
name: labels.durationMs || 'Duration (ms)',
sort: true,
formatter: (cell) => (cell > 0 ? `${cell}` : '-'),
},
{
name: labels.user || 'User',
sort: false,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('-');
}
const label = cell.label || '-';
if (!cell.uuid) {
return gridjs.html(label);
}
const url = withCurrentListReturn(new URL(`admin/users/edit/${cell.uuid}`, appBase).toString());
return gridjs.html(`<a href="${url}">${label}</a>`);
},
},
{
name: labels.tenant || 'Tenant',
sort: false,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('-');
}
const label = cell.label || '-';
if (!cell.uuid) {
return gridjs.html(label);
}
const url = withCurrentListReturn(new URL(`admin/tenants/edit/${cell.uuid}`, appBase).toString());
return gridjs.html(`<a href="${url}">${label}</a>`);
},
},
{
name: labels.errorCode || 'Error code',
sort: false,
formatter: (cell) => (cell ? gridjs.html(`<code>${String(cell)}</code>`) : gridjs.html('-')),
},
{
name: labels.ip || 'IP',
sort: false,
},
{
name: 'ID',
hidden: true,
},
],
sortColumns: ['created_at', 'status_code', 'method', 'path', 'duration_ms', null, null, null, null, null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.created_at,
{
variant: row.status_badge,
label: String(row.status_code || ''),
},
row.method,
row.path,
row.duration_ms,
{
uuid: row.user_uuid || '',
label: row.user_label || '-',
},
{
uuid: row.tenant_uuid || '',
label: row.tenant_label || '-',
},
row.error_code || '',
row.ip || '',
row.id,
]),
rowInteraction: { linkColumn: 3 },
search: gridSearch,
filterSchema,
urlSync: true,
rowDblClick: {
getUrl: (rowData) => {
const id = rowData?.cells?.[9]?.data;
return id ? new URL(`admin/api-audit/view/${id}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#api-audit-search'],
},
});
if (!gridConfig || !gridConfig.grid) {
warnOnce('UI_INIT_FAIL', 'API audit grid init failed', { module: 'admin-api-audit-index', component: 'grid' });
return null;
}
return gridConfig;
};
initApiAuditGrid();
}

View File

@@ -1,104 +0,0 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { warnOnce } from '../core/app-dom.js';
import { getAppBase, withCurrentListReturn } from './app-list-utils.js';
const config = readPageConfig('admin-import-audit-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const profileLabel = (value) => {
const key = String(value || '').toLowerCase();
if (key === 'users') {return labels.users || 'Users';}
if (key === 'departments') {return labels.departments || 'Departments';}
return key || '-';
};
const gridOptions = {
gridjs: window.gridjs,
container: '#import-audit-grid',
dataUrl: 'admin/import-audit/data',
appBase,
columns: [
{ name: labels.created || 'Created', sort: true },
{
name: labels.status || 'Status',
sort: true,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('-');
}
return gridjs.html(`<span class="badge" data-variant="${cell.variant || 'neutral'}">${cell.label || '-'}</span>`);
},
},
{
name: labels.profile || 'Profile',
sort: true,
formatter: (cell) => profileLabel(cell),
},
{ name: labels.durationMs || 'Duration (ms)', sort: true, formatter: (cell) => (cell > 0 ? `${cell}` : '-') },
{ name: labels.rowsTotal || 'Rows total', sort: true },
{ name: labels.createdCount || 'Created count', sort: true },
{ name: labels.skippedCount || 'Skipped count', sort: true },
{ name: labels.failedCount || 'Failed count', sort: true },
{
name: labels.user || 'User',
sort: false,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('-');
}
const label = cell.label || '-';
if (!cell.uuid) {
return gridjs.html(label);
}
const url = withCurrentListReturn(new URL(`admin/users/edit/${cell.uuid}`, appBase).toString());
return gridjs.html(`<a href="${url}">${label}</a>`);
},
},
{ name: 'ID', hidden: true },
],
sortColumns: ['started_at', 'status', 'profile_key', 'duration_ms', 'rows_total', 'created_count', 'skipped_count', 'failed_count', null, null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.started_at,
{ variant: row.status_badge, label: row.status_label || row.status || '' },
row.profile_key,
row.duration_ms,
row.rows_total,
row.created_count,
row.skipped_count,
row.failed_count,
{ uuid: row.user_uuid || '', label: row.user_label || '-' },
row.id,
]),
rowInteraction: { linkColumn: 2 },
search: gridSearch,
filterSchema,
urlSync: true,
rowDblClick: {
getUrl: (rowData) => {
const id = rowData?.cells?.[9]?.data;
return id ? new URL(`admin/import-audit/view/${id}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#import-audit-search'],
},
});
if (!gridConfig || !gridConfig.grid) {
warnOnce('UI_INIT_FAIL', 'Import audit grid init failed', { module: 'admin-import-audit-index', component: 'grid' });
}
}

View File

@@ -1,107 +0,0 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { warnOnce } from '../core/app-dom.js';
import { getAppBase, withCurrentListReturn } from './app-list-utils.js';
const config = readPageConfig('admin-system-audit-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const initSystemAuditGrid = () => {
const gridOptions = {
gridjs: window.gridjs,
container: '#system-audit-grid',
dataUrl: 'admin/system-audit/data',
appBase,
columns: [
{ name: labels.created || 'Created', sort: true },
{
name: labels.status || 'Status',
sort: true,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('');
}
return gridjs.html(`<span class="badge" data-variant="${cell.variant || 'neutral'}">${cell.label || ''}</span>`);
},
},
{ name: labels.event || 'Event', sort: true },
{ name: labels.channel || 'Channel', sort: true },
{
name: labels.actor || 'Actor',
sort: false,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('-');
}
const label = cell.label || '-';
if (!cell.uuid) {
return gridjs.html(label);
}
const url = withCurrentListReturn(new URL(`admin/users/edit/${cell.uuid}`, appBase).toString());
return gridjs.html(`<a href="${url}">${label}</a>`);
},
},
{ name: labels.targetType || 'Target type', sort: false },
{
name: labels.requestId || 'Request ID',
sort: false,
formatter: (cell) => (cell ? gridjs.html(`<code>${String(cell).slice(0, 8)}</code>`) : gridjs.html('-')),
},
{
name: labels.errorCode || 'Error code',
sort: false,
formatter: (cell) => (cell ? gridjs.html(`<code>${String(cell)}</code>`) : gridjs.html('-')),
},
{ name: 'ID', hidden: true },
],
sortColumns: ['created_at', 'outcome', 'event_type', 'channel', null, null, null, null, null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.created_at,
{
variant: row.outcome_badge,
label: String(row.outcome_label || row.outcome || ''),
},
row.event_type,
row.channel,
{
uuid: row.actor_user_uuid || '',
label: row.actor_user_label || '-',
},
row.target_type || '-',
row.request_id || '',
row.error_code || '',
row.id,
]),
rowInteraction: { linkColumn: 2 },
search: gridSearch,
filterSchema,
rowDblClick: {
getUrl: (rowData) => {
const id = rowData?.cells?.[8]?.data;
return id ? new URL(`admin/system-audit/view/${id}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#system-audit-search'],
},
});
return gridConfig;
};
const gridConfig = initSystemAuditGrid();
if (!gridConfig || !gridConfig.grid) {
warnOnce('UI_INIT_FAIL', 'System audit grid init failed', { module: 'admin-system-audit-index', component: 'grid' });
}
}

View File

@@ -1,77 +0,0 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { warnOnce } from '../core/app-dom.js';
import { getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-user-lifecycle-audit-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const gridOptions = {
gridjs: window.gridjs,
container: '#user-lifecycle-audit-grid',
dataUrl: 'admin/user-lifecycle-audit/data',
appBase,
columns: [
{ name: labels.created || 'Created', sort: true },
{
name: labels.status || 'Status',
sort: true,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('-');
}
return gridjs.html(`<span class="badge" data-variant="${cell.variant || 'neutral'}">${cell.label || '-'}</span>`);
},
},
{ name: labels.action || 'Action', sort: true },
{ name: labels.trigger || 'Trigger', sort: true },
{ name: labels.targetEmail || 'Target email', sort: false },
{ name: labels.targetUuid || 'Target UUID', sort: false },
{ name: labels.reasonCode || 'Reason code', sort: false },
{ name: labels.restoredAt || 'Restored at', sort: true },
{ name: 'ID', hidden: true },
],
sortColumns: ['created_at', 'status', 'action', 'trigger_type', null, null, null, 'restored_at', null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.created_at,
{ variant: row.status_badge, label: row.status_label || row.status || '' },
row.action_label || row.action || '-',
row.trigger_type_label || row.trigger_type || '-',
row.target_user_email || '-',
row.target_user_uuid || '-',
row.reason_code || '-',
row.restored_at || '-',
row.id,
]),
rowInteraction: { linkColumn: 2 },
search: gridSearch,
filterSchema,
urlSync: true,
rowDblClick: {
getUrl: (rowData) => {
const id = rowData?.cells?.[8]?.data;
return id ? new URL(`admin/user-lifecycle-audit/view/${id}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#user-lifecycle-audit-search'],
},
});
if (!gridConfig || !gridConfig.grid) {
warnOnce('UI_INIT_FAIL', 'User lifecycle audit grid init failed', { module: 'admin-user-lifecycle-audit-index', component: 'grid' });
}
}