mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Return default user setting if not configured for API endpoint /user/settings/{settingKey} (fixes #1169)
This commit is contained in:
parent
48aa9fd138
commit
4b1766ead0
@ -217,5 +217,6 @@
|
||||
- Fixed that the endpoint `/stock/volatile` didn't include products which expire today (thanks @fipwmaqzufheoxq92ebc)
|
||||
- Fixed that the endpoint `/objects/{entity}` did not include Userfields for Userentities (so the effective endpoint `/objects/userobjects`)
|
||||
- Fixed that the endpoint `/stock/consume` returned the response code `200` and an empty response body when `stock_entry_id` was set (consuming a specific stock entry) but invalid (now returns the response code `400`) (thanks @fipwmaqzufheoxq92ebc)
|
||||
- Fixed that the endpoint `/user/settings/{settingKey}` didn't return the default setting if it was not configured for the current user (same behavior as the endpoint `/user/settings` now)
|
||||
- Endpoint `/calendar/ical`: Fixed that "Track date only"-chores were always set to happen at 12am (are treated as all-day events now)
|
||||
- Fixed (again) that CORS was broken
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user