1
0

fix(user-lifecycle-panel): restore filter-options population

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>
This commit is contained in:
2026-04-26 18:21:27 +02:00
parent 144d8410a4
commit a1c6d62d44

View File

@@ -3,10 +3,12 @@
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' => [
@@ -54,6 +56,17 @@ foreach (UserLifecycleAction::values() as $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 = [];
@@ -63,6 +76,16 @@ foreach (UserLifecycleStatus::values() as $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 = [];
@@ -72,14 +95,47 @@ foreach (UserLifecycleTriggerType::values() as $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'), (int) $actorId),
'description' => sprintf(t('User #%d (deleted)'), (int) $actorId),
];
}
}