From 7f56b6291ab09ed82dac4d9a91d64ff40258b7ac Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 15 Jun 2026 11:52:44 +0200 Subject: [PATCH] fix(ogcore): permisos DELETE de OUs y borrado de clientes sin plantilla --- composer.json | 3 ++- config/api_platform/OrganizationalUnit.yaml | 5 ++++- src/Controller/OgBoot/PxeBootFile/DeleteAction.php | 2 +- src/State/Processor/ClientProcessor.php | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 63cc9fa..e996e96 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,8 @@ }, "autoload-dev": { "psr-4": { - "App\\Tests\\": "tests/" + "App\\Tests\\": "tests/", + "Functional\\": "tests/Functional/" } }, "replace": { diff --git a/config/api_platform/OrganizationalUnit.yaml b/config/api_platform/OrganizationalUnit.yaml index 00697fa..71063e4 100644 --- a/config/api_platform/OrganizationalUnit.yaml +++ b/config/api_platform/OrganizationalUnit.yaml @@ -28,7 +28,10 @@ resources: groups: ['organizational-unit:patch' ] ApiPlatform\Metadata\Post: security: 'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ORGANIZATIONAL_UNIT_ADMIN")' - ApiPlatform\Metadata\Delete: ~ + ApiPlatform\Metadata\Delete: + provider: App\State\Provider\OrganizationalUnitProvider + security: 'is_granted("ROLE_SUPER_ADMIN") or (is_granted("ROLE_ORGANIZATIONAL_UNIT_ADMIN") and object.getCreatedBy() == user.getUserIdentifier())' + securityMessage: 'You can only delete organizational units you created.' change_parent: class: ApiPlatform\Metadata\Post method: POST diff --git a/src/Controller/OgBoot/PxeBootFile/DeleteAction.php b/src/Controller/OgBoot/PxeBootFile/DeleteAction.php index 0a957a8..201f29d 100644 --- a/src/Controller/OgBoot/PxeBootFile/DeleteAction.php +++ b/src/Controller/OgBoot/PxeBootFile/DeleteAction.php @@ -25,7 +25,7 @@ class DeleteAction extends AbstractOgBootController { $response = $this->createRequest('DELETE', '/ogboot/v1/pxes/'.$mac); - if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) { + if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) { return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); } diff --git a/src/State/Processor/ClientProcessor.php b/src/State/Processor/ClientProcessor.php index 5ad7ffa..9a0945d 100644 --- a/src/State/Processor/ClientProcessor.php +++ b/src/State/Processor/ClientProcessor.php @@ -134,7 +134,9 @@ readonly class ClientProcessor implements ProcessorInterface if ($client->getSubnet()) { $this->deleteHostAction->__invoke($client->getSubnet(), $client->getUuid()); } - $this->deletePxeAction->__invoke($client->getMac()); + if ($client->getMac() && $client->getTemplate()) { + $this->deletePxeAction->__invoke($client->getMac()); + } } $this->clientRepository->delete($client);