mirror of
https://github.com/ansible/awx.git
synced 2026-05-10 02:47:36 -02:30
remove ability to add constructed inventories to constructed inventories
This commit is contained in:
@@ -115,6 +115,15 @@ class InventoryInputInventoriesList(SubListAttachDetachAPIView):
|
|||||||
parent_model = Inventory
|
parent_model = Inventory
|
||||||
relationship = 'input_inventories'
|
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):
|
class InventoryActivityStreamList(SubListAPIView):
|
||||||
model = ActivityStream
|
model = ActivityStream
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import pytest
|
||||||
|
from awx.main.models import Inventory
|
||||||
|
from awx.api.versioning import reverse
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_constructed_inventory_post(post, organization, admin_user):
|
||||||
|
inventory1 = Inventory.objects.create(name='dummy1', kind='constructed', organization=organization)
|
||||||
|
inventory2 = Inventory.objects.create(name='dummy2', kind='constructed', organization=organization)
|
||||||
|
resp = post(
|
||||||
|
url=reverse('api:inventory_input_inventories', kwargs={'pk': inventory1.id}),
|
||||||
|
data={'id': inventory2.id},
|
||||||
|
user=admin_user,
|
||||||
|
expect=405,
|
||||||
|
)
|
||||||
|
print(resp)
|
||||||
|
assert resp.status_code == 405
|
||||||
Reference in New Issue
Block a user