mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
Add support for deleting ad hoc commands. Fixes https://trello.com/c/WLnhi28V
This commit is contained in:
@@ -2358,7 +2358,7 @@ class HostAdHocCommandsList(AdHocCommandList, SubListCreateAPIView):
|
|||||||
relationship = 'ad_hoc_commands'
|
relationship = 'ad_hoc_commands'
|
||||||
|
|
||||||
|
|
||||||
class AdHocCommandDetail(RetrieveAPIView):
|
class AdHocCommandDetail(RetrieveDestroyAPIView):
|
||||||
|
|
||||||
model = AdHocCommand
|
model = AdHocCommand
|
||||||
serializer_class = AdHocCommandSerializer
|
serializer_class = AdHocCommandSerializer
|
||||||
|
|||||||
@@ -1226,7 +1226,7 @@ class AdHocCommandAccess(BaseAccess):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def can_delete(self, obj):
|
def can_delete(self, obj):
|
||||||
return False
|
return self.can_read(obj)
|
||||||
|
|
||||||
def can_start(self, obj):
|
def can_start(self, obj):
|
||||||
return self.can_add({
|
return self.can_add({
|
||||||
|
|||||||
@@ -560,12 +560,14 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
|
|||||||
|
|
||||||
def test_ad_hoc_command_detail(self):
|
def test_ad_hoc_command_detail(self):
|
||||||
with self.current_user('admin'):
|
with self.current_user('admin'):
|
||||||
response = self.run_test_ad_hoc_command()
|
response1 = self.run_test_ad_hoc_command()
|
||||||
|
response2 = self.run_test_ad_hoc_command()
|
||||||
|
response3 = self.run_test_ad_hoc_command()
|
||||||
|
|
||||||
# Retrieve detail for ad hoc command. Only GET is supported.
|
# Retrieve detail for ad hoc command. Only GET is supported.
|
||||||
url = reverse('api:ad_hoc_command_detail', args=(response['id'],))
|
|
||||||
self.assertEqual(url, response['url'])
|
|
||||||
with self.current_user('admin'):
|
with self.current_user('admin'):
|
||||||
|
url = reverse('api:ad_hoc_command_detail', args=(response1['id'],))
|
||||||
|
self.assertEqual(url, response1['url'])
|
||||||
response = self.get(url, expect=200)
|
response = self.get(url, expect=200)
|
||||||
self.assertEqual(response['credential'], self.credential.pk)
|
self.assertEqual(response['credential'], self.credential.pk)
|
||||||
self.assertEqual(response['related']['credential'],
|
self.assertEqual(response['related']['credential'],
|
||||||
@@ -580,22 +582,28 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
|
|||||||
self.assertTrue(response['related']['activity_stream'])
|
self.assertTrue(response['related']['activity_stream'])
|
||||||
self.put(url, {}, expect=405)
|
self.put(url, {}, expect=405)
|
||||||
self.patch(url, {}, expect=405)
|
self.patch(url, {}, expect=405)
|
||||||
self.delete(url, expect=405)
|
self.delete(url, expect=204)
|
||||||
|
self.delete(url, expect=404)
|
||||||
with self.current_user('normal'):
|
with self.current_user('normal'):
|
||||||
|
url = reverse('api:ad_hoc_command_detail', args=(response2['id'],))
|
||||||
|
self.assertEqual(url, response2['url'])
|
||||||
response = self.get(url, expect=200)
|
response = self.get(url, expect=200)
|
||||||
self.put(url, {}, expect=405)
|
self.put(url, {}, expect=405)
|
||||||
self.patch(url, {}, expect=405)
|
self.patch(url, {}, expect=405)
|
||||||
self.delete(url, expect=405)
|
self.delete(url, expect=204)
|
||||||
|
self.delete(url, expect=404)
|
||||||
|
url = reverse('api:ad_hoc_command_detail', args=(response3['id'],))
|
||||||
|
self.assertEqual(url, response3['url'])
|
||||||
with self.current_user('other'):
|
with self.current_user('other'):
|
||||||
response = self.get(url, expect=403)
|
response = self.get(url, expect=403)
|
||||||
self.put(url, {}, expect=405)
|
self.put(url, {}, expect=405)
|
||||||
self.patch(url, {}, expect=405)
|
self.patch(url, {}, expect=405)
|
||||||
self.delete(url, expect=405)
|
self.delete(url, expect=403)
|
||||||
with self.current_user('nobody'):
|
with self.current_user('nobody'):
|
||||||
response = self.get(url, expect=403)
|
response = self.get(url, expect=403)
|
||||||
self.put(url, {}, expect=405)
|
self.put(url, {}, expect=405)
|
||||||
self.patch(url, {}, expect=405)
|
self.patch(url, {}, expect=405)
|
||||||
self.delete(url, expect=405)
|
self.delete(url, expect=403)
|
||||||
with self.current_user(None):
|
with self.current_user(None):
|
||||||
response = self.get(url, expect=401)
|
response = self.get(url, expect=401)
|
||||||
self.put(url, {}, expect=401)
|
self.put(url, {}, expect=401)
|
||||||
@@ -603,13 +611,16 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
|
|||||||
self.delete(url, expect=401)
|
self.delete(url, expect=401)
|
||||||
|
|
||||||
# Verify that the credential and inventory are null when they have
|
# Verify that the credential and inventory are null when they have
|
||||||
# been deleted.
|
# been deleted, can delete an ad hoc command without inventory or
|
||||||
|
# credential.
|
||||||
self.credential.mark_inactive()
|
self.credential.mark_inactive()
|
||||||
self.inventory.mark_inactive()
|
self.inventory.mark_inactive()
|
||||||
with self.current_user('admin'):
|
with self.current_user('admin'):
|
||||||
response = self.get(url, expect=200)
|
response = self.get(url, expect=200)
|
||||||
self.assertEqual(response['credential'], None)
|
self.assertEqual(response['credential'], None)
|
||||||
self.assertEqual(response['inventory'], None)
|
self.assertEqual(response['inventory'], None)
|
||||||
|
self.delete(url, expect=204)
|
||||||
|
self.delete(url, expect=404)
|
||||||
|
|
||||||
def test_ad_hoc_command_cancel(self):
|
def test_ad_hoc_command_cancel(self):
|
||||||
# Override setting so that ad hoc command isn't actually started.
|
# Override setting so that ad hoc command isn't actually started.
|
||||||
|
|||||||
Reference in New Issue
Block a user