mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 18:28:25 -04:00
Merge pull request #2897 from alphagov/overlay-for-failed-letters
Precompiled show preview with overlay when validation fails
This commit is contained in:
@@ -60,7 +60,9 @@ def view_notification(service_id, notification_id):
|
|||||||
|
|
||||||
if notification['template']['is_precompiled_letter']:
|
if notification['template']['is_precompiled_letter']:
|
||||||
try:
|
try:
|
||||||
file_contents = view_letter_notification_as_preview(service_id, notification_id, "pdf")
|
file_contents = view_letter_notification_as_preview(
|
||||||
|
service_id, notification_id, "pdf"
|
||||||
|
)
|
||||||
page_count = pdf_page_count(io.BytesIO(file_contents))
|
page_count = pdf_page_count(io.BytesIO(file_contents))
|
||||||
except PdfReadError:
|
except PdfReadError:
|
||||||
return render_template(
|
return render_template(
|
||||||
@@ -72,7 +74,6 @@ def view_notification(service_id, notification_id):
|
|||||||
|
|
||||||
if notification.get('postage'):
|
if notification.get('postage'):
|
||||||
notification['template']['postage'] = notification['postage']
|
notification['template']['postage'] = notification['postage']
|
||||||
|
|
||||||
template = get_template(
|
template = get_template(
|
||||||
notification['template'],
|
notification['template'],
|
||||||
current_service,
|
current_service,
|
||||||
@@ -173,14 +174,22 @@ def view_letter_notification_as_preview(service_id, notification_id, filetype):
|
|||||||
|
|
||||||
if filetype not in ('pdf', 'png'):
|
if filetype not in ('pdf', 'png'):
|
||||||
abort(404)
|
abort(404)
|
||||||
|
notification = notification_api_client.get_notification(service_id, str(notification_id))
|
||||||
try:
|
try:
|
||||||
preview = notification_api_client.get_notification_letter_preview(
|
if notification['status'] == "validation-failed":
|
||||||
service_id,
|
preview = notification_api_client.get_notification_letter_preview_with_overlay(
|
||||||
notification_id,
|
service_id,
|
||||||
filetype,
|
notification_id,
|
||||||
page=request.args.get('page')
|
filetype,
|
||||||
)
|
page=request.args.get('page')
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
preview = notification_api_client.get_notification_letter_preview(
|
||||||
|
service_id,
|
||||||
|
notification_id,
|
||||||
|
filetype,
|
||||||
|
page=request.args.get('page')
|
||||||
|
)
|
||||||
|
|
||||||
display_file = base64.b64decode(preview['content'])
|
display_file = base64.b64decode(preview['content'])
|
||||||
except APIError:
|
except APIError:
|
||||||
|
|||||||
@@ -94,6 +94,17 @@ class NotificationApiClient(NotifyAdminAPIClient):
|
|||||||
|
|
||||||
return self.get(url=get_url)
|
return self.get(url=get_url)
|
||||||
|
|
||||||
|
def get_notification_letter_preview_with_overlay(self, service_id, notification_id, file_type, page=None):
|
||||||
|
get_url = '/service/{}/template/preview/{}/{}{}{}'.format(
|
||||||
|
service_id,
|
||||||
|
notification_id,
|
||||||
|
file_type,
|
||||||
|
'?overlay=1',
|
||||||
|
'&page={}'.format(page) if page else '',
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.get(url=get_url)
|
||||||
|
|
||||||
def update_notification_to_cancelled(self, service_id, notification_id):
|
def update_notification_to_cancelled(self, service_id, notification_id):
|
||||||
return self.post(
|
return self.post(
|
||||||
url='/service/{}/notifications/{}/cancel'.format(service_id, notification_id),
|
url='/service/{}/notifications/{}/cancel'.format(service_id, notification_id),
|
||||||
|
|||||||
@@ -456,6 +456,32 @@ def test_should_show_image_of_letter_notification(
|
|||||||
assert response.get_data(as_text=True) == 'foo'
|
assert response.get_data(as_text=True) == 'foo'
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_show_image_of_letter_notification_that_failed_validation(
|
||||||
|
logged_in_client,
|
||||||
|
fake_uuid,
|
||||||
|
mocker
|
||||||
|
):
|
||||||
|
|
||||||
|
mock_get_notification(mocker, fake_uuid, template_type='letter', notification_status='validation-failed')
|
||||||
|
|
||||||
|
mocker.patch(
|
||||||
|
'app.main.views.notifications.notification_api_client.get_notification_letter_preview_with_overlay',
|
||||||
|
return_value={
|
||||||
|
'content': base64.b64encode(b'foo').decode('utf-8')
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
response = logged_in_client.get(url_for(
|
||||||
|
'main.view_letter_notification_as_preview',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
notification_id=fake_uuid,
|
||||||
|
filetype='png'
|
||||||
|
))
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.get_data(as_text=True) == 'foo'
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_preview_error_image_letter_notification_on_preview_error(
|
def test_should_show_preview_error_image_letter_notification_on_preview_error(
|
||||||
logged_in_client,
|
logged_in_client,
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
|
|||||||
Reference in New Issue
Block a user