Group serializer special v1 functionality

Returns a related `inventory_source` and related link for groups
if accessed from /api/v1/, but not for API v2.
Also inserts corresponding fields to inventory source serializer.
Keep migrated manual sources and auto-create in API v1.
This commit is contained in:
AlanCoding
2017-04-13 11:10:34 -04:00
parent 84c6d41bd4
commit 7223177684
8 changed files with 121 additions and 8 deletions

View File

@@ -1848,7 +1848,7 @@ class GroupList(ListCreateAPIView):
model = Group
serializer_class = GroupSerializer
capabilities_prefetch = ['inventory.admin', 'inventory.adhoc', 'inventory.update']
capabilities_prefetch = ['inventory.admin', 'inventory.adhoc']
class EnforceParentRelationshipMixin(object):
@@ -1992,6 +1992,11 @@ class GroupDetail(RetrieveUpdateDestroyAPIView):
obj = self.get_object()
if not request.user.can_access(self.model, 'delete', obj):
raise PermissionDenied()
if self.request.version == 'v1': # TODO: deletion of automatic inventory_source, remove in 3.3
try:
obj.deprecated_inventory_source.delete()
except Group.deprecated_inventory_source.RelatedObjectDoesNotExist:
pass
obj.delete_recursive()
return Response(status=status.HTTP_204_NO_CONTENT)
@@ -2182,7 +2187,7 @@ class InventorySourceList(ListAPIView):
new_in_14 = True
class InventorySourceDetail(RetrieveUpdateAPIView):
class InventorySourceDetail(RetrieveUpdateDestroyAPIView):
model = InventorySource
serializer_class = InventorySourceSerializer