Skip to content

Commit

Permalink
communications: Send emails to admins when prescriber left the org
Browse files Browse the repository at this point in the history
  • Loading branch information
tonial committed Dec 4, 2024
1 parent 10c1366 commit 7354e39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
29 changes: 20 additions & 9 deletions itou/communications/dispatch/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,33 @@ 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(),
self.subject_template,
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()
6 changes: 6 additions & 0 deletions itou/templates/apply/email/new_for_prescriber_body.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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* :
Expand Down

0 comments on commit 7354e39

Please sign in to comment.