From a9d88f728da8b4f44730e5156d432e1dfebdc010 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Thu, 15 Nov 2018 11:11:32 -0500 Subject: [PATCH] Pre-delete bulk delete related, fix parallel request conflicts --- awx/api/generics.py | 3 +-- awx/api/views/__init__.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/awx/api/generics.py b/awx/api/generics.py index b4745d1f4f..75f1698e2d 100644 --- a/awx/api/generics.py +++ b/awx/api/generics.py @@ -552,9 +552,8 @@ class SubListDestroyAPIView(DestroyAPIView, SubListAPIView): def perform_list_destroy(self, instance_list): if self.check_sub_obj_permission: - # Check permissions for all before deleting, avoiding half-deleted lists for instance in instance_list: - if self.has_delete_permission(instance): + if not self.has_delete_permission(instance): raise PermissionDenied() for instance in instance_list: self.perform_destroy(instance, check_permission=False) diff --git a/awx/api/views/__init__.py b/awx/api/views/__init__.py index 0d2d0fdd21..eaa2b77edb 100644 --- a/awx/api/views/__init__.py +++ b/awx/api/views/__init__.py @@ -2056,6 +2056,14 @@ class InventorySourceHostsList(HostRelatedSearchMixin, SubListDestroyAPIView): relationship = 'hosts' check_sub_obj_permission = False + def perform_list_destroy(self, instance_list): + # Activity stream doesn't record disassociation here anyway + # no signals-related reason to not bulk-delete + Host.groups.through.objects.filter( + host__inventory_sources=self.get_parent_object() + ).delete() + return super(InventorySourceHostsList, self).perform_list_destroy(instance_list) + class InventorySourceGroupsList(SubListDestroyAPIView): @@ -2065,6 +2073,13 @@ class InventorySourceGroupsList(SubListDestroyAPIView): relationship = 'groups' check_sub_obj_permission = False + def perform_list_destroy(self, instance_list): + # Same arguments for bulk delete as with host list + Group.hosts.through.objects.filter( + group__inventory_sources=self.get_parent_object() + ).delete() + return super(InventorySourceGroupsList, self).perform_list_destroy(instance_list) + class InventorySourceUpdatesList(SubListAPIView):