diff --git a/itou/communications/dispatch/email.py b/itou/communications/dispatch/email.py index e613806807..f62024790c 100644 --- a/itou/communications/dispatch/email.py +++ b/itou/communications/dispatch/email.py @@ -13,15 +13,6 @@ class EmailNotification(BaseNotification): REQUIRED = BaseNotification.REQUIRED + ["subject_template", "body_template"] def build(self): - # TODO: Temporary log for analysis : remove by the end of November 2024 - if self.user.is_prescriber and self.structure: - memberships = ( - PrescriberMembership.objects.active().filter(organization=self.structure).select_related("user") - ) - members = [m.user for m in memberships] - if self.user not in members: - admin_count = len([m for m in memberships if m.is_admin]) - logger.info("Estimate new email sent to admin_count=%d", admin_count) return get_email_message( [self.user.email], self.get_context(), @@ -29,6 +20,26 @@ def build(self): self.body_template, ) + def build_copy_for_admins(self, emails): + return get_email_message( + [], + self.get_context() | {"org_old_member": self.user}, + self.subject_template, + self.body_template, + cc=emails, + ) + def send(self): + if self.is_applicable(): + # Don't check user notification settings if not in org anymore + if self.user.is_prescriber and self.structure: + memberships = ( + PrescriberMembership.objects.active().filter(organization=self.structure).select_related("user") + ) + members = [m.user for m in memberships] + if self.user not in members: + emails = [m.user.email for m in memberships if m.is_admin] + logger.info("Send email copy to admin, admin_count=%d", len(emails)) + return self.build_copy_for_admins(emails).send() if self.should_send(): return self.build().send() diff --git a/itou/templates/apply/email/new_for_prescriber_body.txt b/itou/templates/apply/email/new_for_prescriber_body.txt index 7cbfcb8a8e..b8d400cb8e 100644 --- a/itou/templates/apply/email/new_for_prescriber_body.txt +++ b/itou/templates/apply/email/new_for_prescriber_body.txt @@ -3,6 +3,12 @@ {% load str_filters %} {% block body %} +{% if org_old_member|default:False %} +Vous recevez cet e-mail parce que l'utilisateur {{ org_old_member.get_full_name }} ({{ org_old_member.email}}) ne fait plus partie de votre organisation + +----- +{% endif %} + La candidature suivante a été envoyée avec succès à l'entreprise {{ job_application.to_company.display_name }} ({{ job_application.to_company.kind }}) localisée à {{ job_application.to_company.city }} ! *Candidat* :