Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BO]Changer le titre du mail en cas d absence de destinataire #892

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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.',
Expand Down