Commit 6d41a70b authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Notifications par mail basées sur un template : le code du template est passé...

Notifications par mail basées sur un template : le code du template est passé via le header References pour faciliter de debug.
parent 7c2f7134
Loading
Loading
Loading
Loading
+1 −0
Changes for CHANGELOG.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ Journal des modifications

10.4.0
------
- Notifications par mail basées sur un template : le code du template est passé via le header References pour faciliter de debug.
- Pages 'Rôles et privilèges' et 'Profils et privilèges' : harmonisation + mention du code de chaque catégorie/privilège pour faciliter la recherche.
- [FIX] Retour en arrière : un candidat peut de nouveau attester sur l'honneur même si le dossier n'a pas été jugé complet par la gestionnaire.
- [FIX] Admission : la marge du bas dans des PDF générés n'était pas respectée (pb dans unicaen/pdf).
+3 −3
Changes for composer.lock: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -11820,11 +11820,11 @@
        },
        {
            "name": "unicaen/app",
            "version": "6.2.0",
            "version": "6.2.1",
            "source": {
                "type": "git",
                "url": "https://git.unicaen.fr/lib/unicaen/app.git",
                "reference": "1d048236fa16c7a9b9dc90466e01dd87e5fbafbf"
                "reference": "8ded04d54ed8f814b64cbe1b3f7e04f44275bcf8"
            },
            "require": {
                "beberlei/assert": "^3.3",
@@ -11876,7 +11876,7 @@
                ]
            },
            "description": "Module de base des applications unicaen",
            "time": "2025-03-12T08:16:29+00:00"
            "time": "2025-09-24T16:18:13+00:00"
        },
        {
            "name": "unicaen/auth-token",
+43 −30
Changes for module/Admission/src/Admission/Service/Notification/NotificationFactory.php: 43 added lines, 30 removed lines.
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@ use Application\Renderer\Template\Variable\PluginManager\TemplateVariablePluginM
use Application\Service\Role\ApplicationRoleServiceAwareTrait;
use Application\Service\UserContextServiceAwareTrait;
use Individu\Entity\Db\Individu;
use Laminas\Mail\Header\References;
use Notification\Exception\RuntimeException;
use Notification\Factory\NotificationFactory as NF;
use Notification\Notification;
use UnicaenRenderer\Entity\Db\Rendu;
use UnicaenRenderer\Service\Rendu\RenduServiceAwareTrait;

/**
@@ -58,9 +60,9 @@ class NotificationFactory extends NF
        ];

        $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::NOTIFICATION_DOSSIER_INCOMPLET, $vars);
        $notif->setTo([$email => $admission->getIndividu()->getNomCompletFormatter()->avecNomPatronymique()->f()])
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps());
        $notif->setTo([$email => $admission->getIndividu()->getNomCompletFormatter()->avecNomPatronymique()->f()]);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }
@@ -77,8 +79,8 @@ class NotificationFactory extends NF
        $vars = $this->createTemplateVarsForOperation($operationAttendue, $notificationOperationAttendue);

        $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::OPERATION_ATTENDUE, $vars);
        $notificationOperationAttendue->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps());

        $this->initNotificationFromRendu($notificationOperationAttendue, $rendu);

        return $notificationOperationAttendue;
    }
@@ -97,9 +99,9 @@ class NotificationFactory extends NF
        $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::VALIDATION_AJOUTEE, $vars);

        $notif = new Notification();
        $notif->setTo([$email => $admission->getIndividu()->getNomCompletFormatter()->avecNomPatronymique()->f()])
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps());
        $notif->setTo([$email => $admission->getIndividu()->getNomCompletFormatter()->avecNomPatronymique()->f()]);

        $this->initNotificationFromRendu($notif, $rendu);

        /** @var Inscription $inscription */
        $inscription = $admission->getInscription()->first();
@@ -144,9 +146,9 @@ class NotificationFactory extends NF
        $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::VALIDATION_SUPPRIMEE, $vars);

        $notif = new Notification();
        $notif->setTo([$email => $admission->getIndividu()->getNomCompletFormatter()->avecNomPatronymique()->f()])
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps());
        $notif->setTo([$email => $admission->getIndividu()->getNomCompletFormatter()->avecNomPatronymique()->f()]);

        $this->initNotificationFromRendu($notif, $rendu);

        /** @var Inscription $inscription */
        $inscription = $admission->getInscription()->first();
