1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

Disallow deleting job templates when there are jobs running

This commit is contained in:
Matthew Jones 2016-07-07 12:03:17 -04:00
parent 95be0e5011
commit 6a1973c873

View File

@ -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)