From 87cdf2e53b40c3bc9b2ce916ec58c486f890b3b9 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 22 Aug 2023 14:24:40 +0200 Subject: [PATCH 01/24] Fixed: [export] bad type in form of EmergencyFilter and CalendarRangeFilter --- .../Export/Filter/ACPFilters/EmergencyFilter.php | 6 +++--- .../Export/Filter/CalendarRangeFilter.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/EmergencyFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/EmergencyFilter.php index 807ba3903..66ab40e48 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/EmergencyFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/EmergencyFilter.php @@ -22,11 +22,11 @@ use Symfony\Contracts\Translation\TranslatorInterface; class EmergencyFilter implements FilterInterface { private const CHOICES = [ - 'activity is emergency' => true, - 'activity is not emergency' => false, + 'activity is emergency' => 'true', + 'activity is not emergency' => 'false', ]; - private const DEFAULT_CHOICE = false; + private const DEFAULT_CHOICE = 'false'; private TranslatorInterface $translator; diff --git a/src/Bundle/ChillCalendarBundle/Export/Filter/CalendarRangeFilter.php b/src/Bundle/ChillCalendarBundle/Export/Filter/CalendarRangeFilter.php index 5ffb7c01f..84ec77e6b 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Filter/CalendarRangeFilter.php +++ b/src/Bundle/ChillCalendarBundle/Export/Filter/CalendarRangeFilter.php @@ -29,11 +29,11 @@ use Symfony\Contracts\Translation\TranslatorInterface; class CalendarRangeFilter implements FilterInterface { private const CHOICES = [ - 'Not made within a calendar range' => true, - 'Made within a calendar range' => false, + 'Not made within a calendar range' => 'true', + 'Made within a calendar range' => 'false', ]; - private const DEFAULT_CHOICE = false; + private const DEFAULT_CHOICE = 'false'; private TranslatorInterface $translator; From 9ccbba2debbeefc76192bd412374b5a75ba8a731 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 22 Aug 2023 14:28:35 +0200 Subject: [PATCH 02/24] add changie --- .changes/unreleased/Fixed-20230822-142809.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixed-20230822-142809.yaml diff --git a/.changes/unreleased/Fixed-20230822-142809.yaml b/.changes/unreleased/Fixed-20230822-142809.yaml new file mode 100644 index 000000000..b22477135 --- /dev/null +++ b/.changes/unreleased/Fixed-20230822-142809.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: "Corrects a typing error in 2 filters, which caused an \nerror when trying to + reedit a saved export\n\n" +time: 2023-08-22T14:28:09.485466139+02:00 +custom: + Issue: "135" From dcae15e8d86d9e45f8e33d4ad1c3398fe7ce4b75 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 24 Aug 2023 15:14:47 +0200 Subject: [PATCH 03/24] Fixed: [notificationMailer] invert 'if continue' condition inside foreach loop --- .changes/unreleased/Fixed-20230824-152038.yaml | 6 ++++++ .../Notification/Email/NotificationMailer.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Fixed-20230824-152038.yaml diff --git a/.changes/unreleased/Fixed-20230824-152038.yaml b/.changes/unreleased/Fixed-20230824-152038.yaml new file mode 100644 index 000000000..656bd4752 --- /dev/null +++ b/.changes/unreleased/Fixed-20230824-152038.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: Fix who receive reply notification when adding comment (recipees must receive + it, and sender not). +time: 2023-08-24T15:20:38.472382872+02:00 +custom: + Issue: "137" diff --git a/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php b/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php index 5290492b1..a652231ac 100644 --- a/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php +++ b/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php @@ -46,7 +46,7 @@ class NotificationMailer [$comment->getNotification()->getSender()] ) as $dest ) { - if (null === $dest->getEmail() || $comment->getCreatedBy() !== $dest) { + if (null !== $dest->getEmail() && $comment->getCreatedBy() === $dest) { continue; } $email = new TemplatedEmail(); From f3fbd5314a0d5c0bb87249e6974cb9260aea489d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 6 Sep 2023 15:47:45 +0200 Subject: [PATCH 04/24] Add test to NotificationMailer::postPersistComment --- .../Email/NotificationMailerTest.php | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php diff --git a/src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php b/src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php new file mode 100644 index 000000000..47629b4b4 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php @@ -0,0 +1,78 @@ +expectNotToPerformAssertions(); + $user1 = (new User())->setEmail('user1@foo.com'); + $user2 = (new User())->setEmail('user2@foo.com'); + $user3 = (new User())->setEmail('user3@foo.com'); + + $notification = new Notification(); + $notification + ->setTitle('test notification') + ->setSender($user1) + ->addAddressee($user2) + ->addAddressee($user3) + ; + + $comment = (new NotificationComment()) + ->setContent("foo bar baz") + ->setCreatedBy($user2) + ; + $notification->addComment($comment); + + $mailer = $this->prophesize(MailerInterface::class); + + // a mail only to user1 and user3 should have been sent + $mailer->send(Argument::that(function (Email $email) { + foreach ($email->getTo() as $address) { + if ($address->getAddress() === 'user1@foo.com' || $address->getAddress() === 'user3@foo.com') { + return true; + } + } + + return false; + })); + + $objectManager = $this->prophesize(EntityManagerInterface::class); + + $mailer = $this->buildNotificationMailer($mailer->reveal()); + $mailer->postPersistComment($comment, new PostPersistEventArgs($comment, $objectManager->reveal())); + } + + private function buildNotificationMailer( + MailerInterface $mailer = null, + ): NotificationMailer + { + return new NotificationMailer( + $mailer, + new NullLogger(), + new Translator('fr') + ); + } + + + +} From 40a72d9fca746704af7038190dfa633b0d5ce5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 6 Sep 2023 15:47:59 +0200 Subject: [PATCH 05/24] NotificationMailer: send to correct destinees --- .../unreleased/Fixed-20230824-152038.yaml | 6 ------ .../unreleased/Fixed-20230906-154856.yaml | 5 +++++ .../Notification/Email/NotificationMailer.php | 19 ++++++++++++------- 3 files changed, 17 insertions(+), 13 deletions(-) delete mode 100644 .changes/unreleased/Fixed-20230824-152038.yaml create mode 100644 .changes/unreleased/Fixed-20230906-154856.yaml diff --git a/.changes/unreleased/Fixed-20230824-152038.yaml b/.changes/unreleased/Fixed-20230824-152038.yaml deleted file mode 100644 index 656bd4752..000000000 --- a/.changes/unreleased/Fixed-20230824-152038.yaml +++ /dev/null @@ -1,6 +0,0 @@ -kind: Fixed -body: Fix who receive reply notification when adding comment (recipees must receive - it, and sender not). -time: 2023-08-24T15:20:38.472382872+02:00 -custom: - Issue: "137" diff --git a/.changes/unreleased/Fixed-20230906-154856.yaml b/.changes/unreleased/Fixed-20230906-154856.yaml new file mode 100644 index 000000000..73fb2dc48 --- /dev/null +++ b/.changes/unreleased/Fixed-20230906-154856.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: Do not send an email to creator twice when adding a comment to a notification +time: 2023-09-06T15:48:56.991246312+02:00 +custom: + Issue: "" diff --git a/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php b/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php index a652231ac..8facf00b9 100644 --- a/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php +++ b/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php @@ -40,13 +40,18 @@ class NotificationMailer public function postPersistComment(NotificationComment $comment, PostPersistEventArgs $eventArgs): void { - foreach ( - array_merge( - $comment->getNotification()->getAddressees()->toArray(), - [$comment->getNotification()->getSender()] - ) as $dest - ) { - if (null !== $dest->getEmail() && $comment->getCreatedBy() === $dest) { + $dests = [$comment->getNotification()->getSender(), ...$comment->getNotification()->getAddressees()->toArray()]; + + $uniqueDests = []; + foreach ($dests as $dest) { + // avoid duplication + if (in_array(spl_object_hash($dest), $uniqueDests, true)) { + continue; + } + $uniqueDests[] = spl_object_hash($dest); + + // do not send if the sender does not have any email, nor to the creator of the comment + if (null === $dest->getEmail() || $comment->getCreatedBy() === $dest) { continue; } $email = new TemplatedEmail(); From 53cc43f8d30ace37ad07bb027cb15547736886b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 6 Sep 2023 15:55:01 +0200 Subject: [PATCH 06/24] NotificationMailer: add tests when user does not have any email --- .../Email/NotificationMailerTest.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php b/src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php index 47629b4b4..4c1ae5d42 100644 --- a/src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php @@ -62,6 +62,46 @@ class NotificationMailerTest extends TestCase $mailer->postPersistComment($comment, new PostPersistEventArgs($comment, $objectManager->reveal())); } + public function testPostPersistCommentDestWithNullEmail(): void + { + $this->expectNotToPerformAssertions(); + $user1 = (new User())->setEmail('user1@foo.com'); + $user2 = (new User())->setEmail('user2@foo.com'); + $user3 = (new User())->setEmail(null); + + $notification = new Notification(); + $notification + ->setTitle('test notification') + ->setSender($user1) + ->addAddressee($user2) + ->addAddressee($user3) + ; + + $comment = (new NotificationComment()) + ->setContent("foo bar baz") + ->setCreatedBy($user2) + ; + $notification->addComment($comment); + + $mailer = $this->prophesize(MailerInterface::class); + + // a mail only to user1 and user3 should have been sent + $mailer->send(Argument::that(function (Email $email) { + foreach ($email->getTo() as $address) { + if ($address->getAddress() === 'user1@foo.com') { + return true; + } + } + + return false; + })); + + $objectManager = $this->prophesize(EntityManagerInterface::class); + + $mailer = $this->buildNotificationMailer($mailer->reveal()); + $mailer->postPersistComment($comment, new PostPersistEventArgs($comment, $objectManager->reveal())); + } + private function buildNotificationMailer( MailerInterface $mailer = null, ): NotificationMailer From 34ee2b3ba5f59677ea064f10cef057b177c0fdb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 6 Sep 2023 16:18:28 +0200 Subject: [PATCH 07/24] Fix new CS --- .../ChillEventBundle/Search/EventSearch.php | 2 +- .../Email/NotificationMailerTest.php | 30 +++++++++++++------ .../Controller/PersonController.php | 2 +- .../AccompanyingPeriodContextTest.php | 2 +- .../DocGenerator/PersonContextTest.php | 2 +- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Bundle/ChillEventBundle/Search/EventSearch.php b/src/Bundle/ChillEventBundle/Search/EventSearch.php index 6bb3d435d..504d04130 100644 --- a/src/Bundle/ChillEventBundle/Search/EventSearch.php +++ b/src/Bundle/ChillEventBundle/Search/EventSearch.php @@ -152,7 +152,7 @@ class EventSearch extends AbstractSearch $orWhere = $qb->expr()->orX(); foreach ($reachableCenters as $center) { - $n = $n+1; + $n = $n + 1; $circles = $this->authorizationHelper->getReachableScopes( $this->security->getUser(), 'CHILL_EVENT_SEE', diff --git a/src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php b/src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php index 4c1ae5d42..19da87b79 100644 --- a/src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Notification/Email/NotificationMailerTest.php @@ -1,5 +1,14 @@ setSender($user1) ->addAddressee($user2) ->addAddressee($user3) - ; + ; $comment = (new NotificationComment()) ->setContent("foo bar baz") @@ -47,14 +60,14 @@ class NotificationMailerTest extends TestCase // a mail only to user1 and user3 should have been sent $mailer->send(Argument::that(function (Email $email) { - foreach ($email->getTo() as $address) { - if ($address->getAddress() === 'user1@foo.com' || $address->getAddress() === 'user3@foo.com') { - return true; - } + foreach ($email->getTo() as $address) { + if ($address->getAddress() === 'user1@foo.com' || $address->getAddress() === 'user3@foo.com') { + return true; } + } - return false; - })); + return false; + })); $objectManager = $this->prophesize(EntityManagerInterface::class); @@ -104,8 +117,7 @@ class NotificationMailerTest extends TestCase private function buildNotificationMailer( MailerInterface $mailer = null, - ): NotificationMailer - { + ): NotificationMailer { return new NotificationMailer( $mailer, new NullLogger(), diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonController.php b/src/Bundle/ChillPersonBundle/Controller/PersonController.php index 2d4732289..ce6d6bb38 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonController.php @@ -214,7 +214,7 @@ final class PersonController extends AbstractController { $person = new Person(); - $authorizedCenters =$this->authorizationHelper->getReachableCenters($this->getUser(), PersonVoter::CREATE); + $authorizedCenters = $this->authorizationHelper->getReachableCenters($this->getUser(), PersonVoter::CREATE); if (1 === count($authorizedCenters)) { $person->setCenter($authorizedCenters[0]); diff --git a/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/AccompanyingPeriodContextTest.php b/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/AccompanyingPeriodContextTest.php index f9f888999..b5f656702 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/AccompanyingPeriodContextTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/AccompanyingPeriodContextTest.php @@ -108,7 +108,7 @@ class AccompanyingPeriodContextTest extends KernelTestCase ): void { $context = $this->buildContext(); $template = new DocGeneratorTemplate(); - $template->setName(["fr" =>"test"])->setContext(AccompanyingPeriodContext::class) + $template->setName(["fr" => "test"])->setContext(AccompanyingPeriodContext::class) ->setDescription("description")->setActive(true) ->setOptions($options); diff --git a/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextTest.php b/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextTest.php index 71fce8c92..fa99a5363 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextTest.php @@ -102,7 +102,7 @@ final class PersonContextTest extends KernelTestCase self::$container->get(ThirdPartyRepository::class) ); $template = new DocGeneratorTemplate(); - $template->setName(["fr" =>"test"])->setContext(AccompanyingPeriodContext::class) + $template->setName(["fr" => "test"])->setContext(AccompanyingPeriodContext::class) ->setDescription("description")->setActive(true) ->setOptions($options); From 16fcd03a02328ae1b6bb5fe00a04eb064b109943 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 24 Aug 2023 14:32:50 +0200 Subject: [PATCH 08/24] Fixed: [vuejs] fix missing translation in HouseholdMembersEditor component --- .../vuejs/HouseholdMembersEditor/components/PersonComment.vue | 2 +- .../Resources/public/vuejs/HouseholdMembersEditor/js/i18n.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/components/PersonComment.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/components/PersonComment.vue index cb9a02d51..8f61a74d1 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/components/PersonComment.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/components/PersonComment.vue @@ -1,7 +1,7 @@