asdasd
This commit is contained in:
@@ -29,13 +29,15 @@ final class App
|
||||
$widgetRegistry = new WidgetRegistry($this->projectRoot . '/config/widgets.php');
|
||||
$skins = SkinResolver::all();
|
||||
$activeSkin = SkinResolver::resolve($_GET['skin'] ?? null);
|
||||
$apps = AppIconResolver::decorate($registry->all(), $activeSkin);
|
||||
$windows = (new WindowManager($registry))->defaultWindows();
|
||||
$activeWidgetIds = DesktopState::defaultWidgetIds();
|
||||
$isAuthenticated = isset($_SESSION['desktop_auth']) && is_array($_SESSION['desktop_auth']);
|
||||
$authUser = $isAuthenticated && is_array($_SESSION['desktop_auth']['user'] ?? null)
|
||||
? $_SESSION['desktop_auth']['user']
|
||||
: [];
|
||||
$authGroups = array_values(array_map('strval', (array) ($authUser['groups'] ?? [])));
|
||||
$visibleApps = $this->filterAppsForGroups($registry->all(), $authGroups);
|
||||
$apps = AppIconResolver::decorate($visibleApps, $activeSkin);
|
||||
$windows = (new WindowManager($registry))->defaultWindows();
|
||||
$activeWidgetIds = DesktopState::defaultWidgetIds();
|
||||
$displayName = (string) ($authUser['name'] ?? $authUser['username'] ?? 'Gast');
|
||||
|
||||
return [
|
||||
@@ -80,4 +82,30 @@ final class App
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array<string, mixed>> $apps
|
||||
* @param array<int, string> $groups
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private function filterAppsForGroups(array $apps, array $groups): array
|
||||
{
|
||||
$normalizedGroups = array_map(static fn (string $group): string => strtolower(trim($group, '/')), $groups);
|
||||
|
||||
return array_values(array_filter($apps, static function (array $app) use ($normalizedGroups): bool {
|
||||
$requiredGroups = array_values(array_map('strval', (array) ($app['required_groups'] ?? [])));
|
||||
|
||||
if ($requiredGroups === []) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($requiredGroups as $group) {
|
||||
if (in_array(strtolower(trim($group, '/')), $normalizedGroups, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user