mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Added new API endpoints to get all user and config settings (closes #718)
This commit is contained in:
parent
b971375881
commit
42e6a8ef94
@ -28,12 +28,12 @@
|
|||||||
- Fixed that the "Share/Integrate calendar (iCal)" button did not work (thanks @tsia)
|
- Fixed that the "Share/Integrate calendar (iCal)" button did not work (thanks @tsia)
|
||||||
|
|
||||||
### API improvements/fixes
|
### API improvements/fixes
|
||||||
- Fixed that CORS was broken (there was no response to preflight OPTIONS requests)
|
- New endpoint `/user/settings` to get all user settings of the currently logged in user (key/value pairs)
|
||||||
|
- New endpoint `/system/config` to get all config settings (`config.php`) (key/value pairs)
|
||||||
- The endpoint `/stock/products/{productId}/locations` now also returns the current stock amount of the product in that loctation (new field/property `amount`) (thanks @Forceu)
|
- The endpoint `/stock/products/{productId}/locations` now also returns the current stock amount of the product in that loctation (new field/property `amount`) (thanks @Forceu)
|
||||||
|
- Fixed that CORS was broken (there was no response to preflight OPTIONS requests)
|
||||||
|
|
||||||
### General & other improvements/fixes
|
### General & other improvements/fixes
|
||||||
- Fixed that all number inputs are always prefilled in the browser locale number format
|
|
||||||
- Fixed (again) that the `update.sh` file had wrong line endings (DOS instead of Unix)
|
|
||||||
- Optimized that sometimes the corresponding form was not validated when selecting a date from the datetimepicker
|
- Optimized that sometimes the corresponding form was not validated when selecting a date from the datetimepicker
|
||||||
- New `config.php` setting `FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_FIELD_NUMBER_PAD` which activates the number pad for best-before-date fields on (supported) mobile browsers (useful because of [shorthands](https://github.com/grocy/grocy#input-shorthands-for-date-fields)) (defaults to `true`) (thanks @Mik-)
|
- New `config.php` setting `FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_FIELD_NUMBER_PAD` which activates the number pad for best-before-date fields on (supported) mobile browsers (useful because of [shorthands](https://github.com/grocy/grocy#input-shorthands-for-date-fields)) (defaults to `true`) (thanks @Mik-)
|
||||||
- Enhancements for the camera barcode scanner (thanks @Mik-)
|
- Enhancements for the camera barcode scanner (thanks @Mik-)
|
||||||
@ -44,6 +44,8 @@
|
|||||||
- Improved the the overview pages on mobile devices (main column was hidden) (thanks @Mik-)
|
- Improved the the overview pages on mobile devices (main column was hidden) (thanks @Mik-)
|
||||||
- Optimized the handling of settings provided by `data/settingoverrides` files (thanks @dacto)
|
- Optimized the handling of settings provided by `data/settingoverrides` files (thanks @dacto)
|
||||||
- Optimized the update script (`update.sh`) to create the backup tar archive before writing to it (was a problem on Btrfs file systems) (thanks @shane-kerr)
|
- Optimized the update script (`update.sh`) to create the backup tar archive before writing to it (was a problem on Btrfs file systems) (thanks @shane-kerr)
|
||||||
|
- Fixed that all number inputs are always prefilled in the browser locale number format
|
||||||
|
- Fixed (again) that the `update.sh` file had wrong line endings (DOS instead of Unix)
|
||||||
- New translations: (thanks all the translators)
|
- New translations: (thanks all the translators)
|
||||||
- Japanese (demo available at https://ja.demo.grocy.info)
|
- Japanese (demo available at https://ja.demo.grocy.info)
|
||||||
- Chinese (Taiwan) (demo available at https://zh-tw.demo.grocy.info)
|
- Chinese (Taiwan) (demo available at https://zh-tw.demo.grocy.info)
|
||||||
|
@ -16,6 +16,35 @@ class SystemApiController extends BaseApiController
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetConfig(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$constants = get_defined_constants();
|
||||||
|
|
||||||
|
// Some GROCY_* constants are not really config settings and therefore should not be exposed
|
||||||
|
unset($constants['GROCY_AUTHENTICATED']);
|
||||||
|
unset($constants['GROCY_DATAPATH']);
|
||||||
|
unset($constants['GROCY_IS_EMBEDDED_INSTALL']);
|
||||||
|
unset($constants['GROCY_USER_ID']);
|
||||||
|
|
||||||
|
$returnArray = array();
|
||||||
|
foreach ($constants as $constant => $value)
|
||||||
|
{
|
||||||
|
if (substr($constant, 0, 6) === 'GROCY_')
|
||||||
|
{
|
||||||
|
$returnArray[substr($constant, 6)] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->ApiResponse($response, $returnArray);
|
||||||
|
}
|
||||||
|
catch (\Exception $ex)
|
||||||
|
{
|
||||||
|
return $this->GenericErrorResponse($response, $ex->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function LogMissingLocalization(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
public function LogMissingLocalization(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||||
{
|
{
|
||||||
if (GROCY_MODE === 'dev')
|
if (GROCY_MODE === 'dev')
|
||||||
|
@ -69,6 +69,18 @@ class UsersApiController extends BaseApiController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetUserSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return $this->ApiResponse($response, $this->getUsersService()->GetUserSettings(GROCY_USER_ID));
|
||||||
|
}
|
||||||
|
catch (\Exception $ex)
|
||||||
|
{
|
||||||
|
return $this->GenericErrorResponse($response, $ex->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function GetUserSetting(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
public function GetUserSetting(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -115,6 +115,37 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/system/config": {
|
||||||
|
"get": {
|
||||||
|
"summary": "Returns all config settings",
|
||||||
|
"tags": [
|
||||||
|
"System"
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Key/value pairs of config settings",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Key/value pairs of config settings"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "The operation was not successful",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/GenericErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/system/log-missing-localization": {
|
"/system/log-missing-localization": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Logs a missing localization string",
|
"summary": "Logs a missing localization string",
|
||||||
@ -586,12 +617,12 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "An entity object",
|
"description": "Key/value pairs of userfields",
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Just key/value pairs of userfields"
|
"description": "Key/value pairs of userfields"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -639,7 +670,7 @@
|
|||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"description": "Just key/value pairs of userfields"
|
"description": "Key/value pairs of userfields"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -978,9 +1009,40 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/user/settings": {
|
||||||
|
"get": {
|
||||||
|
"summary": "Returns all settings of the currently logged in user",
|
||||||
|
"tags": [
|
||||||
|
"User settings"
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Key/value pairs of user settings",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Key/value pairs of user settings"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "The operation was not successful",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/GenericErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/user/settings/{settingKey}": {
|
"/user/settings/{settingKey}": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Gets the given setting of the currently logged in user",
|
"summary": "Returns the given setting of the currently logged in user",
|
||||||
"tags": [
|
"tags": [
|
||||||
"User settings"
|
"User settings"
|
||||||
],
|
],
|
||||||
|
@ -143,6 +143,7 @@ $app->group('/api', function(RouteCollectorProxy $group)
|
|||||||
// System
|
// System
|
||||||
$group->get('/system/info', '\Grocy\Controllers\SystemApiController:GetSystemInfo');
|
$group->get('/system/info', '\Grocy\Controllers\SystemApiController:GetSystemInfo');
|
||||||
$group->get('/system/db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime');
|
$group->get('/system/db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime');
|
||||||
|
$group->get('/system/config', '\Grocy\Controllers\SystemApiController:GetConfig');
|
||||||
$group->post('/system/log-missing-localization', '\Grocy\Controllers\SystemApiController:LogMissingLocalization');
|
$group->post('/system/log-missing-localization', '\Grocy\Controllers\SystemApiController:LogMissingLocalization');
|
||||||
|
|
||||||
// Generic entity interaction
|
// Generic entity interaction
|
||||||
@ -167,6 +168,7 @@ $app->group('/api', function(RouteCollectorProxy $group)
|
|||||||
$group->delete('/users/{userId}', '\Grocy\Controllers\UsersApiController:DeleteUser');
|
$group->delete('/users/{userId}', '\Grocy\Controllers\UsersApiController:DeleteUser');
|
||||||
|
|
||||||
// User
|
// User
|
||||||
|
$group->get('/user/settings', '\Grocy\Controllers\UsersApiController:GetUserSettings');
|
||||||
$group->get('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:GetUserSetting');
|
$group->get('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:GetUserSetting');
|
||||||
$group->put('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:SetUserSetting');
|
$group->put('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:SetUserSetting');
|
||||||
|
|
||||||
|
@ -50,6 +50,19 @@ class UsersService extends BaseService
|
|||||||
return $returnUsers;
|
return $returnUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetUserSettinsg($userId)
|
||||||
|
{
|
||||||
|
$settingRow = $this->getDatabase()->user_settings()->where('user_id = :1 AND key = :2', $userId, $settingKey)->fetch();
|
||||||
|
if ($settingRow !== null)
|
||||||
|
{
|
||||||
|
return $settingRow->value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function GetUserSetting($userId, $settingKey)
|
public function GetUserSetting($userId, $settingKey)
|
||||||
{
|
{
|
||||||
$settingRow = $this->getDatabase()->user_settings()->where('user_id = :1 AND key = :2', $userId, $settingKey)->fetch();
|
$settingRow = $this->getDatabase()->user_settings()->where('user_id = :1 AND key = :2', $userId, $settingKey)->fetch();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user