Self management
This commit is contained in:
@@ -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;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user