@@ -247,21 +249,21 @@ class NotificationFactory extends NF
            //Récupération des emails des responsables d'ED et d'UR
            $cc = array_merge($cc, $this->extractionMailRule->extractEmailsFromAdmissionRoles($admission, $rolesCC));
            $notificationAvisAdmission->setAnomalies($this->extractionMailRule->getAnomalies());
            $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::DOSSIER_VALIDE, $vars);
            $rendu = $this->getRenduService()->generateRenduByTemplateCode($code = MailTemplates::DOSSIER_VALIDE, $vars);
        }elseif($admissionAvis->getAvis()->getAvisType()->getCode() === AdmissionAvis::AVIS_TYPE__CODE__AVIS_ADMISSION_PRESIDENCE && $admissionAvis->getAvis()->getAvisValeur()->getCode() === AdmissionAvis::AVIS_VALEUR__CODE__AVIS_ADMISSION_VALEUR_NEGATIF) {
            //Récupération des emails des responsables d'ED et d'UR
            $cc = array_merge($cc, $this->extractionMailRule->extractEmailsFromAdmissionRoles($admission, $rolesCC));
            $notificationAvisAdmission->setAnomalies($this->extractionMailRule->getAnomalies());
            $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::DOSSIER_REJETE, $vars);
            $rendu = $this->getRenduService()->generateRenduByTemplateCode($code = MailTemplates::DOSSIER_REJETE, $vars);
        }else{
            $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::AVIS_AJOUTE, $vars);
            $rendu = $this->getRenduService()->generateRenduByTemplateCode($code = MailTemplates::AVIS_AJOUTE, $vars);
        }

        $notif = new Notification();
        $notif->setTo([$email => $admission->getIndividu()->getNomCompletFormatter()->avecNomPatronymique()->f()])
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
            ->setCc($cc);
            ->setCc($cc);;

        $this->initNotificationFromRendu($notif, $rendu);

        $successMessage = sprintf(
            "Un mail de notification vient d'être envoyé à %s",
@@ -322,22 +324,22 @@ class NotificationFactory extends NF
            //Récupération des emails des responsables d'ED et d'UR
            $cc = array_merge($cc, $this->extractionMailRule->extractEmailsFromAdmissionRoles($admission, $rolesCC));
            $notificationAvisAdmission->setAnomalies($this->extractionMailRule->getAnomalies());
            $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::DOSSIER_VALIDE, $vars);
            $rendu = $this->getRenduService()->generateRenduByTemplateCode($code = MailTemplates::DOSSIER_VALIDE, $vars);
        }elseif($admissionAvis->getAvis()->getAvisType()->getCode() === AdmissionAvis::AVIS_TYPE__CODE__AVIS_ADMISSION_PRESIDENCE && $admissionAvis->getAvis()->getAvisValeur()->getCode() === AdmissionAvis::AVIS_VALEUR__CODE__AVIS_ADMISSION_VALEUR_NEGATIF) {
            //Récupération des emails des responsables d'ED et d'UR
            $cc = array_merge($cc, $this->extractionMailRule->extractEmailsFromAdmissionRoles($admission, $rolesCC));
            $notificationAvisAdmission->setAnomalies($this->extractionMailRule->getAnomalies());
            $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::DOSSIER_REJETE, $vars);
            $rendu = $this->getRenduService()->generateRenduByTemplateCode($code = MailTemplates::DOSSIER_REJETE, $vars);
        }else{
            $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::AVIS_MODIFIE, $vars);
            $rendu = $this->getRenduService()->generateRenduByTemplateCode($code = MailTemplates::AVIS_MODIFIE, $vars);
        }

        $notif = new Notification();
        $notif->setTo([$email => $admission->getIndividu()->getNomCompletFormatter()->avecNomPatronymique()->f()])
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
            ->setCc($cc);

        $this->initNotificationFromRendu($notif, $rendu);

        $successMessage = sprintf(
            "Un mail de notification vient d'être envoyé à %s",
            implode(', ', array_reduce(array_keys($notif->getTo()), function(array $accu, string $key) use ($notif) {
@@ -380,12 +382,12 @@ class NotificationFactory extends NF
//        $vars['Url'] = $url;
        $vars = $this->createTemplateVarsForAvis($admissionAvis);

        $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::AVIS_SUPPRIME, $vars);
        $rendu = $this->getRenduService()->generateRenduByTemplateCode($code = MailTemplates::AVIS_SUPPRIME, $vars);

        $notif = new Notification();
        $notif->setTo([$email => $admission->getIndividu()->getNomCompletFormatter()->avecNomPatronymique()->f()])
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps());
        $notif->setTo([$email => $admission->getIndividu()->getNomCompletFormatter()->avecNomPatronymique()->f()]);

        $this->initNotificationFromRendu($notif, $rendu);

        /** @var Inscription $inscription */
        $inscription = $admission->getInscription()->first();
@@ -430,12 +432,12 @@ class NotificationFactory extends NF

        $vars = $this->createTemplateVarsForAvis($admissionAvis);

        $rendu = $this->getRenduService()->generateRenduByTemplateCode(MailTemplates::NOTIFICATION_DECLARATION_DOSSIER_INCOMPLET, $vars);
        $rendu = $this->getRenduService()->generateRenduByTemplateCode($code = MailTemplates::NOTIFICATION_DECLARATION_DOSSIER_INCOMPLET, $vars);

        $notif = new Notification();
        $notif->setTo([$email => $admission->getIndividu()->getNomComplet()])
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps());
        $notif->setTo([$email => $admission->getIndividu()->getNomComplet()]);

        $this->initNotificationFromRendu($notif, $rendu);

        /** @var Inscription $inscription */
        $inscription = $admission->getInscription()->first();
@@ -493,4 +495,15 @@ class NotificationFactory extends NF
            'Url' => $this->urlService,
        ];
    }

    protected function initNotificationFromRendu(Notification $notif, Rendu $rendu): void
    {
        $notif
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps());

        $notif->getHeaders()->addHeader(
            (new References())->setIds([$rendu->getTemplate()->getCode()])
        );
    }
}
 No newline at end of file
