Skip to content

Commit

Permalink
communications: don't send emails to inactive users
Browse files Browse the repository at this point in the history
  • Loading branch information
tonial committed Jan 14, 2025
1 parent 37320cd commit 28bde9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions itou/communications/dispatch/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ def send(self):
logger.info("Send email copy to admin, admin_count=%d", len(admins))
for admin in admins:
self.__class__(admin, self.structure, self.user, **self.context).send()
if not self.user.is_active:
return
if self.should_send():
self.build().send()
7 changes: 7 additions & 0 deletions tests/communications/test_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ def test_method_send_for_employer_that_left_his_company(
" ne fait plus partie de votre structure." in mailoutbox[1].body
)

def test_method_send_for_inactive_user(self, email_notification, django_capture_on_commit_callbacks, mailoutbox):
self.user.is_active = False
self.user.save()
with django_capture_on_commit_callbacks(execute=True):
email_notification(self.user, self.organization).send()
assert len(mailoutbox) == 0


class TestProfiledNotification:
def setup_method(self):
Expand Down

0 comments on commit 28bde9c

Please sign in to comment.