From 7ff23e049aba7de700466a607a9d52609dcfe4f0 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Wed, 19 Jul 2017 08:26:57 -0400 Subject: [PATCH] block deletion of inventory sources with running jobs --- awx/main/access.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/awx/main/access.py b/awx/main/access.py index e91a61dec6..91121928be 100644 --- a/awx/main/access.py +++ b/awx/main/access.py @@ -794,11 +794,14 @@ class InventorySourceAccess(BaseAccess): inventory=data.get('inventory'), update_on_project_update=True, source='scm').exists()) - @check_superuser def can_delete(self, obj): - if obj and obj.inventory: - return self.user.can_access(Inventory, 'admin', obj.inventory, None) - return False + if not (self.user.is_superuser or not (obj and obj.inventory and self.user.can_access(Inventory, 'admin', obj.inventory, None))): + return False + active_jobs_qs = InventoryUpdate.objects.filter(inventory_source=obj, status__in=ACTIVE_STATES) + if active_jobs_qs.exists(): + raise StateConflict({"conflict": _("Resource is being used by running jobs"), + "active_jobs": [dict(type="inventory_update", id=o.id) for o in active_jobs_qs.all()]}) + return True @check_superuser def can_change(self, obj, data):