forked from fa/breadcrumb-the-shire
Follow-up to commit 144d841 (Embed user lifecycle audit into settings
page). The original move from a standalone audit page to a settings
panel silently dropped UserLifecycleAuditService::filterOptions()
from the panel template. The service method was kept (still defined
in UserLifecycleAuditService.php) but had zero callers — dead code,
and three concrete UX/data regressions:
* Actor filter dropdown is empty: previously populated with
display_name + email + (deleted)-marker for every actor that
appeared in lifecycle events; after the move only actor IDs
already pinned in the URL via ?actor_user_ids= are listed, with
bare "User #N" labels instead of human-readable names.
* DB-only enum values are no longer surfaced: action/status/trigger
filter dropdowns are populated only from the PHP enum cases.
Migration drift values present in the DB but absent from the enum
silently disappear from the filter UI.
* Active-actor-fallback lost the (deleted) suffix. An actor ID in
the URL with no matching DB row used to be labeled "User #N
(deleted)" — now just "User #N", losing the lifecycle hint.
Restores the three filter-options merge loops verbatim from the
pre-144d841 implementation: defensive enum-merge for actions /
statuses / triggers, full actor enumeration from filterOptions['actors']
with display_name/email/exists handling, and the (deleted) suffix
fallback. UserLifecycleAuditService::filterOptions() is once again
consumed; sister services (Api/System/Import) keep their existing
usage unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
252 lines
9.6 KiB
PHTML
252 lines
9.6 KiB
PHTML
<?php
|
|
|
|
use MintyPHP\Module\Audit\Domain\UserLifecycleAction;
|
|
use MintyPHP\Module\Audit\Domain\UserLifecycleStatus;
|
|
use MintyPHP\Module\Audit\Domain\UserLifecycleTriggerType;
|
|
use MintyPHP\Module\Audit\Service\UserLifecycleAuditService;
|
|
|
|
$canPurge = (bool) ($canUpdateSettings ?? false);
|
|
|
|
$filterSchema = require __DIR__ . '/../pages/audit/settings-user-lifecycle/filter-schema.php';
|
|
$filterOptions = app(UserLifecycleAuditService::class)->filterOptions(200);
|
|
$filterState = gridParseFilters(requestInput()->queryAll(), [
|
|
...gridSchemaQuery($filterSchema),
|
|
'actions' => [
|
|
'type' => 'csv_strings',
|
|
'max' => 200,
|
|
'return' => 'array',
|
|
'sanitizer' => gridEnumSanitizer(UserLifecycleAction::class),
|
|
],
|
|
'statuses' => [
|
|
'type' => 'csv_strings',
|
|
'max' => 200,
|
|
'return' => 'array',
|
|
'sanitizer' => gridEnumSanitizer(UserLifecycleStatus::class),
|
|
],
|
|
'trigger_types' => [
|
|
'type' => 'csv_strings',
|
|
'max' => 200,
|
|
'return' => 'array',
|
|
'sanitizer' => gridEnumSanitizer(UserLifecycleTriggerType::class),
|
|
],
|
|
'actor_user_ids' => ['type' => 'csv_ids', 'max' => 200, 'return' => 'array'],
|
|
]);
|
|
$activeActions = is_array($filterState['actions'] ?? null) ? $filterState['actions'] : [];
|
|
$activeStatuses = is_array($filterState['statuses'] ?? null) ? $filterState['statuses'] : [];
|
|
$activeTriggerTypes = is_array($filterState['trigger_types'] ?? null) ? $filterState['trigger_types'] : [];
|
|
$activeActorUserIds = array_map('strval', is_array($filterState['actor_user_ids'] ?? null) ? $filterState['actor_user_ids'] : []);
|
|
|
|
$actionLabelMap = [];
|
|
foreach (UserLifecycleAction::cases() as $actionCase) {
|
|
$actionLabelMap[$actionCase->value] = t($actionCase->labelToken());
|
|
}
|
|
$statusLabelMap = [];
|
|
foreach (UserLifecycleStatus::cases() as $statusCase) {
|
|
$statusLabelMap[$statusCase->value] = t($statusCase->labelToken());
|
|
}
|
|
$triggerLabelMap = [];
|
|
foreach (UserLifecycleTriggerType::cases() as $triggerCase) {
|
|
$triggerLabelMap[$triggerCase->value] = t($triggerCase->labelToken());
|
|
}
|
|
|
|
$lifecycleActionItems = [];
|
|
foreach (UserLifecycleAction::values() as $action) {
|
|
$lifecycleActionItems[$action] = [
|
|
'id' => $action,
|
|
'description' => $actionLabelMap[$action] ?? $action,
|
|
];
|
|
}
|
|
// Defensive merge: catch DB values not covered by the PHP enum (migration drift).
|
|
foreach ((array) ($filterOptions['actions'] ?? []) as $action) {
|
|
$action = strtolower(trim((string) $action));
|
|
if ($action === '' || isset($lifecycleActionItems[$action])) {
|
|
continue;
|
|
}
|
|
$lifecycleActionItems[$action] = [
|
|
'id' => $action,
|
|
'description' => $actionLabelMap[$action] ?? $action,
|
|
];
|
|
}
|
|
$lifecycleActionItems = array_values($lifecycleActionItems);
|
|
|
|
$lifecycleStatusItems = [];
|
|
foreach (UserLifecycleStatus::values() as $status) {
|
|
$lifecycleStatusItems[$status] = [
|
|
'id' => $status,
|
|
'description' => $statusLabelMap[$status] ?? $status,
|
|
];
|
|
}
|
|
foreach ((array) ($filterOptions['statuses'] ?? []) as $status) {
|
|
$status = strtolower(trim((string) $status));
|
|
if ($status === '' || isset($lifecycleStatusItems[$status])) {
|
|
continue;
|
|
}
|
|
$lifecycleStatusItems[$status] = [
|
|
'id' => $status,
|
|
'description' => $statusLabelMap[$status] ?? $status,
|
|
];
|
|
}
|
|
$lifecycleStatusItems = array_values($lifecycleStatusItems);
|
|
|
|
$lifecycleTriggerItems = [];
|
|
foreach (UserLifecycleTriggerType::values() as $triggerType) {
|
|
$lifecycleTriggerItems[$triggerType] = [
|
|
'id' => $triggerType,
|
|
'description' => $triggerLabelMap[$triggerType] ?? $triggerType,
|
|
];
|
|
}
|
|
foreach ((array) ($filterOptions['trigger_types'] ?? []) as $triggerType) {
|
|
$triggerType = strtolower(trim((string) $triggerType));
|
|
if ($triggerType === '' || isset($lifecycleTriggerItems[$triggerType])) {
|
|
continue;
|
|
}
|
|
$lifecycleTriggerItems[$triggerType] = [
|
|
'id' => $triggerType,
|
|
'description' => $triggerLabelMap[$triggerType] ?? $triggerType,
|
|
];
|
|
}
|
|
$lifecycleTriggerItems = array_values($lifecycleTriggerItems);
|
|
|
|
$lifecycleActorItems = [];
|
|
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;
|
|
$lifecycleActorItems[$id] = [
|
|
'id' => $id,
|
|
'description' => $label,
|
|
];
|
|
}
|
|
foreach ($activeActorUserIds as $actorId) {
|
|
if (!isset($lifecycleActorItems[$actorId])) {
|
|
$lifecycleActorItems[$actorId] = [
|
|
'id' => $actorId,
|
|
'description' => sprintf(t('User #%d (deleted)'), (int) $actorId),
|
|
];
|
|
}
|
|
}
|
|
$lifecycleActorItems = array_values($lifecycleActorItems);
|
|
|
|
$toolbarFilterState = [
|
|
'search' => (string) ($filterState['search'] ?? ''),
|
|
'actions' => $activeActions,
|
|
'statuses' => $activeStatuses,
|
|
'trigger_types' => $activeTriggerTypes,
|
|
'actor_user_ids' => $activeActorUserIds,
|
|
'created_from' => (string) ($filterState['created_from'] ?? ''),
|
|
'created_to' => (string) ($filterState['created_to'] ?? ''),
|
|
];
|
|
$toolbarOptionSets = [
|
|
'action_items' => $lifecycleActionItems,
|
|
'status_items' => $lifecycleStatusItems,
|
|
'trigger_items' => $lifecycleTriggerItems,
|
|
'actor_items' => $lifecycleActorItems,
|
|
];
|
|
$listFilterContext = gridBuildListFilterContext($filterSchema, [
|
|
'filter_state' => $filterState,
|
|
'search_keys' => ['search'],
|
|
'toolbar_state_overrides' => $toolbarFilterState,
|
|
'toolbar_option_sets' => $toolbarOptionSets,
|
|
]);
|
|
$toolbarFilterSchema = is_array($listFilterContext['toolbarFilterSchema'] ?? null) ? $listFilterContext['toolbarFilterSchema'] : [];
|
|
$searchToolbarFilterSchema = is_array($listFilterContext['searchToolbarFilterSchema'] ?? null) ? $listFilterContext['searchToolbarFilterSchema'] : [];
|
|
$drawerToolbarFilterSchema = is_array($listFilterContext['drawerToolbarFilterSchema'] ?? null) ? $listFilterContext['drawerToolbarFilterSchema'] : [];
|
|
$toolbarFilterState = is_array($listFilterContext['toolbarFilterState'] ?? null) ? $listFilterContext['toolbarFilterState'] : [];
|
|
$toolbarOptionSets = is_array($listFilterContext['toolbarOptionSets'] ?? null) ? $listFilterContext['toolbarOptionSets'] : [];
|
|
$clientFilterSchema = is_array($listFilterContext['clientFilterSchema'] ?? null) ? $listFilterContext['clientFilterSchema'] : [];
|
|
$searchConfig = $listFilterContext['searchConfig'] ?? null;
|
|
|
|
$filterChipMeta = [
|
|
'search' => [
|
|
'label' => t('Search'),
|
|
'type' => 'text',
|
|
],
|
|
'actions' => [
|
|
'label' => t('Action'),
|
|
'type' => 'multi_csv',
|
|
'options' => gridOptionMapFromItems($lifecycleActionItems),
|
|
],
|
|
'statuses' => [
|
|
'label' => t('Status'),
|
|
'type' => 'multi_csv',
|
|
'options' => gridOptionMapFromItems($lifecycleStatusItems),
|
|
],
|
|
'trigger_types' => [
|
|
'label' => t('Trigger'),
|
|
'type' => 'multi_csv',
|
|
'options' => gridOptionMapFromItems($lifecycleTriggerItems),
|
|
],
|
|
'actor_user_ids' => [
|
|
'label' => t('Actor'),
|
|
'type' => 'multi_csv',
|
|
'options' => gridOptionMapFromItems($lifecycleActorItems),
|
|
],
|
|
'created_range' => [
|
|
'label' => t('Created'),
|
|
'type' => 'date_range',
|
|
'from_param' => 'created_from',
|
|
'to_param' => 'created_to',
|
|
],
|
|
];
|
|
|
|
$listTitle = t('User lifecycle logs');
|
|
ob_start();
|
|
$listPurgeEnabled = $canPurge;
|
|
$listPurgeFormId = 'settings-user-lifecycle-audit-purge-form';
|
|
$listPurgeAction = endpointUrl('admin/settings/user-lifecycle/audit-purge');
|
|
$listPurgeConfirmMessage = t('Purge entries older than 365 days?');
|
|
$listPurgeButtonLabel = t('Purge user lifecycle logs');
|
|
require templatePath('partials/app-list-purge-action.phtml');
|
|
$listTitleActionsHtml = ob_get_clean();
|
|
|
|
$filterUiNamespace = 'settings-user-lifecycle';
|
|
$filterToolbarId = 'settings-user-lifecycle-audit-toolbar';
|
|
$filterDrawerToolbarId = 'settings-user-lifecycle-audit-drawer-toolbar';
|
|
$filterDrawerTitleId = 'settings-user-lifecycle-audit-filter-drawer-title';
|
|
|
|
$pageConfig = [
|
|
'dataUrl' => endpointUrl('admin/settings/user-lifecycle/audit-data'),
|
|
'gridSearch' => $searchConfig,
|
|
'filterSchema' => $clientFilterSchema,
|
|
'filterChipMeta' => $filterChipMeta,
|
|
'gridLang' => gridLang(),
|
|
'labels' => [
|
|
'created' => t('Created'),
|
|
'status' => t('Status'),
|
|
'action' => t('Action'),
|
|
'trigger' => t('Trigger'),
|
|
'targetEmail' => t('Target email'),
|
|
'targetUuid' => t('Target UUID'),
|
|
'reasonCode' => t('Reason code'),
|
|
'restoredAt' => t('Restored at'),
|
|
],
|
|
];
|
|
?>
|
|
|
|
<section class="app-settings-user-lifecycle-audit" data-app-component="settings-user-lifecycle-audit">
|
|
<?php require templatePath('partials/app-list-titlebar.phtml'); ?>
|
|
<?php require templatePath('partials/app-list-filters.phtml'); ?>
|
|
|
|
<div class="app-list-table">
|
|
<div id="settings-user-lifecycle-audit-grid"></div>
|
|
</div>
|
|
|
|
<script src="<?php e(assetVersion('vendor/gridjs/gridjs.umd.js')); ?>"></script>
|
|
<script type="application/json" id="page-config-settings-user-lifecycle-audit-panel"><?php gridJsonForJs($pageConfig); ?></script>
|
|
<script type="module" src="<?php e(assetVersion('modules/audit/js/pages/settings-user-lifecycle-audit-panel.js')); ?>"></script>
|
|
</section>
|