mirror of
https://github.com/ansible/awx.git
synced 2026-03-10 05:59:28 -02:30
AC-1116 Support for deleting project/inventory updates.
This commit is contained in:
@@ -26,11 +26,10 @@ from rest_framework import views
|
|||||||
from awx.main.models import *
|
from awx.main.models import *
|
||||||
from awx.main.utils import *
|
from awx.main.utils import *
|
||||||
|
|
||||||
# FIXME: machinery for auto-adding audit trail logs to all CREATE/EDITS
|
__all__ = ['APIView', 'GenericAPIView', 'ListAPIView', 'SimpleListAPIView',
|
||||||
|
'ListCreateAPIView', 'SubListAPIView', 'SubListCreateAPIView',
|
||||||
__all__ = ['APIView', 'GenericAPIView', 'ListAPIView', 'SimpleListAPIView', 'ListCreateAPIView',
|
'RetrieveAPIView', 'RetrieveUpdateAPIView',
|
||||||
'SubListAPIView', 'SubListCreateAPIView', 'RetrieveAPIView',
|
'RetrieveDestroyAPIView', 'RetrieveUpdateDestroyAPIView']
|
||||||
'RetrieveUpdateAPIView', 'RetrieveUpdateDestroyAPIView']
|
|
||||||
|
|
||||||
def get_view_name(cls, suffix=None):
|
def get_view_name(cls, suffix=None):
|
||||||
'''
|
'''
|
||||||
@@ -433,7 +432,7 @@ class RetrieveUpdateAPIView(RetrieveAPIView, generics.RetrieveUpdateAPIView):
|
|||||||
''' scrub any fields the user cannot/should not put/patch, based on user context. This runs after read-only serialization filtering '''
|
''' scrub any fields the user cannot/should not put/patch, based on user context. This runs after read-only serialization filtering '''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class RetrieveUpdateDestroyAPIView(RetrieveUpdateAPIView, generics.RetrieveUpdateDestroyAPIView):
|
class RetrieveDestroyAPIView(RetrieveAPIView, generics.RetrieveDestroyAPIView):
|
||||||
|
|
||||||
def destroy(self, request, *args, **kwargs):
|
def destroy(self, request, *args, **kwargs):
|
||||||
# somewhat lame that delete has to call it's own permissions check
|
# somewhat lame that delete has to call it's own permissions check
|
||||||
@@ -450,3 +449,6 @@ class RetrieveUpdateDestroyAPIView(RetrieveUpdateAPIView, generics.RetrieveUpdat
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError('destroy() not implemented yet for %s' % obj)
|
raise NotImplementedError('destroy() not implemented yet for %s' % obj)
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
class RetrieveUpdateDestroyAPIView(RetrieveUpdateAPIView, RetrieveDestroyAPIView):
|
||||||
|
pass
|
||||||
|
|||||||
12
awx/api/templates/api/retrieve_destroy_api_view.md
Normal file
12
awx/api/templates/api/retrieve_destroy_api_view.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Retrieve {{ model_verbose_name|title }}:
|
||||||
|
|
||||||
|
Make GET request to this resource to retrieve a single {{ model_verbose_name }}
|
||||||
|
record containing the following fields:
|
||||||
|
|
||||||
|
{% include "api/_result_fields_common.md" %}
|
||||||
|
|
||||||
|
# Delete {{ model_verbose_name|title }}:
|
||||||
|
|
||||||
|
Make a DELETE request to this resource to delete this {{ model_verbose_name }}.
|
||||||
|
|
||||||
|
{% include "api/_new_in_awx.md" %}
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
{% include "api/retrieve_api_view.md" %}
|
# Retrieve {{ model_verbose_name|title }}:
|
||||||
|
|
||||||
|
Make GET request to this resource to retrieve a single {{ model_verbose_name }}
|
||||||
|
record containing the following fields:
|
||||||
|
|
||||||
|
{% include "api/_result_fields_common.md" %}
|
||||||
|
|
||||||
# Update {{ model_verbose_name|title }}:
|
# Update {{ model_verbose_name|title }}:
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
{% include "api/retrieve_api_view.md" %}
|
# Retrieve {{ model_verbose_name|title }}:
|
||||||
|
|
||||||
|
Make GET request to this resource to retrieve a single {{ model_verbose_name }}
|
||||||
|
record containing the following fields:
|
||||||
|
|
||||||
|
{% include "api/_result_fields_common.md" %}
|
||||||
|
|
||||||
# Update {{ model_verbose_name|title }}:
|
# Update {{ model_verbose_name|title }}:
|
||||||
|
|
||||||
|
|||||||
@@ -500,7 +500,7 @@ class ProjectUpdateView(GenericAPIView):
|
|||||||
else:
|
else:
|
||||||
return self.http_method_not_allowed(request, *args, **kwargs)
|
return self.http_method_not_allowed(request, *args, **kwargs)
|
||||||
|
|
||||||
class ProjectUpdateDetail(RetrieveAPIView):
|
class ProjectUpdateDetail(RetrieveDestroyAPIView):
|
||||||
|
|
||||||
model = ProjectUpdate
|
model = ProjectUpdate
|
||||||
serializer_class = ProjectUpdateSerializer
|
serializer_class = ProjectUpdateSerializer
|
||||||
@@ -1064,7 +1064,7 @@ class InventorySourceUpdateView(GenericAPIView):
|
|||||||
else:
|
else:
|
||||||
return self.http_method_not_allowed(request, *args, **kwargs)
|
return self.http_method_not_allowed(request, *args, **kwargs)
|
||||||
|
|
||||||
class InventoryUpdateDetail(RetrieveAPIView):
|
class InventoryUpdateDetail(RetrieveDestroyAPIView):
|
||||||
|
|
||||||
model = InventoryUpdate
|
model = InventoryUpdate
|
||||||
serializer_class = InventoryUpdateSerializer
|
serializer_class = InventoryUpdateSerializer
|
||||||
|
|||||||
@@ -482,6 +482,7 @@ class InventoryUpdateAccess(BaseAccess):
|
|||||||
'''
|
'''
|
||||||
I can see inventory updates when I can see the inventory source.
|
I can see inventory updates when I can see the inventory source.
|
||||||
I can change inventory updates whenever I can change their source.
|
I can change inventory updates whenever I can change their source.
|
||||||
|
I can delete when I can change/delete the inventory source.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
model = InventoryUpdate
|
model = InventoryUpdate
|
||||||
@@ -673,6 +674,7 @@ class ProjectUpdateAccess(BaseAccess):
|
|||||||
'''
|
'''
|
||||||
I can see project updates when I can see the project.
|
I can see project updates when I can see the project.
|
||||||
I can change when I can change the project.
|
I can change when I can change the project.
|
||||||
|
I can delete when I can change/delete the project.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
model = ProjectUpdate
|
model = ProjectUpdate
|
||||||
|
|||||||
@@ -1094,6 +1094,12 @@ class InventoryUpdatesTest(BaseTransactionTest):
|
|||||||
})
|
})
|
||||||
response = self.put(inv_src_url2, data, expect=400)
|
response = self.put(inv_src_url2, data, expect=400)
|
||||||
self.assertTrue('source' in response, response)
|
self.assertTrue('source' in response, response)
|
||||||
|
# Make sure we can delete the inventory update.
|
||||||
|
inv_up_url = reverse('api:inventory_update_detail', args=(inventory_update.pk,))
|
||||||
|
with self.current_user(self.super_django_user):
|
||||||
|
self.get(inv_up_url, expect=200)
|
||||||
|
self.delete(inv_up_url, expect=204)
|
||||||
|
self.get(inv_up_url, expect=404)
|
||||||
|
|
||||||
def test_put_inventory_source_detail_with_regions(self):
|
def test_put_inventory_source_detail_with_regions(self):
|
||||||
creds_url = reverse('api:credential_list')
|
creds_url = reverse('api:credential_list')
|
||||||
|
|||||||
@@ -1160,6 +1160,11 @@ class ProjectUpdatesTest(BaseTransactionTest):
|
|||||||
self.check_project_update(project, should_fail=True)#should_still_fail)
|
self.check_project_update(project, should_fail=True)#should_still_fail)
|
||||||
else:
|
else:
|
||||||
self.check_project_update(project, should_fail=should_still_fail)
|
self.check_project_update(project, should_fail=should_still_fail)
|
||||||
|
# Test that we can delete project updates.
|
||||||
|
for pu in project.project_updates.filter(active=True):
|
||||||
|
pu_url = reverse('api:project_update_detail', args=(pu.pk,))
|
||||||
|
with self.current_user(self.super_django_user):
|
||||||
|
self.delete(pu_url, expect=204)
|
||||||
|
|
||||||
def test_create_project_with_scm(self):
|
def test_create_project_with_scm(self):
|
||||||
scm_url = getattr(settings, 'TEST_GIT_PUBLIC_HTTPS',
|
scm_url = getattr(settings, 'TEST_GIT_PUBLIC_HTTPS',
|
||||||
|
|||||||
Reference in New Issue
Block a user