mirror of
https://github.com/ansible/awx.git
synced 2026-01-21 14:38:00 -03:30
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)
|
||||
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)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user