Skip to content

Commit

Permalink
Merge pull request #892 from MTES-MCT/feature/752-bo-changer-le-titre…
Browse files Browse the repository at this point in the history
…-du-mail-en-cas-d-absence-de-destinataire

[BO]Changer le titre du mail en cas d absence de destinataire
  • Loading branch information
sfinx13 committed Feb 10, 2023
2 parents 4b9d90c + 527ed28 commit 7979bd5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
47 changes: 30 additions & 17 deletions src/EventListener/ActivityListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +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) {
$signalement = $entity;
} else {
$signalement = $entity->getSignalement();
}
$uuid = $signalement->getUuid();
$options = array_merge($options, [
'link' => $this->urlGenerator->generate('back_signalement_view', [
Expand All @@ -154,23 +157,33 @@ private function sendMail($entity, $mailType)
]);

$this->removeCurrentUserEmailForNotification();

$this->tos = $this->tos->filter(function ($element) {
return '' !== trim($element) && null !== $element;
});

if ($this->tos->isEmpty()) {
$this->notifier->send(
NotificationService::TYPE_ERROR_SIGNALEMENT,
$this->parameterBag->get('admin_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()
);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Service/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -175,6 +176,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.',
Expand Down

0 comments on commit 7979bd5

Please sign in to comment.