major update
This commit is contained in:
@@ -1,96 +1,42 @@
|
||||
<?php
|
||||
|
||||
use MintyPHP\Router;
|
||||
use MintyPHP\Http\Request;
|
||||
use MintyPHP\Service\Access\AccessServicesFactory;
|
||||
use MintyPHP\Service\Access\UserAuthorizationPolicy;
|
||||
use MintyPHP\Service\User\UserServicesFactory;
|
||||
use MintyPHP\Support\Guard;
|
||||
|
||||
Guard::requireLogin();
|
||||
$authorizationService = (new AccessServicesFactory())->createAuthorizationService();
|
||||
$decision = $authorizationService->authorize(UserAuthorizationPolicy::ABILITY_ADMIN_USERS_VIEW, [
|
||||
'actor_user_id' => (int) ($_SESSION['user']['id'] ?? 0),
|
||||
]);
|
||||
if (!$decision->isAllowed()) {
|
||||
if (Request::wantsJson()) {
|
||||
http_response_code($decision->status());
|
||||
Router::json(['error' => $decision->error()]);
|
||||
return;
|
||||
}
|
||||
Router::redirect('error/forbidden?url=' . urlencode(Request::pathWithQuery()));
|
||||
return;
|
||||
}
|
||||
Guard::requireAbilityOrForbidden(UserAuthorizationPolicy::ABILITY_ADMIN_USERS_VIEW);
|
||||
|
||||
$userServicesFactory = new UserServicesFactory();
|
||||
$userAccountService = $userServicesFactory->createUserAccountService();
|
||||
$userAvatarService = $userServicesFactory->createUserAvatarService();
|
||||
gridRequireGetRequest();
|
||||
|
||||
$userAccountService = app(\MintyPHP\Service\User\UserAccountService::class);
|
||||
$userAvatarService = app(\MintyPHP\Service\User\UserAvatarService::class);
|
||||
|
||||
$currentUserId = (int) ($_SESSION['user']['id'] ?? 0);
|
||||
|
||||
$limit = (int) ($_GET['limit'] ?? 10);
|
||||
$offset = (int) ($_GET['offset'] ?? 0);
|
||||
$search = trim((string) ($_GET['search'] ?? ''));
|
||||
$order = (string) ($_GET['order'] ?? 'last_name');
|
||||
$dir = (string) ($_GET['dir'] ?? 'asc');
|
||||
$active = $_GET['active'] ?? 'all';
|
||||
$createdFrom = trim((string) ($_GET['created_from'] ?? ''));
|
||||
$createdTo = trim((string) ($_GET['created_to'] ?? ''));
|
||||
$tenant = trim((string) ($_GET['tenant'] ?? ''));
|
||||
$roles = $_GET['roles'] ?? '';
|
||||
$departments = $_GET['departments'] ?? '';
|
||||
$emailVerified = $_GET['email_verified'] ?? 'all';
|
||||
$loginStatus = $_GET['login_status'] ?? 'all';
|
||||
$filters = gridParseFiltersFromSchemaFile(__DIR__ . '/filter-schema.php');
|
||||
|
||||
$result = $userAccountService->listPaged([
|
||||
'limit' => $limit,
|
||||
'offset' => $offset,
|
||||
'search' => $search,
|
||||
'order' => $order,
|
||||
'dir' => $dir,
|
||||
'active' => $active,
|
||||
'created_from' => $createdFrom,
|
||||
'created_to' => $createdTo,
|
||||
'tenant' => $tenant,
|
||||
'roles' => $roles,
|
||||
'departments' => $departments,
|
||||
'email_verified' => $emailVerified,
|
||||
'login_status' => $loginStatus,
|
||||
'limit' => $filters['limit'],
|
||||
'offset' => $filters['offset'],
|
||||
'search' => $filters['search'],
|
||||
'order' => $filters['order'],
|
||||
'dir' => $filters['dir'],
|
||||
'active' => $filters['active'],
|
||||
'created_from' => $filters['created_from'],
|
||||
'created_to' => $filters['created_to'],
|
||||
'tenant' => $filters['tenant'],
|
||||
'roles' => $filters['roles'],
|
||||
'departments' => $filters['departments'],
|
||||
'email_verified' => $filters['email_verified'],
|
||||
'login_status' => $filters['login_status'],
|
||||
'tenantUserId' => $currentUserId,
|
||||
]);
|
||||
|
||||
$rows = [];
|
||||
foreach ($result['rows'] as $row) {
|
||||
$tenantLabels = $row['tenant_labels'] ?? [];
|
||||
if (is_string($tenantLabels)) {
|
||||
$tenantList = $tenantLabels !== ''
|
||||
? array_values(array_filter(array_map('trim', explode('||', $tenantLabels))))
|
||||
: [];
|
||||
} elseif (is_array($tenantLabels)) {
|
||||
$tenantList = array_values(array_filter(array_map('trim', $tenantLabels)));
|
||||
} else {
|
||||
$tenantList = [];
|
||||
}
|
||||
$roleLabels = $row['role_labels'] ?? [];
|
||||
if (is_string($roleLabels)) {
|
||||
$roleList = $roleLabels !== ''
|
||||
? array_values(array_filter(array_map('trim', explode('||', $roleLabels))))
|
||||
: [];
|
||||
} elseif (is_array($roleLabels)) {
|
||||
$roleList = array_values(array_filter(array_map('trim', $roleLabels)));
|
||||
} else {
|
||||
$roleList = [];
|
||||
}
|
||||
$departmentLabels = $row['department_labels'] ?? [];
|
||||
if (is_string($departmentLabels)) {
|
||||
$departmentList = $departmentLabels !== ''
|
||||
? array_values(array_filter(array_map('trim', explode('||', $departmentLabels))))
|
||||
: [];
|
||||
} elseif (is_array($departmentLabels)) {
|
||||
$departmentList = array_values(array_filter(array_map('trim', $departmentLabels)));
|
||||
} else {
|
||||
$departmentList = [];
|
||||
}
|
||||
$tenantList = gridNormalizeLabelList($row['tenant_labels'] ?? []);
|
||||
$roleList = gridNormalizeLabelList($row['role_labels'] ?? []);
|
||||
$departmentList = gridNormalizeLabelList($row['department_labels'] ?? []);
|
||||
$primaryTenantLabel = (string) ($row['primary_tenant_label'] ?? '');
|
||||
if ($primaryTenantLabel === '' && count($tenantList) === 1) {
|
||||
$primaryTenantLabel = (string) $tenantList[0];
|
||||
@@ -119,7 +65,4 @@ foreach ($result['rows'] as $row) {
|
||||
];
|
||||
}
|
||||
|
||||
Router::json([
|
||||
'data' => $rows,
|
||||
'total' => $result['total'] ?? 0,
|
||||
]);
|
||||
gridJsonDataResult($rows, (int) ($result['total'] ?? 0));
|
||||
|
||||
Reference in New Issue
Block a user