From 3cc1fb40f0c2048060ea6628a13266329f0c7a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Tue, 6 Feb 2024 22:42:25 +0100 Subject: [PATCH] Fixed problem that no datastructures with an parent element could be created/edited via API This fixes issue #512. The error was introduced when trying to allow the modification of attachments/parameters throught the parent element. We need a seperate write scope to the element, or we end up with an infinite loop. --- src/Entity/Attachments/Attachment.php | 4 ++-- src/Entity/Parameters/AbstractParameter.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Entity/Attachments/Attachment.php b/src/Entity/Attachments/Attachment.php index 72075c42..d98cb847 100644 --- a/src/Entity/Attachments/Attachment.php +++ b/src/Entity/Attachments/Attachment.php @@ -77,7 +77,7 @@ use LogicException; new Delete(security: 'is_granted("delete", object)'), ], normalizationContext: ['groups' => ['attachment:read', 'attachment:read:standalone', 'api:basic:read'], 'openapi_definition_name' => 'Read'], - denormalizationContext: ['groups' => ['attachment:write', 'api:basic:write'], 'openapi_definition_name' => 'Write'], + denormalizationContext: ['groups' => ['attachment:write', 'attachment:write:standalone', 'api:basic:write'], 'openapi_definition_name' => 'Write'], )] #[DocumentedAPIProperty(schemaName: 'Attachment-Read', property: 'media_url', type: 'string', nullable: true, description: 'The URL to the file, where the attachment file can be downloaded. This can be an internal or external URL.', @@ -142,7 +142,7 @@ abstract class Attachment extends AbstractNamedDBElement * ORM mapping is done in subclasses (like PartAttachment). * @phpstan-param T|null $element */ - #[Groups(['attachment:read:standalone', 'attachment:write'])] + #[Groups(['attachment:read:standalone', 'attachment:write:standalone'])] protected ?AttachmentContainingDBElement $element = null; #[ORM\Column(type: Types::BOOLEAN)] diff --git a/src/Entity/Parameters/AbstractParameter.php b/src/Entity/Parameters/AbstractParameter.php index ebdbd777..3e090a73 100644 --- a/src/Entity/Parameters/AbstractParameter.php +++ b/src/Entity/Parameters/AbstractParameter.php @@ -87,7 +87,7 @@ use function sprintf; new Delete(security: 'is_granted("delete", object)'), ], normalizationContext: ['groups' => ['parameter:read', 'parameter:read:standalone', 'api:basic:read'], 'openapi_definition_name' => 'Read'], - denormalizationContext: ['groups' => ['parameter:write', 'api:basic:write'], 'openapi_definition_name' => 'Write'], + denormalizationContext: ['groups' => ['parameter:write', 'parameter:write:standalone', 'api:basic:write'], 'openapi_definition_name' => 'Write'], )] #[ApiFilter(LikeFilter::class, properties: ["name", "symbol", "unit", "group", "value_text"])] #[ApiFilter(DateFilter::class, strategy: DateFilter::EXCLUDE_NULL)] @@ -161,7 +161,7 @@ abstract class AbstractParameter extends AbstractNamedDBElement * * @var AbstractDBElement|null the element to which this parameter belongs to */ - #[Groups(['parameter:read:standalone', 'parameter:write'])] + #[Groups(['parameter:read:standalone', 'parameter:write:standalone'])] protected ?AbstractDBElement $element = null; public function __construct()