1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

AC-1116 Support for deleting project/inventory updates.

This commit is contained in:
Chris Church 2014-04-01 17:15:37 -04:00
parent 4069a33ab0
commit 658581cce0
8 changed files with 47 additions and 10 deletions

View File

@ -26,11 +26,10 @@ from rest_framework import views
from awx.main.models 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', 'RetrieveAPIView',
'RetrieveUpdateAPIView', 'RetrieveUpdateDestroyAPIView']
__all__ = ['APIView', 'GenericAPIView', 'ListAPIView', 'SimpleListAPIView',
'ListCreateAPIView', 'SubListAPIView', 'SubListCreateAPIView',
'RetrieveAPIView', 'RetrieveUpdateAPIView',
'RetrieveDestroyAPIView', 'RetrieveUpdateDestroyAPIView']
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 '''
pass
class RetrieveUpdateDestroyAPIView(RetrieveUpdateAPIView, generics.RetrieveUpdateDestroyAPIView):
class RetrieveDestroyAPIView(RetrieveAPIView, generics.RetrieveDestroyAPIView):
def destroy(self, request, *args, **kwargs):
# somewhat lame that delete has to call it's own permissions check
@ -450,3 +449,6 @@ class RetrieveUpdateDestroyAPIView(RetrieveUpdateAPIView, generics.RetrieveUpdat
else:
raise NotImplementedError('destroy() not implemented yet for %s' % obj)
return Response(status=status.HTTP_204_NO_CONTENT)
class RetrieveUpdateDestroyAPIView(RetrieveUpdateAPIView, RetrieveDestroyAPIView):
pass

View 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" %}

View File

@ -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 }}:

View File

@ -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 }}:

View File

@ -500,7 +500,7 @@ class ProjectUpdateView(GenericAPIView):
else:
return self.http_method_not_allowed(request, *args, **kwargs)
class ProjectUpdateDetail(RetrieveAPIView):
class ProjectUpdateDetail(RetrieveDestroyAPIView):
model = ProjectUpdate
serializer_class = ProjectUpdateSerializer
@ -1064,7 +1064,7 @@ class InventorySourceUpdateView(GenericAPIView):
else:
return self.http_method_not_allowed(request, *args, **kwargs)
class InventoryUpdateDetail(RetrieveAPIView):
class InventoryUpdateDetail(RetrieveDestroyAPIView):
model = InventoryUpdate
serializer_class = InventoryUpdateSerializer

View File

@ -482,6 +482,7 @@ class InventoryUpdateAccess(BaseAccess):
'''
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 delete when I can change/delete the inventory source.
'''
model = InventoryUpdate
@ -673,6 +674,7 @@ class ProjectUpdateAccess(BaseAccess):
'''
I can see project updates when I can see the project.
I can change when I can change the project.
I can delete when I can change/delete the project.
'''
model = ProjectUpdate

View File

@ -1094,6 +1094,12 @@ class InventoryUpdatesTest(BaseTransactionTest):
})
response = self.put(inv_src_url2, data, expect=400)
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):
creds_url = reverse('api:credential_list')

View File

@ -1160,6 +1160,11 @@ class ProjectUpdatesTest(BaseTransactionTest):
self.check_project_update(project, should_fail=True)#should_still_fail)
else:
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):
scm_url = getattr(settings, 'TEST_GIT_PUBLIC_HTTPS',