mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
Can't cancel letter job if job not processed yet
Also add more tests for showing or not the cancel those letters link Also check if all notifications already in database Upgrade delete button text logic to handle more cases Also corrections following review
This commit is contained in:
@@ -173,17 +173,25 @@ def cancel_job(service_id, job_id):
|
||||
@main.route("/services/<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_api_client.get_job(service_id, job_id)['data']
|
||||
notifications = notification_api_client.get_notifications_for_service(
|
||||
job['service'], job['id']
|
||||
)['notifications']
|
||||
if job['job_status'] != 'finished' or len(notifications) < 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_api_client.cancel_letter_job(current_service.id, job_id)
|
||||
except HTTPError as e:
|
||||
flash(e.message, 'dangerous')
|
||||
return redirect(url_for('main.view_job', service_id=service_id, job_id=job_id))
|
||||
flash(" {} letters have been cancelled succesfully".format(number_of_letters), 'default_with_tick')
|
||||
flash("Cancelled {:,.0f} letters from {}".format(
|
||||
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 those letters?", 'cancel')
|
||||
flash("Are you sure you want to cancel sending these letters?", 'cancel')
|
||||
return view_job(service_id, job_id)
|
||||
|
||||
|
||||
@@ -435,12 +443,10 @@ def get_job_partials(job, template):
|
||||
n for n in notifications["notifications"] if n["status"] not in CANCELLABLE_JOB_LETTER_STATUSES
|
||||
]
|
||||
job_created = job["created_at"][:-6]
|
||||
if job["job_status"] != "finished":
|
||||
can_letter_job_be_cancelled = "This job is still being processed. Wait a couple of minutes and try again."
|
||||
elif not letter_can_be_cancelled(
|
||||
if not letter_can_be_cancelled(
|
||||
"created", datetime.strptime(job_created, '%Y-%m-%dT%H:%M:%S.%f')
|
||||
) or len(not_cancellable) != 0:
|
||||
can_letter_job_be_cancelled = "Cancel sending those letters"
|
||||
can_letter_job_be_cancelled = False
|
||||
else:
|
||||
can_letter_job_be_cancelled = True
|
||||
return {
|
||||
|
||||
@@ -2,11 +2,18 @@
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
{% if category in ['cancel', 'delete', 'suspend', 'resume', 'remove', 'revoke this API key'] %}
|
||||
{% set delete_button_text = "Yes, {}".format(category) %}
|
||||
{% elif category == 'try again' %}
|
||||
{% set delete_button_text = category|capitalize %}
|
||||
{% else %}
|
||||
{% set delete_button_text = None %}
|
||||
{% endif %}
|
||||
<div class="bottom-gutter">
|
||||
{{ banner(
|
||||
message if message is string else message[0],
|
||||
'default' if ((category == 'default') or (category == 'default_with_tick')) else 'dangerous',
|
||||
delete_button="Yes, {}".format(category) if category in ['cancel', 'delete', 'suspend', 'resume', 'remove', 'revoke this API key'] else None,
|
||||
delete_button=delete_button_text,
|
||||
with_tick=True if category == 'default_with_tick' else False,
|
||||
context=message[1] if message is not string
|
||||
)}}
|
||||
|
||||
@@ -25,11 +25,7 @@
|
||||
<div class="js-stick-at-bottom-when-scrolling">
|
||||
<div class="page-footer">
|
||||
<span class="page-footer-delete-link page-footer-delete-link-without-button">
|
||||
{% if can_cancel_letter_job == True %}
|
||||
<a href="{{ url_for('main.cancel_letter_job', service_id=current_service.id, job_id=job_id) }}">Cancel sending those letters</a>
|
||||
{% else %}
|
||||
<p> Can't cancel: {{ can_cancel_letter_job }} </p>
|
||||
{% endif %}
|
||||
<a href="{{ url_for('main.cancel_letter_job', service_id=current_service.id, job_id=job_id) }}">Cancel sending these letters</a>
|
||||
</span>
|
||||
{% else %}
|
||||
<div> </div>
|
||||
|
||||
Reference in New Issue
Block a user