+55 −62
Changes for module/Formation/src/Formation/Service/Notification/FormationNotificationFactory.php: 55 added lines, 62 removed lines.
Original line number Diff line number Diff line
@@ -15,10 +15,12 @@ use Formation\Entity\Db\SessionStructureValide;
use Formation\Provider\Template\MailTemplates;
use Formation\Service\Parametre\ParametreServiceAwareTrait;
use Formation\Service\Url\UrlServiceAwareTrait;
use Laminas\Mail\Header\References;
use Notification\Exception\RuntimeException;
use Notification\Factory\NotificationFactory;
use Notification\Notification;
use These\Entity\Db\These;
use UnicaenRenderer\Entity\Db\Rendu;
use UnicaenRenderer\Service\Rendu\RenduServiceAwareTrait;

/**
@@ -56,11 +58,9 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mail)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
        ;
        $notif->setTo($mail);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }
@@ -83,11 +83,9 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mail)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
        ;
        $notif->setTo($mail);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }
@@ -110,11 +108,9 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mail)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
        ;
        $notif->setTo($mail);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }
@@ -137,10 +133,9 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mail)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps());
        $notif->setTo($mail);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }
@@ -163,11 +158,9 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mail)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
        ;
        $notif->setTo($mail);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }
@@ -192,11 +185,9 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mail)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
        ;
        $notif->setTo($mail);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }
@@ -222,11 +213,9 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mails)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
        ;
        $notif->setTo($mail);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }
@@ -260,11 +249,10 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mail)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
        ;
        $notif->setTo($mail);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }

@@ -286,10 +274,9 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mail)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps());
        $notif->setTo($mail);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }
@@ -310,11 +297,10 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mail)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
        ;
        $notif->setTo($mail);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }

@@ -346,11 +332,10 @@ class FormationNotificationFactory extends NotificationFactory
        $mails = array_merge($emailsED, $emailsBdd);

        $notif = new Notification();
        $notif
            ->setTo($mails)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
        ;
        $notif->setTo($mails);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }

@@ -401,11 +386,9 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mails)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps())
        ;
        $notif->setTo($mails);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }
@@ -437,10 +420,9 @@ class FormationNotificationFactory extends NotificationFactory
        }

        $notif = new Notification();
        $notif
            ->setTo($mail)
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps());
        $notif->setTo($mail);

        $this->initNotificationFromRendu($notif, $rendu);

        return $notif;
    }
@@ -453,4 +435,15 @@ class FormationNotificationFactory extends NotificationFactory
            'formation' => $formationTemplateVariable,
        ];
    }

    protected function initNotificationFromRendu(Notification $notif, Rendu $rendu): void
    {
        $notif
            ->setSubject($rendu->getSujet())
            ->setBody($rendu->getCorps());

        $notif->getHeaders()->addHeader(
            (new References())->setIds([$rendu->getTemplate()->getCode()])
        );
    }
}
 No newline at end of file
+8 −0
Changes for module/Notification/src/Notification/Notification.php: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Notification;

use Laminas\Mail\Headers;
use Laminas\View\Model\ViewModel;
use Notification\Entity\NotifEntity;

@@ -24,6 +25,7 @@ class Notification
    protected ?string $toLabel = null;
    protected ?string $ccLabel = null;
    protected ?string $bccLabel = null;
    protected Headers $headers;

    /**
     * @var string[]
@@ -52,6 +54,7 @@ class Notification
    public function __construct(?string $code = null)
    {
        $this->code = $code;
        $this->headers = new Headers();
    }

    /**
@@ -238,6 +241,11 @@ class Notification
        return $this->bcc;
    }

    public function getHeaders(): Headers
    {
        return $this->headers;
    }

    public function getTemplatePath(): ?string
    {
        return $this->templatePath;
Loading