Skip to content
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.

Allow assigning our own reference to Notify emails #298

Merged
merged 1 commit into from
Dec 3, 2024
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
2 changes: 2 additions & 0 deletions app/notification/model/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Notification:
contact_info: str
contact_name: str
content: dict
govuk_notify_reference: str | None

@staticmethod
def from_json(data: dict):
Expand All @@ -26,6 +27,7 @@ def from_json(data: dict):
contact_info=data.get("to"),
contact_name=data.get("full_name", ""),
content=data.get("content"),
govuk_notify_reference=data.get("govuk_notify_reference"),
)
current_app.logger.info(
f"Notification data template_type: ({notification_data.template_type}) "
Expand Down
8 changes: 8 additions & 0 deletions app/notification/model/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def send_magic_link(notification: Notification, code: int = 200) -> tuple:
"request new link url": contents.request_new_link_url,
"contact details": contents.contact_help_email,
},
reference=notification.govuk_notify_reference,
)
current_app.logger.info("Call made to govuk Notify API")
return response, code
Expand Down Expand Up @@ -74,6 +75,7 @@ def send_submitted_application(notification: Notification) -> tuple:
)
notify_payload = {
"email_address": contents.contact_info,
"reference": notification.govuk_notify_reference,
"template_id": template_id,
"email_reply_to_id": contents.reply_to_email_id,
"personalisation": {
Expand All @@ -92,6 +94,7 @@ def send_submitted_application(notification: Notification) -> tuple:
},
}
response = notifications_client.send_email_notification(**notify_payload)
current_app.logger.info("Call made to govuk Notify API")
return response, 200

except errors.HTTPError as e:
Expand Down Expand Up @@ -131,6 +134,7 @@ def send_submitted_eoi(notification: Notification, code: int = 200, template_nam
"caveats": contents.caveats,
"full name": contents.contact_name,
},
reference=notification.govuk_notify_reference,
)
current_app.logger.info("Call made to govuk Notify API")
return response, code
Expand Down Expand Up @@ -171,6 +175,7 @@ def send_incomplete_application(notification: Notification, code: int = 200) ->
},
"contact email": notification.content.get(NotifyConstants.MAGIC_LINK_CONTACT_HELP_EMAIL_FIELD),
},
reference=notification.govuk_notify_reference,
)
return response, code

Expand Down Expand Up @@ -202,6 +207,7 @@ def send_application_reminder(notification: Notification, code: int = 200) -> tu
"round name": contents.round_name,
"application deadline": contents.deadline_date,
},
reference=notification.govuk_notify_reference,
)
current_app.logger.info("Call made to govuk Notify API")
return response, code
Expand All @@ -228,6 +234,7 @@ def send_assessment_assigned(notification: Notification, code: int = 200) -> tup
"assessment link": contents.assessment_link,
"lead assessor email": contents.lead_assessor_email,
},
reference=notification.govuk_notify_reference,
)
current_app.logger.info("Call made to govuk Notify API")
return response, code
Expand All @@ -254,6 +261,7 @@ def send_assessment_unassigned(notification: Notification, code: int = 200) -> t
"assessment link": contents.assessment_link,
"lead assessor email": contents.lead_assessor_email,
},
reference=notification.govuk_notify_reference,
)
current_app.logger.info("Call made to govuk Notify API")
return response, code
Expand Down
15 changes: 12 additions & 3 deletions examplar_data/application_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@
)


def notification_class_data_for_application(date_submitted=True, deadline_date=True, language="en"):
def notification_class_data_for_application(
date_submitted=True, deadline_date=True, language="en", govuk_notify_reference=None
):
return Notification(
template_type="APPLICATION_RECORD_OF_SUBMISSION",
contact_info="[email protected]",
contact_name="Test User",
govuk_notify_reference=govuk_notify_reference,
content={
"application": {
"language": language,
Expand Down Expand Up @@ -84,11 +87,14 @@ def notification_class_data_for_application(date_submitted=True, deadline_date=T
)


def notification_class_data_for_cof_application(date_submitted=True, deadline_date=True, language="en"):
def notification_class_data_for_cof_application(
date_submitted=True, deadline_date=True, language="en", govuk_notify_reference=None
):
return Notification(
template_type="APPLICATION_RECORD_OF_SUBMISSION",
contact_info="[email protected]",
contact_name="Test User",
govuk_notify_reference=govuk_notify_reference,
content={
"application": {
"language": language,
Expand Down Expand Up @@ -118,11 +124,14 @@ def notification_class_data_for_cof_application(date_submitted=True, deadline_da
)


def notification_class_data_for_eoi(date_submitted=True, deadline_date=True, language="en"):
def notification_class_data_for_eoi(
date_submitted=True, deadline_date=True, language="en", govuk_notify_reference=None
):
return Notification(
template_type="APPLICATION_RECORD_OF_SUBMISSION",
contact_info="[email protected]",
contact_name="Test User",
govuk_notify_reference=govuk_notify_reference,
content={
"application": {
"language": language,
Expand Down
3 changes: 2 additions & 1 deletion examplar_data/magic_link_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}


def notification_class_data_for_magic_link():
def notification_class_data_for_magic_link(govuk_notify_reference=None):
return Notification(
template_type="MAGIC_LINK",
contact_info="[email protected]",
Expand All @@ -65,4 +65,5 @@ def notification_class_data_for_magic_link():
"magic_link_url": "https://www.example.com/",
"request_new_link_url": "https://www.example.com/new_link",
},
govuk_notify_reference=govuk_notify_reference,
)
3 changes: 3 additions & 0 deletions tests/test_application/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def test_send_submitted_lang(
template_id=template_id,
email_reply_to_id=ANY,
personalisation=ANY,
reference=None,
)

assert code == 200
Expand All @@ -164,6 +165,7 @@ def test_send_submitted_eoi(
date_submitted=True,
deadline_date=False,
language=language,
govuk_notify_reference="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
),
template_name="Pass with caveats",
)
Expand All @@ -173,6 +175,7 @@ def test_send_submitted_eoi(
template_id=template_id,
email_reply_to_id=ANY,
personalisation=ANY,
reference="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
)

assert code == 200
Expand Down
Loading