more test fixes & letter trimming

This commit is contained in:
stvnrlly
2022-11-22 22:50:47 -05:00
parent ca1897973a
commit a2b58c926e
13 changed files with 33 additions and 606 deletions

View File

@@ -112,29 +112,6 @@ def cancel_job(service_id, job_id):
return redirect(url_for('main.service_dashboard', service_id=service_id))
@main.route("/services/<uuid:service_id>/jobs/<uuid:job_id>/cancel", methods=['GET', 'POST'])
@user_has_permissions()
def cancel_letter_job(service_id, job_id):
if request.method == 'POST':
job = Job.from_id(job_id, service_id=service_id)
if job.status != 'finished' or job.notifications_created < job.notification_count:
flash("We are still processing these letters, please try again in a minute.", 'try again')
return view_job(service_id, job_id)
try:
number_of_letters = job.cancel()
except HTTPError as e:
flash(e.message, 'dangerous')
return redirect(url_for('main.view_job', service_id=service_id, job_id=job_id))
flash("Cancelled {} letters from {}".format(
format_thousands(number_of_letters), job.original_file_name
), 'default_with_tick')
return redirect(url_for('main.service_dashboard', service_id=service_id))
flash("Are you sure you want to cancel sending these letters?", 'cancel')
return view_job(service_id, job_id)
@main.route("/services/<uuid:service_id>/jobs/<uuid:job_id>.json")
@user_has_permissions()
def view_job_updates(service_id, job_id):

View File

@@ -185,31 +185,6 @@ def view_notification(service_id, notification_id):
)
@main.route("/services/<uuid:service_id>/notification/<uuid:notification_id>/cancel", methods=['GET', 'POST'])
@user_has_permissions('view_activity', 'send_messages')
def cancel_letter(service_id, notification_id):
if request.method == 'POST':
try:
notification_api_client.update_notification_to_cancelled(current_service.id, notification_id)
except HTTPError as e:
message_fragments = ["already been cancelled", "too late to cancel"]
if e.status_code == 400 and any(fragment in e.message for fragment in message_fragments):
flash(e.message)
else:
raise e
return redirect(url_for('main.view_notification', service_id=service_id, notification_id=notification_id))
flash("Are you sure you want to cancel sending this letter?", 'cancel')
return view_notification(service_id, notification_id)
def get_preview_error_image():
path = os.path.join(os.path.dirname(__file__), "..", "..", "static", "images", "preview_error.png")
with open(path, "rb") as file:
return file.read()
@main.route("/services/<uuid:service_id>/notification/<uuid:notification_id>.<letter_file_extension:filetype>")
@user_has_permissions('view_activity', 'send_messages')
def view_letter_notification_as_preview(

View File

@@ -199,10 +199,7 @@ class Job(JSONModel):
)
def cancel(self):
if self.template_type == 'letter':
return job_api_client.cancel_letter_job(self.service, self.id)
else:
return job_api_client.cancel_job(self.service, self.id)
return job_api_client.cancel_job(self.service, self.id)
class ImmediateJobs(ModelList):

View File

@@ -115,12 +115,5 @@ class JobApiClient(NotifyAdminAPIClient):
data={}
)
@cache.delete('has_jobs-{service_id}')
def cancel_letter_job(self, service_id, job_id):
return self.post(
url='/service/{}/job/{}/cancel-letter-job'.format(service_id, job_id),
data={}
)
job_api_client = JobApiClient()

View File

@@ -9,10 +9,6 @@
{{ job.original_file_name }}
{% endblock %}
{% block backLink %}
{{ govukBackLink({ "href": url_for('main.uploads', service_id=current_service.id) }) }}
{% endblock %}
{% block maincolumn_content %}
{{ page_header(job.original_file_name) }}

View File

@@ -50,20 +50,7 @@
{{ template|string }}
</div>
{% if template.template_type == 'letter' %}
<div class="js-stick-at-bottom-when-scrolling">
<div class="page-footer">
{% if show_cancel_button %}
<span class="page-footer-delete-link page-footer-delete-link-without-button">
<a class="govuk-link govuk-link--destructive" href="{{ url_for('main.cancel_letter', service_id=current_service.id, notification_id=notification_id) }}">Cancel sending this letter</a>
</span>
{% else %}
<div>&nbsp;</div>
{% endif %}
<a class="govuk-link govuk-link--no-visited-state page-footer-right-aligned-link-without-button" href="{{ url_for('main.view_letter_notification_as_preview', service_id=current_service.id, notification_id=notification_id, filetype='pdf') }}" download>Download as a PDF</a>
</div>
</div>
{% elif template.template_type == 'email' %}
{% if template.template_type == 'email' %}
<div class="js-stick-at-bottom-when-scrolling">
{{ ajax_block(partials, updates_url, 'status', finished=finished) }}
</div>