190 lines
6.0 KiB
PHTML
190 lines
6.0 KiB
PHTML
<?php
|
|
$pageAuth = is_array($viewAuth['page'] ?? null) ? $viewAuth['page'] : [];
|
|
$canPurgeApiAudit = (bool) ($pageAuth['can_purge'] ?? 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('API audit logs')],
|
|
];
|
|
require templatePath('partials/app-breadcrumb.phtml');
|
|
?>
|
|
<?php
|
|
$listTitle = t('API audit logs');
|
|
ob_start();
|
|
?>
|
|
<?php
|
|
$listPurgeEnabled = $canPurgeApiAudit;
|
|
$listPurgeFormId = 'api-audit-purge-form';
|
|
$listPurgeAction = 'admin/api-audit/purge';
|
|
$listPurgeConfirmMessage = t('Purge entries older than 90 days?');
|
|
$listPurgeButtonLabel = t('Purge API audit logs');
|
|
require templatePath('partials/app-list-purge-action.phtml');
|
|
?>
|
|
<?php
|
|
$listTitleActionsHtml = ob_get_clean();
|
|
require templatePath('partials/app-list-titlebar.phtml');
|
|
?>
|
|
<?php
|
|
$filterUiNamespace = 'api-audit';
|
|
require templatePath('partials/app-list-filters.phtml');
|
|
?>
|
|
<div class="app-list-table">
|
|
<div id="api-audit-grid"></div>
|
|
</div>
|
|
|
|
<script src="<?php e(asset('vendor/gridjs/gridjs.umd.js')); ?>"></script>
|
|
<script type="module">
|
|
import { initStandardListPage } from "<?php e(assetVersion('js/core/app-grid-factory.js')); ?>";
|
|
import { getAppBase } from "<?php e(assetVersion('js/pages/app-list-utils.js')); ?>";
|
|
|
|
const appBase = getAppBase();
|
|
const gridSearch = <?php gridJsonForJs($searchConfig); ?>;
|
|
const filterSchema = <?php gridJsonForJs($clientFilterSchema); ?>;
|
|
const filterChipMeta = <?php gridJsonForJs($filterChipMeta); ?>;
|
|
|
|
const initApiAuditGrid = () => {
|
|
const gridOptions = {
|
|
gridjs: window.gridjs,
|
|
container: '#api-audit-grid',
|
|
dataUrl: 'admin/api-audit/data',
|
|
appBase,
|
|
columns: [
|
|
{
|
|
name: "<?php e(t('Created')); ?>",
|
|
sort: true
|
|
},
|
|
{
|
|
name: "<?php e(t('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: "<?php e(t('Method')); ?>",
|
|
sort: true,
|
|
formatter: (cell) => {
|
|
const method = String(cell || '').toUpperCase();
|
|
return gridjs.html(`<span class="badge" data-variant="neutral">${method}</span>`);
|
|
}
|
|
},
|
|
{
|
|
name: "<?php e(t('Path')); ?>",
|
|
sort: true
|
|
},
|
|
{
|
|
name: "<?php e(t('Duration (ms)')); ?>",
|
|
sort: true,
|
|
formatter: (cell) => (cell > 0 ? `${cell}` : '-')
|
|
},
|
|
{
|
|
name: "<?php e(t('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 = new URL(`admin/users/edit/${cell.uuid}`, appBase).toString();
|
|
return gridjs.html(`<a href="${url}">${label}</a>`);
|
|
}
|
|
},
|
|
{
|
|
name: "<?php e(t('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 = new URL(`admin/tenants/edit/${cell.uuid}`, appBase).toString();
|
|
return gridjs.html(`<a href="${url}">${label}</a>`);
|
|
}
|
|
},
|
|
{
|
|
name: "<?php e(t('Error code')); ?>",
|
|
sort: false,
|
|
formatter: (cell) => cell ? gridjs.html(`<code>${String(cell)}</code>`) : gridjs.html('-')
|
|
},
|
|
{
|
|
name: "<?php e(t('IP')); ?>",
|
|
sort: false
|
|
},
|
|
{
|
|
name: 'ID',
|
|
hidden: true
|
|
}
|
|
],
|
|
sortColumns: ['created_at', 'status_code', 'method', 'path', 'duration_ms', null, null, null, null, null],
|
|
paginationLimit: 10,
|
|
language: <?php MintyPHP\Buffer::get('grid_lang'); ?>,
|
|
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
|
|
]),
|
|
actions: {
|
|
enabled: false
|
|
},
|
|
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) {
|
|
console.warn('API audit grid init failed');
|
|
return null;
|
|
}
|
|
return gridConfig;
|
|
};
|
|
|
|
initApiAuditGrid();
|
|
</script>
|