mirror of
https://github.com/ansible/awx.git
synced 2026-01-18 05:01:19 -03:30
remove ability to add constructed inventories to constructed inventories
This commit is contained in:
parent
c98f86a355
commit
2d9f2d36a1
@ -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
|
||||
|
||||
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user