From 9df20d83bbb58ddfa23367d7fb6325ae94e8cda4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9l=C3=A8ne=20Meneuvrier?= Date: Tue, 7 Feb 2023 10:25:29 +0100 Subject: [PATCH 1/4] 752 : change mail title when no user notifiabme --- src/EventListener/ActivityListener.php | 12 +++++++----- src/Service/NotificationService.php | 5 +++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/EventListener/ActivityListener.php b/src/EventListener/ActivityListener.php index 4df6ab164..f5fc8b45c 100755 --- a/src/EventListener/ActivityListener.php +++ b/src/EventListener/ActivityListener.php @@ -142,8 +142,10 @@ private function sendMail($entity, $mailType) $options['entity'] = $entity; if (!$this->tos->isEmpty()) { if ($entity instanceof Signalement) { + /** @var Signalement $signalement */ $signalement = $entity; } else { + /** @var Signalement $signalement */ $signalement = $entity->getSignalement(); } $uuid = $signalement->getUuid(); @@ -154,15 +156,15 @@ private function sendMail($entity, $mailType) ]); $this->removeCurrentUserEmailForNotification(); - if ($this->tos->isEmpty()) { + if ($this->tos->isEmpty() || (1 === \count($this->tos) && empty($this->tos[0]))) { $this->notifier->send( - NotificationService::TYPE_ERROR_SIGNALEMENT, - $this->parameterBag->get('admin_email'), + NotificationService::TYPE_ERROR_SIGNALEMENT_NO_USER, + $this->parameterBag->get('notifications_email'), [ 'url' => $this->parameterBag->get('host_url'), 'error' => sprintf( - 'Aucun utilisateur est notifiable pour le signalement #%s.', - $signalement->getReference() + 'Aucun utilisateur est notifiable pour le signalement #%s', + $signalement->getReference(), ), ], $signalement->getTerritory() diff --git a/src/Service/NotificationService.php b/src/Service/NotificationService.php index 0c5e259bf..441f34c94 100755 --- a/src/Service/NotificationService.php +++ b/src/Service/NotificationService.php @@ -33,6 +33,7 @@ class NotificationService public const TYPE_NEW_COMMENT_BACK = 10; public const TYPE_CONTACT_FORM = 8; public const TYPE_ERROR_SIGNALEMENT = 9; + public const TYPE_ERROR_SIGNALEMENT_NO_USER = 12; public const TYPE_CRON = 100; public function __construct( @@ -174,6 +175,10 @@ private function config(int $type, array $params = []): array 'template' => 'erreur_signalement_email', 'subject' => 'Une erreur est survenue lors de la création d\'un signalement !', ], + self::TYPE_ERROR_SIGNALEMENT_NO_USER => [ + 'template' => 'erreur_signalement_email', + 'subject' => 'Aucun utilisateur notifiable pour un signalement !', + ], self::TYPE_CRON => [ 'template' => 'cron_email', 'subject' => 'La tache planifiée s\'est bien éxécutée.', From 956873abb3e85b07e10c94e302efdb18bdcf3695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9l=C3=A8ne=20Meneuvrier?= Date: Wed, 8 Feb 2023 14:03:40 +0100 Subject: [PATCH 2/4] 752 : change based on comment --- src/EventListener/ActivityListener.php | 44 +++++++++++++++----------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/EventListener/ActivityListener.php b/src/EventListener/ActivityListener.php index f5fc8b45c..39885792f 100755 --- a/src/EventListener/ActivityListener.php +++ b/src/EventListener/ActivityListener.php @@ -140,14 +140,15 @@ private function sendMail($entity, $mailType) { $options = []; $options['entity'] = $entity; + $sendErrorMail = false; + if ($entity instanceof Signalement) { + /** @var Signalement $signalement */ + $signalement = $entity; + } else { + /** @var Signalement $signalement */ + $signalement = $entity->getSignalement(); + } if (!$this->tos->isEmpty()) { - if ($entity instanceof Signalement) { - /** @var Signalement $signalement */ - $signalement = $entity; - } else { - /** @var Signalement $signalement */ - $signalement = $entity->getSignalement(); - } $uuid = $signalement->getUuid(); $options = array_merge($options, [ 'link' => $this->urlGenerator->generate('back_signalement_view', [ @@ -157,22 +158,27 @@ private function sendMail($entity, $mailType) $this->removeCurrentUserEmailForNotification(); if ($this->tos->isEmpty() || (1 === \count($this->tos) && empty($this->tos[0]))) { - $this->notifier->send( - NotificationService::TYPE_ERROR_SIGNALEMENT_NO_USER, - $this->parameterBag->get('notifications_email'), - [ - 'url' => $this->parameterBag->get('host_url'), - 'error' => sprintf( - 'Aucun utilisateur est notifiable pour le signalement #%s', - $signalement->getReference(), - ), - ], - $signalement->getTerritory() - ); + $sendErrorMail = true; } else { $this->notifier->send($mailType, array_unique($this->tos->toArray()), $options, $signalement->getTerritory()); $this->tos->clear(); } + } else { + $sendErrorMail = true; + } + if ($sendErrorMail) { + $this->notifier->send( + NotificationService::TYPE_ERROR_SIGNALEMENT_NO_USER, + $this->parameterBag->get('notifications_email'), + [ + 'url' => $this->parameterBag->get('host_url'), + 'error' => sprintf( + 'Aucun utilisateur est notifiable pour le signalement #%s', + $signalement->getReference(), + ), + ], + $signalement->getTerritory() + ); } } From cc9c77fdd6756030d50194993591179c2dd19fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9l=C3=A8ne=20Meneuvrier?= Date: Wed, 8 Feb 2023 15:40:13 +0100 Subject: [PATCH 3/4] 752 : fix ci --- .github/workflows/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b3c45df81..09aaf6ac9 100755 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -98,6 +98,11 @@ jobs: php bin/console --env=test doctrine:fixtures:load --no-interaction env: DATABASE_URL: mysql://root:histologe@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/histologe_db + NOTIFICATIONS_EMAIL: notifications@histologe.beta.gouv.fr + CONTACT_EMAIL: contact@histologe.beta.gouv.fr + HISTOLOGE_URL: http://localhost:8080 + SERVER_NAME: localhost:8080 + MAILER_DSN: ${{ secrets.MAILER_DSN_CI }} - name: Run tests run: | From 527ed2886618855e6bdf17a4817269d056081ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9l=C3=A8ne=20Meneuvrier?= Date: Fri, 10 Feb 2023 09:59:58 +0100 Subject: [PATCH 4/4] 752 : filter arraycollection --- src/EventListener/ActivityListener.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/EventListener/ActivityListener.php b/src/EventListener/ActivityListener.php index 39885792f..4ad47e9d2 100755 --- a/src/EventListener/ActivityListener.php +++ b/src/EventListener/ActivityListener.php @@ -157,7 +157,12 @@ private function sendMail($entity, $mailType) ]); $this->removeCurrentUserEmailForNotification(); - if ($this->tos->isEmpty() || (1 === \count($this->tos) && empty($this->tos[0]))) { + + $this->tos = $this->tos->filter(function ($element) { + return '' !== trim($element) && null !== $element; + }); + + if ($this->tos->isEmpty()) { $sendErrorMail = true; } else { $this->notifier->send($mailType, array_unique($this->tos->toArray()), $options, $signalement->getTerritory());