From 7fb0e443075d6823add27da2b304499eba3b25a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 28 May 2022 01:45:11 +0200 Subject: [PATCH 1/5] fix null value for calendar in private comments --- .../migrations/Version20220527234046.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/Bundle/ChillCalendarBundle/migrations/Version20220527234046.php diff --git a/src/Bundle/ChillCalendarBundle/migrations/Version20220527234046.php b/src/Bundle/ChillCalendarBundle/migrations/Version20220527234046.php new file mode 100644 index 000000000..c53f82661 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/migrations/Version20220527234046.php @@ -0,0 +1,30 @@ +addSql('UPDATE chill_calendar.calendar SET privateComment_comments=\'{}\' WHERE privateComment_comments IS NULL'); + $this->addSql('ALTER TABLE chill_calendar.calendar ALTER COLUMN privateComment_comments SET NOT NULL'); + $this->addSql('ALTER TABLE chill_calendar.calendar ALTER COLUMN privateComment_comments SET DEFAULT \'{}\''); + + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_calendar.calendar ALTER COLUMN privateComment_comments DROP NOT NULL'); + $this->addSql('ALTER TABLE chill_calendar.calendar ALTER COLUMN privateComment_comments SET DEFAULT NULL'); + } +} From 679d19e2a13a2b66155273a6cfa7eaf4b673096d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 30 May 2022 10:01:27 +0200 Subject: [PATCH 2/5] allow null values for private comment --- .../Entity/Embeddable/PrivateCommentEmbeddable.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php b/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php index 09a35324e..00e0f29d7 100644 --- a/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php +++ b/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php @@ -54,9 +54,9 @@ class PrivateCommentEmbeddable return $this; } - public function setCommentForUser(User $user, string $content): self + public function setCommentForUser(User $user, ?string $content): self { - $this->comments[$user->getId()] = trim($content); + $this->comments[$user->getId()] = trim((string) $content); return $this; } From 0849b2d5f401d75de119f4691ee442f457e15153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 30 May 2022 21:16:40 +0200 Subject: [PATCH 3/5] docgen: fix title of origin --- src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php | 4 ++++ .../ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php | 7 +++---- .../Normalizer/AccompanyingPeriodDocGenNormalizer.php | 1 + .../Normalizer/AccompanyingPeriodOriginNormalizer.php | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index da1709f48..ab51bbf85 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -692,6 +692,10 @@ class AccompanyingPeriod implements return [[self::STEP_DRAFT, self::STEP_CONFIRMED]]; } + if ($this->getStep() === self::STEP_CLOSED) { + return [[self::STEP_DRAFT, self::STEP_CONFIRMED, self::STEP_CLOSED]]; + } + throw new LogicException('no validation group permitted with this step: ' . $this->getStep()); } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php index 7a1114b3e..492d7d995 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php @@ -14,7 +14,6 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; use DateTimeImmutable; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation as Serializer; -use Symfony\Component\Serializer\Annotation\Groups; /** * @ORM\Entity @@ -31,20 +30,20 @@ class Origin * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") - * @Groups({"read", "docgen:read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ private ?int $id = null; /** * @ORM\Column(type="json") - * @Groups({"read", "docgen:read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Context({"is-translatable": true}, groups={"docgen:read"}) */ private array $label = []; /** * @ORM\Column(type="date_immutable", nullable=true) - * @Groups({"read"}) + * @Serializer\Groups({"read"}) */ private ?DateTimeImmutable $noActiveAfter = null; diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php index fab2a022d..79adc560c 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php @@ -121,6 +121,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf 'type' => 'accompanying_period', 'isNull' => false, 'closingDate' => $this->normalizer->normalize($period->getClosingDate(), $format, $dateContext), + 'closingMotive' => $this->normalizer->normalize($period->getClosingMotive(), $format, array_merge($context, ['docgen:expects' => AccompanyingPeriod\ClosingMotive::class])), 'confidential' => $period->isConfidential(), 'createdAt' => $this->normalizer->normalize($period->getCreatedAt(), $format, $dateContext), 'createdBy' => $this->normalizer->normalize($period->getCreatedBy(), $format, $userContext), diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodOriginNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodOriginNormalizer.php index 66f65b67b..6cc3d446b 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodOriginNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodOriginNormalizer.php @@ -35,6 +35,6 @@ final class AccompanyingPeriodOriginNormalizer implements NormalizerInterface public function supportsNormalization($data, $format = null): bool { - return $data instanceof Origin; + return $data instanceof Origin && $format === 'json'; } } From a4e3ffbe27f85a92de4ef2630be71617da8f0856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 30 May 2022 22:41:47 +0200 Subject: [PATCH 4/5] fix cs --- .../migrations/Version20220527234046.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/migrations/Version20220527234046.php b/src/Bundle/ChillCalendarBundle/migrations/Version20220527234046.php index c53f82661..9cb68932e 100644 --- a/src/Bundle/ChillCalendarBundle/migrations/Version20220527234046.php +++ b/src/Bundle/ChillCalendarBundle/migrations/Version20220527234046.php @@ -1,5 +1,12 @@ addSql('ALTER TABLE chill_calendar.calendar ALTER COLUMN privateComment_comments DROP NOT NULL'); + $this->addSql('ALTER TABLE chill_calendar.calendar ALTER COLUMN privateComment_comments SET DEFAULT NULL'); + } + public function getDescription(): string { return ''; @@ -19,12 +32,5 @@ final class Version20220527234046 extends AbstractMigration $this->addSql('UPDATE chill_calendar.calendar SET privateComment_comments=\'{}\' WHERE privateComment_comments IS NULL'); $this->addSql('ALTER TABLE chill_calendar.calendar ALTER COLUMN privateComment_comments SET NOT NULL'); $this->addSql('ALTER TABLE chill_calendar.calendar ALTER COLUMN privateComment_comments SET DEFAULT \'{}\''); - - } - - public function down(Schema $schema): void - { - $this->addSql('ALTER TABLE chill_calendar.calendar ALTER COLUMN privateComment_comments DROP NOT NULL'); - $this->addSql('ALTER TABLE chill_calendar.calendar ALTER COLUMN privateComment_comments SET DEFAULT NULL'); } } From f92cef02cff90455bf0a67e4c51c898406478bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 30 May 2022 22:43:50 +0200 Subject: [PATCH 5/5] fix creating a new AccompanyingPeriodWorkEvaluationDocument when replacing the document (the workflow was lost) --- CHANGELOG.md | 11 +- .../vuejs/AccompanyingCourseWorkEdit/store.js | 8 + .../AccompanyingPeriodOriginNormalizer.php | 2 +- ...anyingPeriodWorkEvaluationDenormalizer.php | 14 -- ...ngPeriodWorkEvaluationDenormalizerTest.php | 140 ++++++++++++++++++ 5 files changed, 158 insertions(+), 17 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizerTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f61f05de..f6b15672e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,15 @@ and this project adheres to ## Unreleased + +## Test releases + +### 2022-05-30 + +* fix creating a new AccompanyingPeriodWorkEvaluationDocument when replacing the document (the workflow was lost) + +### 2022-05-27 + * [storedobject] add title field on StoredObject entity + use it in activity documents (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/604) * [main] add a "read more..." on comment embeddable when overflown (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/604) * [person] add closing motive to closed acc course (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/603) @@ -28,8 +37,6 @@ and this project adheres to * [address] can add extra address info even if noAddress (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/576) -## Test releases - ### 2022-05-06 * [person] add civility when creating a person (with the on-the-fly component or in the php form) (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/557) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js index caec4fd05..4b997d002 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js @@ -232,6 +232,14 @@ const store = createStore({ return; } + let doc = evaluation.documents.find(d => d.key === payload.oldDocument.key); + + if (typeof doc === 'undefined') { + console.error('doc not found'); + } + + doc.storedObject = payload.document.storedObject; + return; let newDocument = Object.assign( payload.document, { key: evaluation.documents.length + 1, diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodOriginNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodOriginNormalizer.php index 6cc3d446b..ca7589e79 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodOriginNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodOriginNormalizer.php @@ -35,6 +35,6 @@ final class AccompanyingPeriodOriginNormalizer implements NormalizerInterface public function supportsNormalization($data, $format = null): bool { - return $data instanceof Origin && $format === 'json'; + return $data instanceof Origin && 'json' === $format; } } diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php index 4680d9fa7..77e289e6a 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php @@ -13,8 +13,6 @@ namespace Chill\PersonBundle\Serializer\Normalizer; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; -use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; -use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\ContextAwareDenormalizerInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; @@ -35,18 +33,6 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm use ObjectToPopulateTrait; - private EntityManagerInterface $em; - - private AccompanyingPeriodWorkRepository $workRepository; - - public function __construct( - AccompanyingPeriodWorkRepository $workRepository, - EntityManagerInterface $em - ) { - $this->workRepository = $workRepository; - $this->em = $em; - } - public function denormalize($data, $type, $format = null, array $context = []) { $evaluation = $this->denormalizer->denormalize($data, $type, $format, array_merge( diff --git a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizerTest.php new file mode 100644 index 000000000..f46e76932 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizerTest.php @@ -0,0 +1,140 @@ +markTestIncomplete('not yet finished'); + $evaluation = new AccompanyingPeriodWorkEvaluation(); + $doc = new AccompanyingPeriodWorkEvaluationDocument(); + $doc->setStoredObject($storedObject = new StoredObject()); + $reflectionProperty = new ReflectionProperty(AccompanyingPeriodWorkEvaluationDocument::class, 'id'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($doc, 1); + + $evaluation->addDocument($doc); + + $data = json_decode(self::ENCODED_DATA); + $context = + [AbstractNormalizer::OBJECT_TO_POPULATE => $evaluation, 'groups' => ['write']]; + + $denormalizer = new AccompanyingPeriodWorkEvaluationDenormalizer(); + + /* + $this->assertTrue( + $denormalizer->supportsDenormalization( + $data, + AccompanyingPeriodWorkEvaluation::class, + 'json', + $context + ) + ); + */ + + $denormalizedEvaluation = $denormalizer->denormalize( + $data, + AccompanyingPeriodWorkEvaluation::class, + 'json', + $context + ); + + $this->assertSame($evaluation, $denormalizedEvaluation); + $this->assertCount(1, $evaluation->getDocuments()); + $this->assertSame($doc, $evaluation->getDocuments()->first()); + $this->assertNotSame($storedObject, $evaluation->getDocuments()->first()->getStoredObject()); + } +}