mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 17:45:32 -04:00
Merge pull request #1367 from alphagov/letter-notification-page
Letter notification page
This commit is contained in:
@@ -14,11 +14,13 @@ from app import (
|
|||||||
current_service
|
current_service
|
||||||
)
|
)
|
||||||
from app.main import main
|
from app.main import main
|
||||||
|
from app.template_previews import TemplatePreview
|
||||||
from app.utils import (
|
from app.utils import (
|
||||||
user_has_permissions,
|
user_has_permissions,
|
||||||
get_help_argument,
|
get_help_argument,
|
||||||
get_template,
|
get_template,
|
||||||
get_time_left,
|
get_time_left,
|
||||||
|
get_letter_timings,
|
||||||
REQUESTED_STATUSES,
|
REQUESTED_STATUSES,
|
||||||
FAILURE_STATUSES,
|
FAILURE_STATUSES,
|
||||||
SENDING_STATUSES,
|
SENDING_STATUSES,
|
||||||
@@ -40,20 +42,18 @@ def get_status_arg(filter_args):
|
|||||||
return REQUESTED_STATUSES
|
return REQUESTED_STATUSES
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<service_id>/notification/<notification_id>")
|
@main.route("/services/<service_id>/notification/<uuid:notification_id>")
|
||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('view_activity', admin_override=True)
|
@user_has_permissions('view_activity', admin_override=True)
|
||||||
def view_notification(service_id, notification_id):
|
def view_notification(service_id, notification_id):
|
||||||
notification = notification_api_client.get_notification(service_id, notification_id)
|
notification = notification_api_client.get_notification(service_id, str(notification_id))
|
||||||
template = get_template(
|
template = get_template(
|
||||||
notification['template'],
|
notification['template'],
|
||||||
current_service,
|
current_service,
|
||||||
letter_preview_url=url_for(
|
letter_preview_url=url_for(
|
||||||
'.view_template_version_preview',
|
'.view_letter_notification_as_image',
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
template_id=notification['template']['id'],
|
notification_id=notification_id,
|
||||||
version=notification['template_version'],
|
|
||||||
filetype='png',
|
|
||||||
),
|
),
|
||||||
show_recipient=True,
|
show_recipient=True,
|
||||||
redact_missing_personalisation=True,
|
redact_missing_personalisation=True,
|
||||||
@@ -63,6 +63,7 @@ def view_notification(service_id, notification_id):
|
|||||||
job = job_api_client.get_job(service_id, notification['job']['id'])['data']
|
job = job_api_client.get_job(service_id, notification['job']['id'])['data']
|
||||||
else:
|
else:
|
||||||
job = None
|
job = None
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/notifications/notification.html',
|
'views/notifications/notification.html',
|
||||||
finished=(notification['status'] in (DELIVERED_STATUSES + FAILURE_STATUSES)),
|
finished=(notification['status'] in (DELIVERED_STATUSES + FAILURE_STATUSES)),
|
||||||
@@ -79,10 +80,33 @@ def view_notification(service_id, notification_id):
|
|||||||
partials=get_single_notification_partials(notification),
|
partials=get_single_notification_partials(notification),
|
||||||
created_by=notification.get('created_by'),
|
created_by=notification.get('created_by'),
|
||||||
created_at=notification['created_at'],
|
created_at=notification['created_at'],
|
||||||
help=get_help_argument()
|
help=get_help_argument(),
|
||||||
|
estimated_letter_delivery_date=get_letter_timings(notification['created_at']).earliest_delivery,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/services/<service_id>/notification/<uuid:notification_id>.png")
|
||||||
|
@login_required
|
||||||
|
@user_has_permissions('view_activity', admin_override=True)
|
||||||
|
def view_letter_notification_as_image(service_id, notification_id):
|
||||||
|
|
||||||
|
notification = notification_api_client.get_notification(service_id, notification_id)
|
||||||
|
|
||||||
|
template = get_template(
|
||||||
|
notification['template'],
|
||||||
|
current_service,
|
||||||
|
letter_preview_url=url_for(
|
||||||
|
'.view_letter_notification_as_image',
|
||||||
|
service_id=service_id,
|
||||||
|
notification_id=notification_id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
template.values = notification['personalisation']
|
||||||
|
|
||||||
|
return TemplatePreview.from_utils_template(template, 'png', page=request.args.get('page'))
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<service_id>/notification/<notification_id>.json")
|
@main.route("/services/<service_id>/notification/<notification_id>.json")
|
||||||
@user_has_permissions('view_activity', admin_override=True)
|
@user_has_permissions('view_activity', admin_override=True)
|
||||||
def view_notification_updates(service_id, notification_id):
|
def view_notification_updates(service_id, notification_id):
|
||||||
|
|||||||
@@ -30,8 +30,16 @@
|
|||||||
on {{ created_at|format_datetime_short }}
|
on {{ created_at|format_datetime_short }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
{% if template.template_type == 'letter' %}
|
||||||
|
<p>
|
||||||
|
Estimated delivery date: {{ estimated_letter_delivery_date|string|format_date_short }}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{{ template|string }}
|
{{ template|string }}
|
||||||
|
|
||||||
{{ ajax_block(partials, updates_url, 'status', finished=finished) }}
|
{% if template.template_type != 'letter' %}
|
||||||
|
{{ ajax_block(partials, updates_url, 'status', finished=finished) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ def service_json(
|
|||||||
def template_json(service_id,
|
def template_json(service_id,
|
||||||
id_,
|
id_,
|
||||||
name="sample template",
|
name="sample template",
|
||||||
type_="sms",
|
type_=None,
|
||||||
content=None,
|
content=None,
|
||||||
subject=None,
|
subject=None,
|
||||||
version=1,
|
version=1,
|
||||||
@@ -97,7 +97,7 @@ def template_json(service_id,
|
|||||||
template = {
|
template = {
|
||||||
'id': id_,
|
'id': id_,
|
||||||
'name': name,
|
'name': name,
|
||||||
'template_type': type_,
|
'template_type': type_ or "sms",
|
||||||
'content': content,
|
'content': content,
|
||||||
'service': service_id,
|
'service': service_id,
|
||||||
'version': version,
|
'version': version,
|
||||||
@@ -226,9 +226,10 @@ def notification_json(
|
|||||||
with_links=False,
|
with_links=False,
|
||||||
rows=5,
|
rows=5,
|
||||||
personalisation=None,
|
personalisation=None,
|
||||||
|
template_type=None,
|
||||||
):
|
):
|
||||||
if template is None:
|
if template is None:
|
||||||
template = template_json(service_id, str(generate_uuid()))
|
template = template_json(service_id, str(generate_uuid()), type_=template_type)
|
||||||
if sent_at is None:
|
if sent_at is None:
|
||||||
sent_at = str(datetime.utcnow().time())
|
sent_at = str(datetime.utcnow().time())
|
||||||
if created_at is None:
|
if created_at is None:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
from flask import url_for
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from app.utils import (
|
from app.utils import (
|
||||||
@@ -8,6 +9,7 @@ from app.utils import (
|
|||||||
DELIVERED_STATUSES,
|
DELIVERED_STATUSES,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from notifications_utils.template import LetterImageTemplate
|
||||||
from tests.conftest import mock_get_notification, SERVICE_ONE_ID, normalize_spaces
|
from tests.conftest import mock_get_notification, SERVICE_ONE_ID, normalize_spaces
|
||||||
|
|
||||||
|
|
||||||
@@ -110,3 +112,52 @@ def test_notification_page_doesnt_link_to_template_in_tour(
|
|||||||
'sample template sent by Test User on 1 January at 1:01am'
|
'sample template sent by Test User on 1 January at 1:01am'
|
||||||
)
|
)
|
||||||
assert len(page.select('main p:nth-of-type(1) a')) == 0
|
assert len(page.select('main p:nth-of-type(1) a')) == 0
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time("2016-01-01 01:01")
|
||||||
|
def test_notification_page_shows_status_of_letter_notification(
|
||||||
|
client_request,
|
||||||
|
mocker,
|
||||||
|
fake_uuid,
|
||||||
|
):
|
||||||
|
|
||||||
|
mock_get_notification(mocker, fake_uuid, template_type='letter')
|
||||||
|
|
||||||
|
page = client_request.get(
|
||||||
|
'main.view_notification',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
notification_id=fake_uuid,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert normalize_spaces(page.select('main p:nth-of-type(1)')[0].text) == (
|
||||||
|
'sample template sent by Test User on 1 January at 1:01am'
|
||||||
|
)
|
||||||
|
assert normalize_spaces(page.select('main p:nth-of-type(2)')[0].text) == (
|
||||||
|
'Estimated delivery date: 6 January'
|
||||||
|
)
|
||||||
|
assert page.select('p.notification-status') == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_show_image_of_letter_notification(
|
||||||
|
logged_in_client,
|
||||||
|
fake_uuid,
|
||||||
|
mocker
|
||||||
|
):
|
||||||
|
|
||||||
|
mock_get_notification(mocker, fake_uuid, template_type='letter')
|
||||||
|
|
||||||
|
mocked_preview = mocker.patch(
|
||||||
|
'app.main.views.templates.TemplatePreview.from_utils_template',
|
||||||
|
return_value='foo'
|
||||||
|
)
|
||||||
|
|
||||||
|
response = logged_in_client.get(url_for(
|
||||||
|
'main.view_letter_notification_as_image',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
notification_id=fake_uuid,
|
||||||
|
))
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.get_data(as_text=True) == 'foo'
|
||||||
|
assert isinstance(mocked_preview.call_args[0][0], LetterImageTemplate)
|
||||||
|
assert mocked_preview.call_args[0][1] == 'png'
|
||||||
|
|||||||
@@ -1679,6 +1679,7 @@ def mock_get_notification(
|
|||||||
fake_uuid,
|
fake_uuid,
|
||||||
notification_status='delivered',
|
notification_status='delivered',
|
||||||
redact_personalisation=False,
|
redact_personalisation=False,
|
||||||
|
template_type=None,
|
||||||
):
|
):
|
||||||
def _get_notification(
|
def _get_notification(
|
||||||
service_id,
|
service_id,
|
||||||
@@ -1687,7 +1688,8 @@ def mock_get_notification(
|
|||||||
noti = notification_json(
|
noti = notification_json(
|
||||||
service_id,
|
service_id,
|
||||||
rows=1,
|
rows=1,
|
||||||
status=notification_status
|
status=notification_status,
|
||||||
|
template_type=template_type,
|
||||||
)['notifications'][0]
|
)['notifications'][0]
|
||||||
|
|
||||||
noti['id'] = notification_id
|
noti['id'] = notification_id
|
||||||
@@ -1701,7 +1703,9 @@ def mock_get_notification(
|
|||||||
service_id,
|
service_id,
|
||||||
'5407f4db-51c7-4150-8758-35412d42186a',
|
'5407f4db-51c7-4150-8758-35412d42186a',
|
||||||
content='hello ((name))',
|
content='hello ((name))',
|
||||||
|
subject='blah',
|
||||||
redact_personalisation=redact_personalisation,
|
redact_personalisation=redact_personalisation,
|
||||||
|
type_=template_type,
|
||||||
)
|
)
|
||||||
return noti
|
return noti
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user