From f28ad90bf31699e0a38c7771aa17f97799642f95 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Thu, 15 Apr 2021 15:28:26 -0400 Subject: [PATCH] Remove source_script field from serializers Remove some other uses of source_script --- awx/api/serializers.py | 30 ------------------- awx/main/access.py | 4 +-- .../tests/functional/test_rbac_workflow.py | 2 +- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 266cb01191..5b50bc999c 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -167,7 +167,6 @@ SUMMARIZABLE_FK_FIELDS = { 'current_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'), 'current_job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'), 'inventory_source': ('id', 'name', 'source', 'last_updated', 'status'), - 'source_script': DEFAULT_SUMMARY_FIELDS, 'role': ('id', 'role_field'), 'notification_template': DEFAULT_SUMMARY_FIELDS, 'instance_group': ('id', 'name', 'controller_id', 'is_container_group'), @@ -1991,7 +1990,6 @@ class InventorySourceOptionsSerializer(BaseSerializer): '*', 'source', 'source_path', - 'source_script', 'source_vars', 'credential', 'enabled_var', @@ -2018,34 +2016,6 @@ class InventorySourceOptionsSerializer(BaseSerializer): raise serializers.ValidationError(_("`{}` is a prohibited environment variable".format(env_k))) return ret - def validate(self, attrs): - # TODO: Validate source - errors = {} - - source = attrs.get('source', self.instance and self.instance.source or '') - source_script = attrs.get('source_script', self.instance and self.instance.source_script or '') - if source == 'custom': - if source_script is None or source_script == '': - errors['source_script'] = _("If 'source' is 'custom', 'source_script' must be provided.") - else: - try: - if not self.instance: - dest_inventory = attrs.get('inventory', None) - if not dest_inventory: - errors['inventory'] = _("Must provide an inventory.") - else: - dest_inventory = self.instance.inventory - if dest_inventory and source_script.organization != dest_inventory.organization: - errors['source_script'] = _("The 'source_script' does not belong to the same organization as the inventory.") - except Exception: - errors['source_script'] = _("'source_script' doesn't exist.") - logger.exception('Problem processing source_script validation.') - - if errors: - raise serializers.ValidationError(errors) - - return super(InventorySourceOptionsSerializer, self).validate(attrs) - # TODO: remove when old 'credential' fields are removed def get_summary_fields(self, obj): summary_fields = super(InventorySourceOptionsSerializer, self).get_summary_fields(obj) diff --git a/awx/main/access.py b/awx/main/access.py index f8a5bb0cba..0647b598d2 100644 --- a/awx/main/access.py +++ b/awx/main/access.py @@ -1030,7 +1030,7 @@ class InventorySourceAccess(NotificationAttachMixin, BaseAccess): model = InventorySource select_related = ('created_by', 'modified_by', 'inventory') - prefetch_related = ('credentials__credential_type', 'last_job', 'source_script', 'source_project') + prefetch_related = ('credentials__credential_type', 'last_job', 'source_project') def filtered_queryset(self): return self.model.objects.filter(inventory__in=Inventory.accessible_pk_qs(self.user, 'read_role')) @@ -1092,7 +1092,7 @@ class InventoryUpdateAccess(BaseAccess): 'modified_by', 'inventory_source', ) - prefetch_related = ('unified_job_template', 'instance_group', 'credentials__credential_type', 'inventory', 'source_script') + prefetch_related = ('unified_job_template', 'instance_group', 'credentials__credential_type', 'inventory') def filtered_queryset(self): return self.model.objects.filter(inventory_source__inventory__in=Inventory.accessible_pk_qs(self.user, 'read_role')) diff --git a/awx/main/tests/functional/test_rbac_workflow.py b/awx/main/tests/functional/test_rbac_workflow.py index 0195b1adf3..d48eb3f80b 100644 --- a/awx/main/tests/functional/test_rbac_workflow.py +++ b/awx/main/tests/functional/test_rbac_workflow.py @@ -198,7 +198,7 @@ class TestWFJTCopyAccess: def test_workflow_copy_no_start(self, wfjt, inventory, admin_user): # Test that un-startable resource doesn't block copy - inv_src = InventorySource.objects.create(inventory=inventory, source='custom', source_script=None) + inv_src = InventorySource.objects.create(inventory=inventory, source='file') assert not inv_src.can_update wfjt.workflow_job_template_nodes.create(unified_job_template=inv_src) access = WorkflowJobTemplateAccess(admin_user, save_messages=True)