From 454690a0087d332281a6b17d1e0aa7adeb01ef24 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Wed, 24 Apr 2019 18:29:01 +0100 Subject: [PATCH] Fix bug in precompiled preview with overlay The bug treated all pages of png preview as if they were all first page, showing overlay for address bar --- app/template/rest.py | 5 +++-- tests/app/template/test_rest.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/template/rest.py b/app/template/rest.py index 7c44ec405..7c8a7162a 100644 --- a/app/template/rest.py +++ b/app/template/rest.py @@ -240,10 +240,11 @@ def preview_letter_template_by_notification_id(service_id, notification_id, file if overlay: path = '/precompiled/overlay.{}'.format(file_type) + query_string = '?page_number={}'.format(page_number) if file_type == 'png' else '' content = pdf_file elif file_type == 'png': query_string = '?hide_notify=true' if page_number == '1' else '' - path = '/precompiled-preview.png' + query_string + path = '/precompiled-preview.png' else: path = None @@ -259,7 +260,7 @@ def preview_letter_template_by_notification_id(service_id, notification_id, file ) if path: - url = current_app.config['TEMPLATE_PREVIEW_API_HOST'] + path + url = current_app.config['TEMPLATE_PREVIEW_API_HOST'] + path + query_string response_content = _get_png_preview_or_overlaid_pdf(url, content, notification.id, json=False) else: response_content = content diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index e2d5caeb3..aec8af030 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -1102,7 +1102,7 @@ def test_preview_letter_template_precompiled_s3_error( "filetype, post_url, overlay", [ ('png', 'precompiled-preview.png', None), - ('png', 'precompiled/overlay.png', 1), + ('png', 'precompiled/overlay.png?page_number=1', 1), ('pdf', 'precompiled/overlay.pdf', 1) ] )