Various validations for const. inv. serialization

- prevent constructed inventory host,group,inventory_source creation
- disable deleting constructed inventory hosts
- remove the ability to add constructed inventory sources
- remove ability to add constructed inventories to constructed inventories
- block updates to constructed source type
- added tests for group/host/source creation
This commit is contained in:
Gabe Muniz
2023-02-09 12:56:33 -05:00
committed by Rick Elrod
parent 7a74437651
commit 7112da9cdc
4 changed files with 91 additions and 6 deletions

View File

@@ -115,6 +115,15 @@ class InventoryInputInventoriesList(SubListAttachDetachAPIView):
parent_model = Inventory
relationship = 'input_inventories'
# Specifically overriding the post method on this view to disallow constructed inventories as input inventories
def post(self, request, *args, **kwargs):
obj = Inventory.objects.get(id=request.data.get('id'))
if obj.kind == 'constructed':
return Response(
dict(error=_('You cannot add a constructed inventory to another constructed inventory.')), status=status.HTTP_405_METHOD_NOT_ALLOWED
)
return super(InventoryInputInventoriesList, self).post(request, *args, **kwargs)
class InventoryActivityStreamList(SubListAPIView):
model = ActivityStream