Self management
All checks were successful
Deploy / deploy-staging (push) Successful in 24s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-06-17 22:56:22 +02:00
parent a8853f9fd1
commit 6930a14d6b
15 changed files with 1475 additions and 76 deletions

View File

@@ -6,6 +6,7 @@ namespace App;
use Desktop\AppRegistry;
use Desktop\AppIconResolver;
use Desktop\AppVisibility;
use Desktop\DesktopState;
use Desktop\SkinResolver;
use Desktop\WidgetRegistry;
@@ -28,16 +29,30 @@ final class App
$registry = new AppRegistry($this->projectRoot . '/config/apps.php');
$widgetRegistry = new WidgetRegistry($this->projectRoot . '/config/widgets.php');
$skins = SkinResolver::all();
$activeSkin = SkinResolver::resolve($_GET['skin'] ?? null);
$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);
$visibleApps = AppVisibility::filterByGroups($registry->all(), $authGroups);
$userSelfManagement = new UserSelfManagementService($this->projectRoot);
$resolvedSkin = $userSelfManagement->resolveActiveSkin(
isset($_GET['skin']) ? (string) $_GET['skin'] : null,
$authUser,
$visibleApps,
$widgetRegistry->all(),
$skins
);
$userSettings = $resolvedSkin['settings'];
$activeSkin = (string) $resolvedSkin['skin'];
$enabledApps = AppVisibility::filterByEnabledIds(
$visibleApps,
array_values(array_map('strval', (array) ($userSettings['apps']['enabled_ids'] ?? []))),
[UserSelfManagementService::APP_ID]
);
$apps = AppIconResolver::decorate($enabledApps, $activeSkin);
$windows = (new WindowManager($registry))->defaultWindows();
$activeWidgetIds = DesktopState::defaultWidgetIds();
$activeWidgetIds = array_values(array_map('strval', (array) ($userSettings['widgets']['active_ids'] ?? DesktopState::defaultWidgetIds())));
$displayName = (string) ($authUser['name'] ?? $authUser['username'] ?? 'Gast');
$storageScope = $isAuthenticated
? strtolower((string) ($authUser['username'] ?? $authUser['sub'] ?? 'user'))
@@ -56,6 +71,8 @@ final class App
'wallpaper' => SkinResolver::wallpaper($activeSkin),
'storage_scope' => preg_replace('/[^a-z0-9._-]+/i', '-', $storageScope) ?: 'guest',
'workspace' => DesktopState::defaultWorkspace(),
'settings_api' => '/api/user-self-management/index.php',
'user_preferences' => $userSettings,
'login' => [
'authenticated' => $isAuthenticated,
'mode' => $isAuthenticated ? 'authenticated' : 'login-required',
@@ -85,30 +102,4 @@ 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;
}));
}
}