mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 05:59:44 -04:00
Add a cancel job button
If you schedule a job you might change your mind or circumstances might change. So you need to be able to cancel it. This commit adds a button on the job page which hits the `…/cancel` API endpoint for a job.
This commit is contained in:
@@ -12,7 +12,8 @@ from flask import (
|
||||
jsonify,
|
||||
request,
|
||||
url_for,
|
||||
current_app
|
||||
current_app,
|
||||
redirect
|
||||
)
|
||||
from flask_login import login_required
|
||||
from werkzeug.datastructures import MultiDict
|
||||
@@ -147,6 +148,14 @@ def view_job_csv(service_id, job_id):
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/jobs/<job_id>", methods=['POST'])
|
||||
@login_required
|
||||
@user_has_permissions('send_texts', 'send_emails', 'send_letters', admin_override=True)
|
||||
def cancel_job(service_id, job_id):
|
||||
job_api_client.cancel_job(service_id, job_id)
|
||||
return redirect(url_for('main.service_dashboard', service_id=service_id))
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/jobs/<job_id>.json")
|
||||
@login_required
|
||||
@user_has_permissions('view_activity', admin_override=True)
|
||||
|
||||
@@ -77,3 +77,18 @@ class JobApiClient(BaseAPIClient):
|
||||
job['data']['notifications_requested'] = stats['requested']
|
||||
|
||||
return job
|
||||
|
||||
def cancel_job(self, service_id, job_id):
|
||||
|
||||
job = self.post(
|
||||
url='/service/{}/job/{}/cancel'.format(service_id, job_id),
|
||||
data={}
|
||||
)
|
||||
|
||||
stats = self.__convert_statistics(job['data'])
|
||||
job['data']['notifications_sent'] = stats['delivered'] + stats['failed']
|
||||
job['data']['notifications_delivered'] = stats['delivered']
|
||||
job['data']['notifications_failed'] = stats['failed']
|
||||
job['data']['notifications_requested'] = stats['requested']
|
||||
|
||||
return job
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% from "components/table.html" import list_table, field, right_aligned_field_heading, date_field, row_heading %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
|
||||
<div class="ajax-block-container">
|
||||
{% if job.job_status == 'scheduled' %}
|
||||
@@ -6,6 +7,14 @@
|
||||
<p>
|
||||
Sending will start at {{ job.scheduled_for|format_time }}
|
||||
</p>
|
||||
<div class="page-footer">
|
||||
<form method="post">
|
||||
{{ page_footer(
|
||||
button_text="Cancel sending",
|
||||
destructive=True
|
||||
) }}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% else %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user