From 6a1973c873b285f90c4c91678c364e4bae931e00 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Thu, 7 Jul 2016 12:03:17 -0400 Subject: [PATCH] Disallow deleting job templates when there are jobs running --- awx/api/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index a9a2e80549..4ad0a9cc58 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -2188,8 +2188,9 @@ class JobTemplateDetail(RetrieveUpdateDestroyAPIView): can_delete = request.user.can_access(JobTemplate, 'delete', obj) if not can_delete: raise PermissionDenied("Cannot delete job template.") - for pu in obj.jobs.filter(status__in=['new', 'pending', 'waiting', 'running']): - pu.cancel() + if obj.jobs.filter(status__in=['new', 'pending', 'waiting', 'running']).exists(): + return Response({"error": "Delete not allowed while there are jobs running"}, + status=status.HTTP_405_METHOD_NOT_ALLOWED) return super(JobTemplateDetail, self).destroy(request, *args, **kwargs)