From 813c786dc7e5c8bdd3cb7711f4c6b69c6f3d2f61 Mon Sep 17 00:00:00 2001 From: Aaron Tan Date: Wed, 26 Oct 2016 14:53:22 -0400 Subject: [PATCH] Add destory sanity checks to prevent UJ deletion during underlying workflow run. --- awx/api/views.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/awx/api/views.py b/awx/api/views.py index 66980e141d..ea38018267 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -1087,6 +1087,14 @@ class ProjectUpdateDetail(RetrieveDestroyAPIView): serializer_class = ProjectUpdateSerializer new_in_13 = True + def destroy(self, request, *args, **kwargs): + obj = self.get_object() + for unified_job_node in obj.unified_job_nodes.all(): + if unified_job_node.workflow_job.status in ('new', 'pending', 'waiting', + 'running', 'updating'): + raise PermissionDenied() + return super(ProjectUpdateDetail, self).destroy(request, *args, **kwargs) + class ProjectUpdateCancel(RetrieveAPIView): model = ProjectUpdate @@ -2166,6 +2174,14 @@ class InventoryUpdateDetail(RetrieveDestroyAPIView): serializer_class = InventoryUpdateSerializer new_in_14 = True + def destroy(self, request, *args, **kwargs): + obj = self.get_object() + for unified_job_node in obj.unified_job_nodes.all(): + if unified_job_node.workflow_job.status in ('new', 'pending', 'waiting', + 'running', 'updating'): + raise PermissionDenied() + return super(InventoryUpdateDetail, self).destroy(request, *args, **kwargs) + class InventoryUpdateCancel(RetrieveAPIView): model = InventoryUpdate @@ -2869,6 +2885,14 @@ class JobDetail(RetrieveUpdateDestroyAPIView): return self.http_method_not_allowed(request, *args, **kwargs) return super(JobDetail, self).update(request, *args, **kwargs) + def destroy(self, request, *args, **kwargs): + obj = self.get_object() + for unified_job_node in obj.unified_job_nodes.all(): + if unified_job_node.workflow_job.status in ('new', 'pending', 'waiting', + 'running', 'updating'): + raise PermissionDenied() + return super(JobDetail, self).destroy(request, *args, **kwargs) + class JobLabelList(SubListAPIView): model = Label