-
Notifications
You must be signed in to change notification settings - Fork 0
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 - Notifications] Refactorisation envoi de mail #1134
Conversation
You have successfully added a new SonarCloud configuration ``. As part of the setup process, we have scanned this repository and found no existing alerts. In the future, you will see all code scanning alerts on the repository Security tab. |
NotificationMailerType::TYPE_CRON, | ||
$this->parameterBag->get('admin_email'), | ||
[ | ||
'cron_label' => 'demande de feedback à l\'usager', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus besoin de passer l'url
, elle est passé en tant que paramètre par défaut
@@ -23,7 +23,7 @@ | |||
<tbody> | |||
<tr style="text-align: center;width: 100%"> | |||
<td> | |||
<a href="{{ lien_suivi|raw }}" target="_blank" rel="noopener">{{ btnText|capitalize }}</a></td> | |||
<a href="{{ lien_suivi|raw }}" target="_blank" rel="noopener">{{ btntext|capitalize }}</a></td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Il y'avait les deux variables btnText
et btntext
j'ai gardé celui ou il y'avais moins de fichier à modifier
src/Service/Mailer/Mail/Signalement/SignalementClosedToOnePartnerMailer.php
Show resolved
Hide resolved
@@ -34,36 +41,27 @@ public function validationResponseSignalement(Signalement $signalement, Request | |||
$signalement->setCodeSuivi(md5(uniqid())); | |||
$toRecipients = $signalement->getMailUsagers(); | |||
foreach ($toRecipients as $toRecipient) { | |||
$notificationService->send( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avant @emilschn
), | ||
], | ||
$signalement->getTerritory() | ||
$notificationMailerRegistry->send( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apres @emilschn la construction des paramètres se fait dans la classe dorénavant dans la majorité des cas, il reste toujours possible de passer des paramètres.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'ai refait une passe de tests, j'ai mis mes commentaires
@@ -36,7 +36,7 @@ security: | |||
signature_properties: [id, email] | |||
default_target_path: login_creation_pass | |||
failure_path: login_activation_fail | |||
max_uses: 1 | |||
max_uses: 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aujourd'hui deux systèmes de reset-password cohabite, mise à jour de la configuration afin de permettre aux utilisateurs de cliquer au max 3 fois sur le lien.
Pour info LoginLink est utilisé de maniere détourné car cela sert à faire de la connexion sans mot de passe et non à générer des liens de reset-password. Doit être remplacer par le système qui a été mis en place coté BO
@@ -1,91 +0,0 @@ | |||
<?php | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jamais utilisé depuis 8 mois
territory: $user->getTerritory(), | ||
user: $user, | ||
params: [ | ||
'nb_signalements' => $userItem['nb_signalements'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seulement 2 mails ont un tableau associatif passé en paramètre celui ci et celui d'ESABORA
@@ -63,63 +58,6 @@ public function countByStatusForUser($user, Territory|null $territory, Qualifica | |||
->getResult(); | |||
} | |||
|
|||
public function findByStatusAndOrCityForUser(User|UserInterface|null $user, array $options, int|null $export): Paginator|array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus utilisé depuis la livraison de la 1.6.0
{ | ||
} | ||
|
||
abstract public function getMailerParamsFromNotification(NotificationMail $notificationMail): array; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Il est obligatoire d'implementer getMailerParamsFromNotification même si vous n'avez pas de paramètre à utiliser ce qui est assez rare dans ce cas la, passez un tableau vide comme dans AccountDeleteMailer
return $this->parameterBag->get('host_url').$this->urlGenerator->generate($route, $params); | ||
} | ||
|
||
public function updateMailerSubjectFromNotification(NotificationMail $notificationMail): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Si vous devez avoir un objet avec des paramètres implémenter updateMailerSubjectFromNotification
]; | ||
} | ||
|
||
public function updateMailerSubjectFromNotification(NotificationMail $notificationMail): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pour gérer les placeholder dans un objet de mail
|
||
class NotificationMail | ||
{ | ||
public function __construct( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Porte les paramètres, peut être amené à évoluer si ces paramètre ne permettent pas de récupérer l'info dont on a besoin
Pour moi, c'est ok sur les fonctionnalités re-testées. |
ok pour moi aussi ! |
8451018
to
3402bc5
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Ticket
#1139
Description
L'approche actuelle rend le code difficile à maintenir et à étendre car elle est très rigide et ne permet pas d'étendre la fonctionnalité d'envoi de base.
L'idée est de créer une hiérarchie de classes ou chaque classe correspond à un type de notification qui étend une classe principale qui encapsule la logique d'envoi.
Cela permet d'avoir une meilleur visibilité sur les différents mail envoyés et de rendre le code plus flexible, plus facile à maintenir et à étendre. On pourrait imaginer apporter des fonctionnalités supplémentaires sur un type de mail particulier.
Changements apportés
NotificationService
parNotificationMailerRegistry
qui est un registre qui contient l'ensemble des maiil de notification référencé par le tag symfonyapp.notification_mailer
NotificationMail
pour encapsuler les données utile à l'envoiNotificationMailerType
AbstractNotificationMailer
AbstractNotificationMailer
réparti selon une arborescence métier qui peut évoluer, aucune contrainte existe.Comment envoyer un mail ?
Définir une constante dans NotificationMailerType.php pour identifier un email
Créer une classe Mailer pour configurer un email
Envoyer un email
Injecter le service NotificationMailerRegistry et définir un objet Notification
Tests (22 emails)
Tester l'ensemble des cas métiers qui déclenche les 23 mails.