fix: user settings
All checks were successful
JS Unit Tests / test (pull_request) Successful in 15s
Build Test / build (pull_request) Successful in 19s
PHP Unit Tests / test (pull_request) Successful in 50s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-03-04 20:35:00 -05:00
parent 24e046792b
commit 3a2739fdd8
4 changed files with 43 additions and 16 deletions

View File

@@ -249,7 +249,7 @@ class UserAccountsStore
// Settings Operations
// =========================================================================
public function fetchSettings(string $tenant, string $uid, array $settings = []): ?array
public function fetchSettings(string $tenant, string $uid, array $settings = [], bool $flatten = false): ?array
{
// Only fetch the settings field from the database
$user = $this->store->selectCollection('user_accounts')->findOne(
@@ -264,12 +264,39 @@ class UserAccountsStore
$userSettings = $user['settings'] ?? [];
if (empty($settings)) {
return $userSettings;
return $flatten ? $this->flattenSettings($userSettings) : $userSettings;
}
// Specific keys are always returned in dot-notation (already flat)
$result = [];
foreach ($settings as $key) {
$result[$key] = $userSettings[$key] ?? null;
$parts = explode('.', $key);
$value = $userSettings;
foreach ($parts as $part) {
if (!is_array($value) || !array_key_exists($part, $value)) {
$value = null;
break;
}
$value = $value[$part];
}
$result[$key] = $value;
}
return $result;
}
/**
* Recursively flatten a nested settings array into dot-notation keys.
*/
private function flattenSettings(array $settings, string $prefix = ''): array
{
$result = [];
foreach ($settings as $key => $value) {
$fullKey = $prefix !== '' ? "{$prefix}.{$key}" : (string) $key;
if (is_array($value)) {
$result = array_merge($result, $this->flattenSettings($value, $fullKey));
} else {
$result[$fullKey] = $value;
}
}
return $result;
}