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(