Change setting base
All checks were successful
Deploy / deploy-staging (push) Successful in 23s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-06-20 01:21:10 +02:00
parent 162ec5322f
commit 1286f2245a
13 changed files with 524 additions and 7 deletions

View File

@@ -37,7 +37,7 @@ final class UserSelfManagementService
public function load(array $authUser, array $visibleApps, array $widgets, array $availableSkins): array
{
return $this->normalizeSettings(
$this->store($this->storageScope($authUser))->read(),
$this->readRawSettings($authUser),
$authUser,
$visibleApps,
$widgets,
@@ -60,7 +60,7 @@ final class UserSelfManagementService
$normalized = $this->normalizeSettings($merged, $authUser, $visibleApps, $widgets, $availableSkins);
$normalized['updated_at'] = gmdate(DATE_ATOM);
$this->store($this->storageScope($authUser))->write($normalized);
$this->writeRawSettings($normalized, $authUser);
return $normalized;
}
@@ -142,7 +142,7 @@ final class UserSelfManagementService
'meta' => [
'storage_scope' => $this->storageScope($authUser),
'authenticated' => ($authUser['sub'] ?? '') !== '' || ($authUser['username'] ?? '') !== '',
'sync_mode' => 'local-profile',
'sync_mode' => $this->repository()->available() ? 'base-db-user-data' : 'local-fallback',
'sync_targets' => [
'ldap' => 'planned',
'keycloak' => 'planned',
@@ -162,11 +162,26 @@ final class UserSelfManagementService
return $sanitized !== null && $sanitized !== '' ? $sanitized : 'guest';
}
private function store(string $scope): JsonStore
private function fileStore(string $scope): JsonStore
{
return new JsonStore($this->projectRoot . '/data/user-self-management/users/' . $scope . '.json');
}
private function repository(): DesktopUserPreferenceRepository
{
static $repository = null;
if ($repository instanceof DesktopUserPreferenceRepository) {
return $repository;
}
$repository = new DesktopUserPreferenceRepository(
ConfigLoader::load($this->projectRoot, 'base_db')
);
return $repository;
}
/**
* @param array<string, mixed> $settings
* @param array<string, mixed> $authUser
@@ -236,6 +251,49 @@ final class UserSelfManagementService
];
}
/**
* @param array<string, mixed> $authUser
* @return array<string, mixed>
*/
private function readRawSettings(array $authUser): array
{
$scope = $this->storageScope($authUser);
$repository = $this->repository();
if ($repository->available()) {
$stored = $repository->read($scope);
if (is_array($stored)) {
return $stored;
}
$legacy = $this->fileStore($scope)->read();
if ($legacy !== []) {
$repository->write($scope, $legacy, $authUser);
}
return $legacy;
}
return $this->fileStore($scope)->read();
}
/**
* @param array<string, mixed> $settings
* @param array<string, mixed> $authUser
*/
private function writeRawSettings(array $settings, array $authUser): void
{
$scope = $this->storageScope($authUser);
$repository = $this->repository();
if ($repository->available()) {
$repository->write($scope, $settings, $authUser);
return;
}
$this->fileStore($scope)->write($settings);
}
/**
* @param mixed $selected
* @param array<int, string> $allowedIds