mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 13:39:41 -04:00
Remove the letter validation preview endpoints
We can use the ‘Uploads’ feature to check if letters are printable now. This code works in a completely different way, so if we kept it we’d have to maintain two different code paths, and make sure that they didn’t diverge. Also deletes the related HTML templates.
This commit is contained in:
@@ -386,77 +386,6 @@ def platform_admin_returned_letters():
|
||||
)
|
||||
|
||||
|
||||
@main.route("/platform-admin/letter-validation-preview", methods=["GET", "POST"])
|
||||
@user_is_platform_admin
|
||||
def platform_admin_letter_validation_preview():
|
||||
return letter_validation_preview(from_platform_admin=True)
|
||||
|
||||
|
||||
@main.route("/services/<uuid:service_id>/letter-validation-preview", methods=["GET", "POST"])
|
||||
@user_has_permissions()
|
||||
def service_letter_validation_preview(service_id):
|
||||
return letter_validation_preview(from_platform_admin=False)
|
||||
|
||||
|
||||
def letter_validation_preview(from_platform_admin):
|
||||
message, pages, passed_validation, error_code = None, [], 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(
|
||||
view_location,
|
||||
form=form, message="Document did not pass the virus scan",
|
||||
pages=pages, passed_validation=passed_validation
|
||||
), 400
|
||||
|
||||
try:
|
||||
if len(pdf_file.read()) > (2 * 1024 * 1024):
|
||||
return render_template(
|
||||
view_location,
|
||||
form=form,
|
||||
message="File must be less than 2MB",
|
||||
pages=pages, passed_validation=passed_validation
|
||||
), 400
|
||||
pdf_file.seek(0)
|
||||
response = validate_letter(pdf_file)
|
||||
response.raise_for_status()
|
||||
if response.status_code == 200:
|
||||
pages, message = response.json()["pages"], response.json()["message"],
|
||||
passed_validation = response.json()["result"]
|
||||
invalid_pages = response.json().get('invalid_pages')
|
||||
page_count = len(pages)
|
||||
if page_count > LETTER_MAX_PAGE_COUNT:
|
||||
message = "letter-too-long"
|
||||
passed_validation = False
|
||||
|
||||
if not passed_validation:
|
||||
error_code = message
|
||||
message = get_letter_validation_error(
|
||||
message, invalid_pages=invalid_pages, page_count=page_count
|
||||
)
|
||||
except RequestException as error:
|
||||
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(
|
||||
view_location,
|
||||
form=form, message=message, pages=pages, passed_validation=passed_validation
|
||||
), 400
|
||||
else:
|
||||
raise error
|
||||
|
||||
return render_template(
|
||||
view_location,
|
||||
form=form, message=message, pages=pages, passed_validation=passed_validation, error_code=error_code
|
||||
)
|
||||
|
||||
|
||||
@main.route("/platform-admin/clear-cache", methods=['GET', 'POST'])
|
||||
@user_is_platform_admin
|
||||
def clear_cache():
|
||||
|
||||
@@ -94,7 +94,6 @@ class HeaderNavigation(Navigation):
|
||||
'performance_platform_xlsx',
|
||||
'usage_for_all_services',
|
||||
'platform_admin',
|
||||
'platform_admin_letter_validation_preview',
|
||||
'platform_admin_list_complaints',
|
||||
'platform_admin_reports',
|
||||
'platform_admin_returned_letters',
|
||||
@@ -267,7 +266,6 @@ class HeaderNavigation(Navigation):
|
||||
'service_edit_sms_sender',
|
||||
'service_email_reply_to',
|
||||
'service_letter_contact_details',
|
||||
'service_letter_validation_preview',
|
||||
'service_make_blank_default_letter_contact',
|
||||
'service_name_change',
|
||||
'service_name_change_confirm',
|
||||
@@ -539,7 +537,6 @@ class MainNavigation(Navigation):
|
||||
'organisations',
|
||||
'performance_platform_xlsx',
|
||||
'platform_admin',
|
||||
'platform_admin_letter_validation_preview',
|
||||
'platform_admin_list_complaints',
|
||||
'platform_admin_reports',
|
||||
'platform_admin_returned_letters',
|
||||
@@ -566,7 +563,6 @@ class MainNavigation(Navigation):
|
||||
'service_delete_letter_contact',
|
||||
'service_delete_sms_sender',
|
||||
'service_download_agreement',
|
||||
'service_letter_validation_preview',
|
||||
'service_switch_can_upload_document',
|
||||
'service_switch_count_as_live',
|
||||
'service_switch_live',
|
||||
@@ -772,7 +768,6 @@ class CaseworkNavigation(Navigation):
|
||||
'organisation_settings',
|
||||
'organisations',
|
||||
'performance_platform_xlsx',
|
||||
'platform_admin_letter_validation_preview',
|
||||
'platform_admin_list_complaints',
|
||||
'platform_admin_reports',
|
||||
'platform_admin_returned_letters',
|
||||
@@ -822,7 +817,6 @@ class CaseworkNavigation(Navigation):
|
||||
'service_edit_sms_sender',
|
||||
'service_email_reply_to',
|
||||
'service_letter_contact_details',
|
||||
'service_letter_validation_preview',
|
||||
'service_make_blank_default_letter_contact',
|
||||
'service_name_change',
|
||||
'service_name_change_confirm',
|
||||
@@ -1051,7 +1045,6 @@ class OrgNavigation(Navigation):
|
||||
'organisations',
|
||||
'performance_platform_xlsx',
|
||||
'platform_admin',
|
||||
'platform_admin_letter_validation_preview',
|
||||
'platform_admin_list_complaints',
|
||||
'platform_admin_reports',
|
||||
'platform_admin_returned_letters',
|
||||
@@ -1103,7 +1096,6 @@ class OrgNavigation(Navigation):
|
||||
'service_edit_sms_sender',
|
||||
'service_email_reply_to',
|
||||
'service_letter_contact_details',
|
||||
'service_letter_validation_preview',
|
||||
'service_make_blank_default_letter_contact',
|
||||
'service_name_change',
|
||||
'service_name_change_confirm',
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
{% 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 service_page_title %}
|
||||
Letter validation preview
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
<div class="grid-row">
|
||||
<div class="column-whole">
|
||||
{% if passed_validation %}
|
||||
{{ banner(message, with_tick=True) }}
|
||||
{% elif message %}
|
||||
{% include "partials/check/letter-validation-failed-banner.html" %}
|
||||
{% endif %}
|
||||
|
||||
<h1 class="heading-large">Letter validation preview</h1>
|
||||
<div class="bottom-gutter">
|
||||
{{ file_upload(
|
||||
form.file,
|
||||
action = url_for('main.service_letter_validation_preview', service_id=current_service.id),
|
||||
button_text='Choose a file',
|
||||
)}}
|
||||
</div>
|
||||
{%if not pages %}
|
||||
<div>
|
||||
<p>Your file must be:
|
||||
<li>a PDF</li>
|
||||
<li>no more than 10 pages long</li>
|
||||
<li>less than 2 MB</li>
|
||||
</p>
|
||||
<p>The content of your letter must appear inside the printable area.</p>
|
||||
<p>
|
||||
<a href="https://docs.notifications.service.gov.uk/documentation/images/notify-pdf-letter-spec-v2.4.pdf">
|
||||
Download the letter specification</a> for more information.
|
||||
</p>
|
||||
</div>
|
||||
{% endif%}
|
||||
</div>
|
||||
<div class="column-whole template-container" >
|
||||
|
||||
{% for page in pages %}
|
||||
<div class="letter">
|
||||
<img src="data:image/png;base64,{{ page }}">
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -24,7 +24,6 @@
|
||||
('Find users by email', url_for('main.find_users_by_email')),
|
||||
('Email Complaints', url_for('main.platform_admin_list_complaints')),
|
||||
('Returned letters', url_for('main.platform_admin_returned_letters')),
|
||||
('Letter validation preview', url_for('main.platform_admin_letter_validation_preview')),
|
||||
('Clear cache', url_for('main.clear_cache')),
|
||||
] %}
|
||||
<li>
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
{% extends "views/platform-admin/_base_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 %}
|
||||
|
||||
{% block per_page_title %}
|
||||
{{ page_title|capitalize }}
|
||||
{% endblock %}
|
||||
|
||||
{% block platform_admin_content %}
|
||||
|
||||
<div class="grid-row">
|
||||
<div class="column-whole">
|
||||
<h1 class="heading-large">Letter Validation Preview</h1>
|
||||
|
||||
{{ file_upload(
|
||||
form.file,
|
||||
action = url_for('main.platform_admin_letter_validation_preview'),
|
||||
button_text='Upload a PDF document',
|
||||
)}}
|
||||
</div>
|
||||
<div class="column-whole template-container">
|
||||
{% if passed_validation %}
|
||||
{{ banner(message, with_tick=True) }}
|
||||
{% elif message %}
|
||||
{% include "partials/check/letter-validation-failed-banner.html" %}
|
||||
{% endif %}
|
||||
|
||||
{% for page in pages %}
|
||||
<div class="letter">
|
||||
<img src="data:image/png;base64,{{ page }}">
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user