mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Return default user setting if not configured for API endpoint /user/settings/{settingKey} (fixes #1169)
This commit is contained in:
@@ -53,14 +53,22 @@ class UsersService extends BaseService
|
||||
public function GetUserSetting($userId, $settingKey)
|
||||
{
|
||||
$settingRow = $this->getDatabase()->user_settings()->where('user_id = :1 AND key = :2', $userId, $settingKey)->fetch();
|
||||
|
||||
if ($settingRow !== null)
|
||||
{
|
||||
return $settingRow->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
// Use the configured default values for a missing setting, otherwise return NULL
|
||||
global $GROCY_DEFAULT_USER_SETTINGS;
|
||||
if (array_key_exists($settingKey, $GROCY_DEFAULT_USER_SETTINGS))
|
||||
{
|
||||
return $GROCY_DEFAULT_USER_SETTINGS[$settingKey];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +77,6 @@ class UsersService extends BaseService
|
||||
$settings = [];
|
||||
|
||||
$settingRows = $this->getDatabase()->user_settings()->where('user_id = :1', $userId)->fetchAll();
|
||||
|
||||
foreach ($settingRows as $settingRow)
|
||||
{
|
||||
$settings[$settingRow->key] = $settingRow->value;
|
||||
|
Reference in New Issue
Block a user