From 2c81a2489e79310d25f52b31d4056c3233823b5a Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Fri, 7 Jul 2017 11:28:58 -0400 Subject: [PATCH] prohibit direct creation of manual inventory sources --- awx/api/serializers.py | 6 ++++++ awx/main/tests/functional/api/test_inventory.py | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index ff3277d18b..a5dee2dc27 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1640,6 +1640,12 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt def validate_source_project(self, value): if value.scm_type == '': raise serializers.ValidationError(_("Can not use manual project for SCM-based inventory.")) + + def validate_source(self, value): + if value == '': + raise serializers.ValidationError( + {"source": "Manual inventory sources are created automatically " + "when a group is created in the v1 API."}) return value def validate(self, attrs): diff --git a/awx/main/tests/functional/api/test_inventory.py b/awx/main/tests/functional/api/test_inventory.py index c74d751ea2..8777b3b384 100644 --- a/awx/main/tests/functional/api/test_inventory.py +++ b/awx/main/tests/functional/api/test_inventory.py @@ -342,8 +342,10 @@ class TestControlledBySCM: def test_adding_inv_src_without_proj_access_prohibited(self, post, project, inventory, rando): inventory.admin_role.members.add(rando) - post(reverse('api:inventory_inventory_sources_list', kwargs={'pk': inventory.id}), - {'name': 'new inv src', 'source_project': project.pk}, rando, expect=403) + post( + reverse('api:inventory_inventory_sources_list', kwargs={'pk': inventory.id}), + {'name': 'new inv src', 'source_project': project.pk, 'source': 'scm', 'overwrite_vars': True}, + rando, expect=403) def test_no_post_in_options(self, options, scm_inventory, admin_user): r = options(reverse('api:inventory_inventory_sources_list', kwargs={'pk': scm_inventory.id}),