Skip to content
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

[GEN-1567] Privilégier les administrateurs de l’organisation lors des notifications de relance des demandes de Prolongation #3984

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions itou/approvals/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def email(self):
PrescriberMembership.objects.active()
.filter(organization=self.prolongation_request.prescriber_organization)
.exclude(user=self.prolongation_request.validated_by)
# Limit to the last 10 active colleagues, it should cover the ones dedicated to the IAE and some more.
.order_by(F("user__last_login").desc(nulls_last=True), "-joined_at", "-pk")[:10]
# Limit to the last 10 active colleagues, admins take precedence over regular members.
# It should cover the ones dedicated to the IAE and some more.
.order_by("-is_admin", F("user__last_login").desc(nulls_last=True), "-joined_at", "-pk")[:10]
.values_list("user__email", flat=True)
)
context = {
Expand Down
10 changes: 7 additions & 3 deletions tests/approvals/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ def test_prolongation_request_created(snapshot):

def test_prolongation_request_created_reminder(snapshot):
prolongation_request = ProlongationRequestFactory(for_snapshot=True)
other_prescribers = PrescriberFactory.create_batch(
3, membership__organization=prolongation_request.prescriber_organization
admin_prescribers = PrescriberFactory.create_batch(
9, membership__organization=prolongation_request.prescriber_organization, membership__is_admin=True
)
regular_prescribers = PrescriberFactory.create_batch(
3, membership__organization=prolongation_request.prescriber_organization, membership__is_admin=False
)
default_storage.location = "snapshot"
email = notifications.ProlongationRequestCreatedReminder(prolongation_request).email

assert email.to == [prolongation_request.validated_by.email]
assert set(email.cc) == {member.email for member in other_prescribers}
# Notification is sent to the 10 most active colleagues, admins take precedence
assert set(email.cc) == {member.email for member in admin_prescribers} | {regular_prescribers[-1].email}
assert email.subject == snapshot(name="subject")
assert email.body == snapshot(name="body")

Expand Down