-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from uktrade/feature/ORPD-129-gov.uk-notify-init
Adds GOV.UK Notify and allows test emails to be sent
- Loading branch information
Showing
10 changed files
with
384 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import logging | ||
import uuid | ||
|
||
from notifications_python_client.notifications import NotificationsAPIClient | ||
|
||
from django.conf import settings | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class EmailSendError(Exception): | ||
"""Email send error exception. | ||
This class is used to raise exceptions when there is an error | ||
sending an email via the GovUK Notify service. | ||
""" | ||
|
||
|
||
def send_email_notification( | ||
email_address, template_id, personalisation=None, reference=None | ||
) -> dict: | ||
"""Send email notification. | ||
This function sends an email notification using the GovUK Notify API. | ||
Note: If successful, the response of the GovUK Notify API is returned | ||
as a dictionary which includes an 'id' key for the successfully sent email. | ||
""" | ||
if settings.SUPPRESS_NOTIFY: | ||
logger.warning( | ||
"SUPPRESS_NOTIFY detected, suppressing email" | ||
f" notification to: {email_address}" | ||
) | ||
return {"id": str(uuid.uuid4()), "status": "testing"} | ||
notifications_client = NotificationsAPIClient( | ||
settings.GOVUK_NOTIFY_API_KEY | ||
) | ||
response: dict = notifications_client.send_email_notification( | ||
email_address=email_address, | ||
template_id=template_id, | ||
personalisation=personalisation, | ||
reference=reference, | ||
) | ||
if "id" in response: | ||
# See docstring | ||
response["status"] = "delivered" | ||
return response | ||
else: | ||
raise EmailSendError(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block head_title %}{{service_name}} - {{ result.title }}{% endblock %} | ||
{% block service_name %}{{service_name}}{% endblock %} | ||
|
||
{% block body_content %} | ||
<div class="govuk-width-container"> | ||
<div class="govuk-width-container"> | ||
{% comment %} <nav class="govuk-breadcrumbs" aria-label="Breadcrumb"> | ||
<ol class="govuk-breadcrumbs__list"> | ||
<li class="govuk-breadcrumbs__list-item"> | ||
<a class="govuk-breadcrumbs__link" href="{{ request.META.HTTP_REFERER }}">Search results</a> | ||
</li> | ||
<li class="govuk-breadcrumbs__list-item"> | ||
{{ result.title }} | ||
</li> | ||
</ol> | ||
</nav> {% endcomment %} | ||
<main class="govuk-main-wrapper" id="main-content" role="main"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h1 class="govuk-heading-xl">Send feedback</h1> | ||
<form method="post" class="govuk-form-group"> | ||
{% csrf_token %} | ||
<div class="govuk-form-group"> | ||
<label class="govuk-label govuk-label--m" for="{{ form.name.id_for_label }}"> | ||
{{ form.name.label }} | ||
</label> | ||
{{ form.name }} | ||
</div> | ||
<div class="govuk-form-group"> | ||
<label class="govuk-label govuk-label--m" for="{{ form.message.id_for_label }}"> | ||
{{ form.message.label }} | ||
</label> | ||
{{ form.message }} | ||
</div> | ||
<button type="submit" class="govuk-button">Send</button> | ||
</form> | ||
</div> | ||
</div> | ||
</main> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.