From deb8eaa982f8c71615e9ba70275b4f157b20d7d9 Mon Sep 17 00:00:00 2001 From: Jim Ladd Date: Mon, 24 Jul 2017 14:32:13 -0400 Subject: [PATCH] Disable POST to v1 inventory_sources --- awx/api/views.py | 7 +++++++ awx/main/tests/unit/test_views.py | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/awx/api/views.py b/awx/api/views.py index 0297c649d2..e783b94d0b 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -2532,6 +2532,13 @@ class InventorySourceList(ListCreateAPIView): always_allow_superuser = False new_in_320 = True + @property + def allowed_methods(self): + methods = super(InventorySourceList, self).allowed_methods + if get_request_version(self.request) == 1: + methods.remove('POST') + return methods + class InventorySourceDetail(RetrieveUpdateDestroyAPIView): diff --git a/awx/main/tests/unit/test_views.py b/awx/main/tests/unit/test_views.py index dd7f63bb3a..8252581a12 100644 --- a/awx/main/tests/unit/test_views.py +++ b/awx/main/tests/unit/test_views.py @@ -6,7 +6,7 @@ from rest_framework import exceptions # AWX from awx.main.views import ApiErrorView -from awx.api.views import JobList +from awx.api.views import JobList, InventorySourceList HTTP_METHOD_NAMES = [ @@ -44,3 +44,10 @@ def test_disable_post_on_v2_jobs_list(version, supports_post): job_list.request = mock.MagicMock() with mock.patch('awx.api.views.get_request_version', return_value=version): assert ('POST' in job_list.allowed_methods) == supports_post + +@pytest.mark.parametrize('version, supports_post', [(1, False), (2, True)]) +def test_disable_post_on_v1_inventory_source_list(version, supports_post): + inv_source_list = InventorySourceList() + inv_source_list.request = mock.MagicMock() + with mock.patch('awx.api.views.get_request_version', return_value=version): + assert ('POST' in inv_source_list.allowed_methods) == supports_post