Skip to content

Commit

Permalink
Send email to assignees at report publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
AdJez committed Jan 28, 2025
1 parent 963f95c commit 558ff31
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 540 deletions.
27 changes: 23 additions & 4 deletions src/backend/partaj/core/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ def send_referral_answered_to_users(cls, referral, published_by):
cls.send(data)

@classmethod
def send_referral_answered_to_unit_owners(cls, referral, published_by):
def send_referral_answered_to_unit_owners_and_assignees(
cls, referral, published_by
):
"""
Send the "referral answered" email to the units'owner when an answer is added to
a referral.
Expand All @@ -223,10 +225,27 @@ def send_referral_answered_to_unit_owners(cls, referral, published_by):
"REFERRAL_ANSWERED_UNIT_OWNER_TEMPLATE_ID"
]

for assignee in referral.assignees.exclude(id=published_by.id):
link_path = FrontendLink.unit_referral_detail_answer(referral=referral.id)

data = {
"params": {
"answer_sender": published_by.get_full_name(),
"case_number": referral.id,
"link_to_referral": f"{cls.location}{link_path}",
"title": referral.title or referral.object,
},
"replyTo": cls.reply_to,
"templateId": template_unit_owner_id,
"to": [{"email": assignee.email}],
}
cls.send(data)

for unit in referral.units.all():
contacts = unit.members.filter(
unitmembership__role=UnitMembershipRole.OWNER
)
).exclude(id=published_by.id)

# Get the path to the referral detail view from the requester's "my referrals" view
link_path = FrontendLink.unit_referral_detail_answer(referral=referral.id)

Expand All @@ -245,7 +264,7 @@ def send_referral_answered_to_unit_owners(cls, referral, published_by):
cls.send(data)

@classmethod
def send_referral_answered_to_created_by(cls, referral, version):
def send_referral_answered_to_published_by(cls, referral, published_by):
"""
Send the "referral answered" email to the response owner when an answer is added to
a referral.
Expand All @@ -261,7 +280,7 @@ def send_referral_answered_to_created_by(cls, referral, version):
},
"replyTo": cls.reply_to,
"templateId": template_created_by_id,
"to": [{"email": version.created_by.email}],
"to": [{"email": published_by.email}],
}
cls.send(data)

Expand Down
12 changes: 7 additions & 5 deletions src/backend/partaj/core/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ def answer_published(sender, referral, published_answer, published_by, **kwargs)
# Notify the requester by sending them an email
Mailer.send_referral_answered_to_users(published_by=published_by, referral=referral)

# Notify the unit owner by sending them an email
Mailer.send_referral_answered_to_unit_owners(
# Notify the unit owner and assignees by sending them an email
Mailer.send_referral_answered_to_unit_owners_and_assignees(
published_by=published_by, referral=referral
)

Expand Down Expand Up @@ -422,12 +422,14 @@ def report_published(sender, referral, version, published_by, **kwargs):
Mailer.send_referral_answered_to_users(published_by=published_by, referral=referral)

# Notify the unit'owner by sending them an email
Mailer.send_referral_answered_to_unit_owners(
Mailer.send_referral_answered_to_unit_owners_and_assignees(
published_by=published_by, referral=referral
)

# Notify the response'owner by sending them an email
Mailer.send_referral_answered_to_created_by(referral=referral, version=version)
# Notify the response sender by sending them an email
Mailer.send_referral_answered_to_published_by(
referral=referral, published_by=published_by
)

if referral.units.filter(kdb_export=False):
capture_message(
Expand Down
Loading

0 comments on commit 558ff31

Please sign in to comment.