From 8fd5fa90ffe6b42f8de86e737b329ff52e23da83 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 19 Mar 2019 15:54:39 +0000 Subject: [PATCH] Make the letter-validation-preview url public. In the short term I have created a duplicate version of the letter-validation-preview so that people from a service can upload a pdf and see why the letter isnot validating. It's hard to get a precompiled letter to validate when starting to integrate with Notify. This will return the overlay of the letter validation and is now available to the services. At the moment they send us a PDF to upload. This is temporary because there is a story to create a one-off flow to get this overlay, that will replace this page. There is no navigation to this on purpose. --- app/main/views/platform_admin.py | 19 ++++++++-- app/navigation.py | 4 ++ .../views/letter-validation-preview.html | 37 +++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 app/templates/views/letter-validation-preview.html diff --git a/app/main/views/platform_admin.py b/app/main/views/platform_admin.py index 1029bba3c..c51ff7572 100644 --- a/app/main/views/platform_admin.py +++ b/app/main/views/platform_admin.py @@ -253,16 +253,29 @@ def platform_admin_returned_letters(): @login_required @user_is_platform_admin def platform_admin_letter_validation_preview(): + return letter_validation_preview(from_platform_admin=True) + + +@main.route("/services//letter-validation-preview", methods=["GET", "POST"]) +@login_required +def service_letter_validation_preview(service_id): + return letter_validation_preview(from_platform_admin=False) + + +def letter_validation_preview(from_platform_admin): message, pages, result = None, [], None form = PDFUploadForm() + view_location = 'views/platform-admin/letter-validation-preview.html' \ + if from_platform_admin else'views/letter-validation-preview.html' + if form.validate_on_submit(): pdf_file = form.file.data virus_free = antivirus_client.scan(pdf_file) if not virus_free: return render_template( - 'views/platform-admin/letter-validation-preview.html', + view_location, form=form, message="Document didn't pass the virus scan", pages=pages, result=result ), 400 @@ -275,14 +288,14 @@ def platform_admin_letter_validation_preview(): if error.response and error.response.status_code == 400: message = "Something was wrong with the file you tried to upload. Please upload a valid PDF file." return render_template( - 'views/platform-admin/letter-validation-preview.html', + view_location, form=form, message=message, pages=pages, result=result ), 400 else: raise error return render_template( - 'views/platform-admin/letter-validation-preview.html', + view_location, form=form, message=message, pages=pages, result=result ) diff --git a/app/navigation.py b/app/navigation.py index 512c568f5..fd6f18711 100644 --- a/app/navigation.py +++ b/app/navigation.py @@ -233,6 +233,7 @@ class HeaderNavigation(Navigation): 'service_edit_sms_sender', 'service_email_reply_to', 'service_letter_contact_details', + 'service_letter_validation_preview', 'service_name_change', 'service_name_change_confirm', 'service_preview_email_branding', @@ -487,6 +488,7 @@ class MainNavigation(Navigation): 'service_dashboard_updates', 'service_delete_email_reply_to', 'service_delete_sms_sender', + 'service_letter_validation_preview', 'service_switch_can_upload_document', 'service_switch_live', 'service_set_permission', @@ -701,6 +703,7 @@ class CaseworkNavigation(Navigation): 'service_edit_sms_sender', 'service_email_reply_to', 'service_letter_contact_details', + 'service_letter_validation_preview', 'service_name_change', 'service_name_change_confirm', 'service_preview_email_branding', @@ -940,6 +943,7 @@ class OrgNavigation(Navigation): 'service_edit_sms_sender', 'service_email_reply_to', 'service_letter_contact_details', + 'service_letter_validation_preview', 'service_name_change', 'service_name_change_confirm', 'service_preview_email_branding', diff --git a/app/templates/views/letter-validation-preview.html b/app/templates/views/letter-validation-preview.html new file mode 100644 index 000000000..e10499cea --- /dev/null +++ b/app/templates/views/letter-validation-preview.html @@ -0,0 +1,37 @@ +{% extends "withnav_template.html" %} +{% from "components/banner.html" import banner %} +{% from "components/textbox.html" import textbox %} +{% from "components/file-upload.html" import file_upload %} +{% from "components/page-footer.html" import page_footer %} + +{% from "components/form.html" import form_wrapper %} +{% block maincolumn_content %} + +
+
+ {% if result %} + {{ banner(message, with_tick=True) }} + {% elif message %} + {{ banner(message, 'dangerous')}} + {% endif %} + +

Letter Validation Preview

+
+ {{ file_upload( + form.file, + action = url_for('main.services_letter_validation_preview', service_id=current_service.id), + button_text='Upload a PDF document', + )}} +
+
+
+ + {% for page in pages %} +
+ +
+ {% endfor %} +
+
+ +{% endblock %}