From 91ba08dfa14d774695c306c7b918d42de38387aa Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 4 Feb 2022 10:34:32 +0100 Subject: [PATCH 1/3] accompanying course: normalize the requestor entity --- .../AccompanyingCourseApiController.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php index c66488869..10f733307 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php @@ -234,17 +234,20 @@ final class AccompanyingCourseApiController extends ApiController $requestor = null; $exceptions = []; - foreach ([Person::class, ThirdParty::class] as $class) { - try { - $requestor = $this->getSerializer() - ->deserialize($request->getContent(), $class, $_format, []); - } catch (RuntimeException $e) { - $exceptions[] = $e; + try { + $contentAsArray = json_decode($request->getContent(), true); + $entityType = $contentAsArray['type']; + if ($entityType === 'person') { + $requestor = $this->getSerializer()->deserialize($request->getContent(), Person::class, $_format, []); + } elseif ($entityType === 'thirdparty') { + $requestor = $this->getSerializer()->deserialize($request->getContent(), ThirdParty::class, $_format, []); } + } catch (RuntimeException $e) { + $exceptions[] = $e; } if (null === $requestor) { - throw new BadRequestException('Could not find any person or requestor', 0, $exceptions[0]); + throw new BadRequestException('Could not find any person or thirdparty', 0, null); } $accompanyingPeriod->setRequestor($requestor); From f43e216e13cc56c6501991115117373d53cb2e88 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 11 Feb 2022 10:53:05 +0100 Subject: [PATCH 2/3] fix normalisation of AccompanyingCourse requestor api --- .../Normalizer/DiscriminatedObjectDenormalizer.php | 3 ++- .../Controller/AccompanyingCourseApiController.php | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/DiscriminatedObjectDenormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/DiscriminatedObjectDenormalizer.php index 77f14c8da..76ba52a3d 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/DiscriminatedObjectDenormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/DiscriminatedObjectDenormalizer.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Serializer\Normalizer; use LogicException; +use Symfony\Component\Serializer\Exception\NotNormalizableValueException; use Symfony\Component\Serializer\Exception\RuntimeException; use Symfony\Component\Serializer\Normalizer\ContextAwareDenormalizerInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; @@ -44,7 +45,7 @@ class DiscriminatedObjectDenormalizer implements ContextAwareDenormalizerInterfa if ($this->denormalizer->supportsDenormalization($data, $localType, $format)) { try { return $this->denormalizer->denormalize($data, $localType, $format, $context); - } catch (RuntimeException $e) { + } catch (RuntimeException|NotNormalizableValueException $e) { $lastException = $e; } } diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php index 10f733307..3da40db4c 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Serializer\Model\Collection; use Chill\MainBundle\Serializer\Model\Counter; +use Chill\MainBundle\Serializer\Normalizer\DiscriminatedObjectDenormalizer; use Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralsSuggestionInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; @@ -235,13 +236,12 @@ final class AccompanyingCourseApiController extends ApiController $exceptions = []; try { - $contentAsArray = json_decode($request->getContent(), true); - $entityType = $contentAsArray['type']; - if ($entityType === 'person') { - $requestor = $this->getSerializer()->deserialize($request->getContent(), Person::class, $_format, []); - } elseif ($entityType === 'thirdparty') { - $requestor = $this->getSerializer()->deserialize($request->getContent(), ThirdParty::class, $_format, []); - } + $requestor = $this->getSerializer()->deserialize( + $request->getContent(), + '@multi', + $_format, + [DiscriminatedObjectDenormalizer::ALLOWED_TYPES => [Person::class, ThirdParty::class]] + ); } catch (RuntimeException $e) { $exceptions[] = $e; } From 861abe708b72673523cd89a37dba80b52f71d8cc Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 11 Feb 2022 10:55:37 +0100 Subject: [PATCH 3/3] upd CHANGELOG --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b00be8bc..5e33ffee0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ## Unreleased +* fix normalisation of accompanying course requestor api (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/378) * renommer "dossier numéro" en "parcours numéro" dans les résultats de recherche * renomme date de début en date d'ouverture dans le formulaire parcours * [homepage widget] improve content tables, improve counter pluralization with style on number @@ -19,7 +20,7 @@ and this project adheres to * [parcours]: validation + message for closing parcours adjusted. * [household]: household composition double edit button replaced by a delete action (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/426) [fast_actions] improve fast-actions buttons override mechanism, fix https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/413 -[homepage widget] add vue homepage_widget with asynchone loading, give a global view resume of the user concerned actions, notifications, etc. +[homepage widget] add vue homepage_widget with asynchone loading, give a global view resume of the user concerned actions, notifications, etc. * [person]: Comment on marital status is possible even if marital status is not defined (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/421) * [parcours]: In the list of person results the requestor is not displayed if defined as anonymous (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/424) * [bugfix]: modal closes and newly created person/thirdparty is selected when multiple persons/thirdparties are created through the modal (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/429) @@ -27,7 +28,7 @@ and this project adheres to * [workflow][notification] improve how notifications and workflows are 'attached' to entities: contextual list, counter, buttons and vue modal * [AddAddress] disable multiselect search, and rely only on most pertinent Cities and Street computed backend * [fast_actions] improve fast-actions buttons override mechanism, fix https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/413 -* [homepage widget] add vue homepage_widget with asynchone loading, give a global view resume of the user concerned actions, notifications, etc. +* [homepage widget] add vue homepage_widget with asynchone loading, give a global view resume of the user concerned actions, notifications, etc. ## Test releases @@ -79,7 +80,7 @@ and this project adheres to * [popover] add popover html popup mechanism (used by workflow breadcrumb) * [templates] improve updatedBy macro in item metadatas * [parcours]: bug fix when comment is pinned all other comments remain in the collection (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/385) -* [workflow] +* [workflow] * add My workflow section with my opened subscriptions * apply workflow on documents, accompanyingCourseWork and Evaluations * [wopi-link] a new vue component allow to open wopi link in a fullscreen chill-themed modal