Files
fs 874a90d8f8 refactor(admin-lists): slim tenant + user grids, Stripe-style pagination
Tenant list:
- Drop the avatar/logo column — the list now shows only Tenant name
  and user count. Also drop the logo-hasLogo server lookup and the
  initials/placeholder markup.

User list (13 → 4 columns, Stripe pattern):
- User (compound: avatar + Name + email subtitle, click opens drawer)
- Tenants (badges, primary tooltip)
- Last login (relative badge)
- State (active/inactive badge)
- UUID hidden at the last column for cells[uuidIndex].data
- Everything else (departments, roles, phone, mobile, short_dial,
  created, modified) lives in the detail drawer.
- Document the off-by-one gotcha: with row selection enabled gridjs
  prepends a checkbox cell, so runtime cells[] are shifted by +1;
  uuidIndex is 5 (column position 4 + selection offset).
- New .grid-user-profile css mirrors .grid-tenant-profile (avatar +
  stacked name/email) with ellipsis and primary-color hover affordance.

Pagination (all Grid.js lists):
- Non-current page buttons now use the neutral-chip secondary-outline
  tokens (--app-button-neutral-*) plus the raised box-shadow — matches
  the rest of the button system in both light and dark themes.
- Current page stays distinctly primary-filled with the filled-shadow;
  focus-visible combines the chip shadow with the primary focus ring.
- Disabled pager buttons remain neutral but lose the lift shadow.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 21:52:44 +02:00

98 lines
3.7 KiB
PHP

<?php
use MintyPHP\Domain\Taxonomy\TenantStatus;
use MintyPHP\Service\Access\TenantAuthorizationPolicy;
use MintyPHP\Support\Guard;
Guard::requireLogin();
gridRequireGetRequest();
$decision = Guard::requireAbilityDecisionOrForbidden(TenantAuthorizationPolicy::ABILITY_ADMIN_TENANTS_VIEW);
$capabilities = $decision->attribute('capabilities', []);
$allowedTenantIds = is_array($capabilities) ? toIntIds($capabilities['allowed_tenant_ids'] ?? []) : [];
$isStrictScope = is_array($capabilities) ? (bool) ($capabilities['is_strict_scope'] ?? false) : false;
$hasGlobalAccess = is_array($capabilities) ? (bool) ($capabilities['has_global_access'] ?? false) : false;
$filters = gridParseFiltersFromSchemaFile(__DIR__ . '/filter-schema.php');
$order = $filters['order'];
$dir = $filters['dir'];
$computedOrderKeys = ['users'];
$userTenantRepository = app(\MintyPHP\Repository\Tenant\UserTenantRepository::class);
$settingsDefaultsGateway = app(\MintyPHP\Service\Settings\SettingsDefaultsGateway::class);
$gridUserCountEnricher = app(\MintyPHP\Service\Data\GridUserCountEnricher::class);
$fetchRows = static function (array $tenantRows) use ($userTenantRepository, $settingsDefaultsGateway, $gridUserCountEnricher): array {
$userCounts = $gridUserCountEnricher->computeCounts(
$tenantRows,
$userTenantRepository->countUsersByTenantIds(...),
$userTenantRepository->countActiveUsersByTenantIds(...)
);
$defaultTenantId = $settingsDefaultsGateway->getDefaultTenantId();
$rows = [];
foreach ($tenantRows as $row) {
$tenantId = (int) ($row['id'] ?? 0);
$counts = $userCounts[$tenantId] ?? ['active_users' => 0, 'inactive_users' => 0];
$tenantStatus = TenantStatus::normalizeOr((string) ($row['status'] ?? ''), TenantStatus::Active);
$tenantUuid = (string) ($row['uuid'] ?? '');
$rows[] = [
'id' => $row['id'] ?? null,
'uuid' => $tenantUuid,
'is_default' => $tenantId > 0 && $defaultTenantId === $tenantId,
'description' => $row['description'] ?? '',
'status' => $tenantStatus->value,
'status_badge' => $tenantStatus->badgeVariant(),
'status_label' => t($tenantStatus->labelToken()),
'total_users' => $counts['active_users'] + $counts['inactive_users'],
];
}
return $rows;
};
$listOptions = [
'limit' => $filters['limit'],
'offset' => $filters['offset'],
'search' => $filters['search'],
'status' => $filters['status'],
'order' => in_array($order, $computedOrderKeys, true) ? 'description' : $order,
'dir' => $dir,
];
if (!$hasGlobalAccess) {
if ($allowedTenantIds) {
$listOptions['tenantIds'] = $allowedTenantIds;
} elseif ($isStrictScope) {
$listOptions['tenantIds'] = [];
}
}
$result = app(\MintyPHP\Service\Tenant\TenantService::class)->listPaged($listOptions);
$rows = [];
$total = (int) ($result['total'] ?? 0);
if (in_array($order, $computedOrderKeys, true)) {
$fullResult = app(\MintyPHP\Service\Tenant\TenantService::class)->listPaged([
...$listOptions,
'limit' => max(1, $total),
'offset' => 0,
'order' => 'description',
'dir' => 'asc',
]);
$rows = $fetchRows($fullResult['rows'] ?? []);
usort($rows, static function (array $a, array $b) use ($dir): int {
$cmp = ((int) $a['total_users']) <=> ((int) $b['total_users']);
if ($cmp === 0) {
$cmp = strcasecmp((string) $a['description'], (string) $b['description']);
}
return $dir === 'desc' ? -$cmp : $cmp;
});
$rows = array_slice($rows, $filters['offset'], $filters['limit']);
} else {
$rows = $fetchRows($result['rows'] ?? []);
}
gridJsonDataResult($rows, $total);