mirror of
https://github.com/grocy/grocy.git
synced 2026-04-07 05:16:15 +02:00
Allow only admin users to create custom API-Keys
This commit is contained in:
parent
1546a823c5
commit
e3666cfb4b
|
|
@ -13,6 +13,9 @@ class GenericEntityApiController extends BaseApiController
|
||||||
|
|
||||||
if ($this->IsValidEntity($args['entity']))
|
if ($this->IsValidEntity($args['entity']))
|
||||||
{
|
{
|
||||||
|
if($this->IsEntityWithEditRequiresAdmin($args['entity']))
|
||||||
|
User::checkPermission($request, User::PERMISSION_ADMIN);
|
||||||
|
|
||||||
$requestBody = $request->getParsedBody();
|
$requestBody = $request->getParsedBody();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
@ -49,6 +52,8 @@ class GenericEntityApiController extends BaseApiController
|
||||||
|
|
||||||
if ($this->IsValidEntity($args['entity']))
|
if ($this->IsValidEntity($args['entity']))
|
||||||
{
|
{
|
||||||
|
if($this->IsEntityWithEditRequiresAdmin($args['entity']))
|
||||||
|
User::checkPermission($request, User::PERMISSION_ADMIN);
|
||||||
$row = $this->getDatabase()->{$args['entity']}
|
$row = $this->getDatabase()->{$args['entity']}
|
||||||
($args['objectId']);
|
($args['objectId']);
|
||||||
$row->delete();
|
$row->delete();
|
||||||
|
|
@ -68,6 +73,8 @@ class GenericEntityApiController extends BaseApiController
|
||||||
|
|
||||||
if ($this->IsValidEntity($args['entity']))
|
if ($this->IsValidEntity($args['entity']))
|
||||||
{
|
{
|
||||||
|
if($this->IsEntityWithEditRequiresAdmin($args['entity']))
|
||||||
|
User::checkPermission($request, User::PERMISSION_ADMIN);
|
||||||
$requestBody = $request->getParsedBody();
|
$requestBody = $request->getParsedBody();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
@ -223,6 +230,10 @@ class GenericEntityApiController extends BaseApiController
|
||||||
{
|
{
|
||||||
parent::__construct($container);
|
parent::__construct($container);
|
||||||
}
|
}
|
||||||
|
private function IsEntityWithEditRequiresAdmin($entity)
|
||||||
|
{
|
||||||
|
return !in_array($entity, $this->getOpenApiSpec()->components->internalSchemas->EntityEditRequiresAdmin->enum);
|
||||||
|
}
|
||||||
|
|
||||||
private function IsEntityWithPreventedListing($entity)
|
private function IsEntityWithPreventedListing($entity)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3483,6 +3483,12 @@
|
||||||
"meal_plan"
|
"meal_plan"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"EntityEditRequiresAdmin": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"api_keys"
|
||||||
|
]
|
||||||
|
},
|
||||||
"StockTransactionType": {
|
"StockTransactionType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user