major update
This commit is contained in:
@@ -1,51 +1,35 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Router;
|
||||
use MintyPHP\Domain\Taxonomy\UserLifecycleAction;
|
||||
use MintyPHP\Domain\Taxonomy\UserLifecycleStatus;
|
||||
use MintyPHP\Domain\Taxonomy\UserLifecycleTriggerType;
|
||||
use MintyPHP\Service\Access\OperationsAuthorizationPolicy;
|
||||
use MintyPHP\Support\Guard;
|
||||
use MintyPHP\Service\Access\PermissionService;
|
||||
use MintyPHP\Service\Audit\AuditServicesFactory;
|
||||
|
||||
Guard::requireLogin();
|
||||
Guard::requirePermissionOrForbidden(PermissionService::USER_LIFECYCLE_AUDIT_VIEW);
|
||||
Guard::requireAbilityOrForbidden(OperationsAuthorizationPolicy::ABILITY_ADMIN_USER_LIFECYCLE_AUDIT_VIEW);
|
||||
gridRequireGetRequest();
|
||||
|
||||
if (strtoupper((string) ($_SERVER['REQUEST_METHOD'] ?? 'GET')) !== 'GET') {
|
||||
http_response_code(405);
|
||||
Router::json(['error' => 'method_not_allowed']);
|
||||
}
|
||||
$filters = gridParseFiltersFromSchemaFile(__DIR__ . '/filter-schema.php');
|
||||
|
||||
$factory = new AuditServicesFactory();
|
||||
$result = $factory->createUserLifecycleAuditService()->listPaged([
|
||||
'limit' => (int) ($_GET['limit'] ?? 20),
|
||||
'offset' => (int) ($_GET['offset'] ?? 0),
|
||||
'search' => trim((string) ($_GET['search'] ?? '')),
|
||||
'action' => trim((string) ($_GET['action'] ?? '')),
|
||||
'status' => trim((string) ($_GET['status'] ?? '')),
|
||||
'trigger_type' => trim((string) ($_GET['trigger_type'] ?? '')),
|
||||
'created_from' => trim((string) ($_GET['created_from'] ?? '')),
|
||||
'created_to' => trim((string) ($_GET['created_to'] ?? '')),
|
||||
'order' => (string) ($_GET['order'] ?? 'created_at'),
|
||||
'dir' => (string) ($_GET['dir'] ?? 'desc'),
|
||||
]);
|
||||
$result = app(\MintyPHP\Service\Audit\UserLifecycleAuditService::class)->listPaged($filters);
|
||||
|
||||
$rows = [];
|
||||
foreach ((array) ($result['rows'] ?? []) as $row) {
|
||||
$status = strtolower(trim((string) ($row['status'] ?? '')));
|
||||
$statusBadge = 'neutral';
|
||||
if ($status === 'success') {
|
||||
$statusBadge = 'success';
|
||||
} elseif ($status === 'failed') {
|
||||
$statusBadge = 'danger';
|
||||
} elseif ($status === 'skipped') {
|
||||
$statusBadge = 'warning';
|
||||
}
|
||||
$status = UserLifecycleStatus::normalizeOr((string) ($row['status'] ?? ''), UserLifecycleStatus::Failed);
|
||||
$action = UserLifecycleAction::normalizeOr((string) ($row['action'] ?? ''), UserLifecycleAction::Deactivate);
|
||||
$triggerType = UserLifecycleTriggerType::normalizeOr((string) ($row['trigger_type'] ?? ''), UserLifecycleTriggerType::System);
|
||||
|
||||
$rows[] = [
|
||||
'id' => (int) ($row['id'] ?? 0),
|
||||
'created_at' => dt((string) ($row['created_at'] ?? '')),
|
||||
'status' => $status,
|
||||
'status_badge' => $statusBadge,
|
||||
'action' => (string) ($row['action'] ?? ''),
|
||||
'trigger_type' => (string) ($row['trigger_type'] ?? ''),
|
||||
'status' => $status->value,
|
||||
'status_badge' => $status->badgeVariant(),
|
||||
'status_label' => t($status->labelToken()),
|
||||
'action' => $action->value,
|
||||
'action_label' => t($action->labelToken()),
|
||||
'trigger_type' => $triggerType->value,
|
||||
'trigger_type_label' => t($triggerType->labelToken()),
|
||||
'reason_code' => (string) ($row['reason_code'] ?? ''),
|
||||
'target_user_uuid' => (string) ($row['target_user_uuid'] ?? ''),
|
||||
'target_user_email' => (string) ($row['target_user_email'] ?? ''),
|
||||
@@ -53,7 +37,4 @@ foreach ((array) ($result['rows'] ?? []) as $row) {
|
||||
];
|
||||
}
|
||||
|
||||
Router::json([
|
||||
'data' => $rows,
|
||||
'total' => (int) ($result['total'] ?? 0),
|
||||
]);
|
||||
gridJsonDataResult($rows, (int) ($result['total'] ?? 0));
|
||||
|
||||
Reference in New Issue
Block a user