From 2d1d3715827c05a2b2732026bb09fc8c6d981bb3 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Mon, 11 May 2015 20:32:43 -0400 Subject: [PATCH] Return 400 when attempting to relaunch an ad hoc command with deleted inventory. Fixes https://trello.com/c/IbvBelXJ --- awx/main/access.py | 4 ++-- awx/main/tests/ad_hoc.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/awx/main/access.py b/awx/main/access.py index cd63cc41e4..1cbc50bf09 100644 --- a/awx/main/access.py +++ b/awx/main/access.py @@ -1208,7 +1208,7 @@ class AdHocCommandAccess(BaseAccess): # If a credential is provided, the user should have read access to it. credential_pk = get_pk_from_dict(data, 'credential') if credential_pk: - credential = get_object_or_400(Credential, pk=credential_pk) + credential = get_object_or_400(Credential, pk=credential_pk, active=True) if not self.user.can_access(Credential, 'read', credential): return False @@ -1216,7 +1216,7 @@ class AdHocCommandAccess(BaseAccess): # given inventory. inventory_pk = get_pk_from_dict(data, 'inventory') if inventory_pk: - inventory = get_object_or_400(Inventory, pk=inventory_pk) + inventory = get_object_or_400(Inventory, pk=inventory_pk, active=True) if not self.user.can_access(Inventory, 'run_ad_hoc_commands', inventory): return False diff --git a/awx/main/tests/ad_hoc.py b/awx/main/tests/ad_hoc.py index 00d87ece66..581981f5d7 100644 --- a/awx/main/tests/ad_hoc.py +++ b/awx/main/tests/ad_hoc.py @@ -719,6 +719,13 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): self.patch(url, {}, expect=401) self.delete(url, expect=401) + # Try to relaunch after the inventory has been marked inactive. + self.inventory.mark_inactive() + with self.current_user('admin'): + response = self.get(url, expect=200) + self.assertEqual(response['passwords_needed_to_start'], []) + response = self.post(url, {}, expect=400) + def test_ad_hoc_command_events_list(self): with self.current_user('admin'): response = self.run_test_ad_hoc_command()