mirror of
https://github.com/grocy/grocy.git
synced 2026-04-06 21:06: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->IsEntityWithEditRequiresAdmin($args['entity']))
|
||||
User::checkPermission($request, User::PERMISSION_ADMIN);
|
||||
|
||||
$requestBody = $request->getParsedBody();
|
||||
|
||||
try
|
||||
|
|
@ -49,6 +52,8 @@ class GenericEntityApiController extends BaseApiController
|
|||
|
||||
if ($this->IsValidEntity($args['entity']))
|
||||
{
|
||||
if($this->IsEntityWithEditRequiresAdmin($args['entity']))
|
||||
User::checkPermission($request, User::PERMISSION_ADMIN);
|
||||
$row = $this->getDatabase()->{$args['entity']}
|
||||
($args['objectId']);
|
||||
$row->delete();
|
||||
|
|
@ -68,6 +73,8 @@ class GenericEntityApiController extends BaseApiController
|
|||
|
||||
if ($this->IsValidEntity($args['entity']))
|
||||
{
|
||||
if($this->IsEntityWithEditRequiresAdmin($args['entity']))
|
||||
User::checkPermission($request, User::PERMISSION_ADMIN);
|
||||
$requestBody = $request->getParsedBody();
|
||||
|
||||
try
|
||||
|
|
@ -223,6 +230,10 @@ class GenericEntityApiController extends BaseApiController
|
|||
{
|
||||
parent::__construct($container);
|
||||
}
|
||||
private function IsEntityWithEditRequiresAdmin($entity)
|
||||
{
|
||||
return !in_array($entity, $this->getOpenApiSpec()->components->internalSchemas->EntityEditRequiresAdmin->enum);
|
||||
}
|
||||
|
||||
private function IsEntityWithPreventedListing($entity)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3483,6 +3483,12 @@
|
|||
"meal_plan"
|
||||
]
|
||||
},
|
||||
"EntityEditRequiresAdmin": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"api_keys"
|
||||
]
|
||||
},
|
||||
"StockTransactionType": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user