- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks - Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists - Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services - Add Microsoft OIDC SSO, API token management, and user lifecycle features - Add swagger-ui vendor integration and OpenAPI spec - Add production Docker setup and bin/ scripts - Update composer dependencies, config, templates, and frontend assets throughout Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
<?php
|
|
|
|
use MintyPHP\Router;
|
|
use MintyPHP\Support\Guard;
|
|
use MintyPHP\Repository\Access\UserRoleRepository;
|
|
use MintyPHP\Repository\Access\RolePermissionRepository;
|
|
use MintyPHP\Service\Access\RoleService;
|
|
use MintyPHP\Service\Settings\SettingService;
|
|
use MintyPHP\Service\Access\PermissionService;
|
|
|
|
Guard::requireLogin();
|
|
Guard::requirePermission(PermissionService::ROLES_VIEW);
|
|
|
|
$limit = (int) ($_GET['limit'] ?? 10);
|
|
$offset = (int) ($_GET['offset'] ?? 0);
|
|
$search = trim((string) ($_GET['search'] ?? ''));
|
|
$order = (string) ($_GET['order'] ?? 'description');
|
|
$dir = (string) ($_GET['dir'] ?? 'asc');
|
|
$active = (string) ($_GET['active'] ?? '');
|
|
|
|
$result = RoleService::listPaged([
|
|
'limit' => $limit,
|
|
'offset' => $offset,
|
|
'search' => $search,
|
|
'order' => $order,
|
|
'dir' => $dir,
|
|
'active' => $active,
|
|
]);
|
|
|
|
$defaultRoleId = SettingService::getDefaultRoleId();
|
|
$roleIds = [];
|
|
foreach ($result['rows'] as $roleRow) {
|
|
$roleId = (int) ($roleRow['id'] ?? 0);
|
|
if ($roleId > 0) {
|
|
$roleIds[] = $roleId;
|
|
}
|
|
}
|
|
$roleIds = array_values(array_unique($roleIds));
|
|
$roleUserCounts = UserRoleRepository::countUsersByRoleIds($roleIds);
|
|
$roleActiveUserCounts = UserRoleRepository::countActiveUsersByRoleIds($roleIds);
|
|
$rolePermissionCounts = RolePermissionRepository::countPermissionsByRoleIds($roleIds);
|
|
|
|
$rows = [];
|
|
foreach ($result['rows'] as $row) {
|
|
$roleId = (int) ($row['id'] ?? 0);
|
|
$usersTotal = (int) ($roleUserCounts[$roleId] ?? 0);
|
|
$usersActive = (int) ($roleActiveUserCounts[$roleId] ?? 0);
|
|
$usersInactive = max(0, $usersTotal - $usersActive);
|
|
$rows[] = [
|
|
'id' => $row['id'] ?? null,
|
|
'uuid' => $row['uuid'] ?? '',
|
|
'is_default' => $roleId > 0 && $defaultRoleId === $roleId,
|
|
'description' => $row['description'] ?? '',
|
|
'code' => $row['code'] ?? '',
|
|
'active' => (int) ($row['active'] ?? 1),
|
|
'active_users' => $usersActive,
|
|
'inactive_users' => $usersInactive,
|
|
'permission_count' => (int) ($rolePermissionCounts[$roleId] ?? 0),
|
|
'created' => dt($row['created'] ?? ''),
|
|
'modified' => dt($row['modified'] ?? ''),
|
|
];
|
|
}
|
|
|
|
Router::json([
|
|
'data' => $rows,
|
|
'total' => $result['total'] ?? 0,
|
|
]);
|