mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 23:51:09 +03:00
Disallow deleting job templates when there are jobs running
This commit is contained in:
parent
95be0e5011
commit
6a1973c873
@ -2188,8 +2188,9 @@ class JobTemplateDetail(RetrieveUpdateDestroyAPIView):
|
|||||||
can_delete = request.user.can_access(JobTemplate, 'delete', obj)
|
can_delete = request.user.can_access(JobTemplate, 'delete', obj)
|
||||||
if not can_delete:
|
if not can_delete:
|
||||||
raise PermissionDenied("Cannot delete job template.")
|
raise PermissionDenied("Cannot delete job template.")
|
||||||
for pu in obj.jobs.filter(status__in=['new', 'pending', 'waiting', 'running']):
|
if obj.jobs.filter(status__in=['new', 'pending', 'waiting', 'running']).exists():
|
||||||
pu.cancel()
|
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)
|
return super(JobTemplateDetail, self).destroy(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user