mirror of
https://github.com/ansible/awx.git
synced 2026-05-23 16:47:45 -02:30
Remove source_script field from serializers
Remove some other uses of source_script
This commit is contained in:
@@ -167,7 +167,6 @@ SUMMARIZABLE_FK_FIELDS = {
|
|||||||
'current_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
'current_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
||||||
'current_job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
'current_job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
||||||
'inventory_source': ('id', 'name', 'source', 'last_updated', 'status'),
|
'inventory_source': ('id', 'name', 'source', 'last_updated', 'status'),
|
||||||
'source_script': DEFAULT_SUMMARY_FIELDS,
|
|
||||||
'role': ('id', 'role_field'),
|
'role': ('id', 'role_field'),
|
||||||
'notification_template': DEFAULT_SUMMARY_FIELDS,
|
'notification_template': DEFAULT_SUMMARY_FIELDS,
|
||||||
'instance_group': ('id', 'name', 'controller_id', 'is_container_group'),
|
'instance_group': ('id', 'name', 'controller_id', 'is_container_group'),
|
||||||
@@ -1991,7 +1990,6 @@ class InventorySourceOptionsSerializer(BaseSerializer):
|
|||||||
'*',
|
'*',
|
||||||
'source',
|
'source',
|
||||||
'source_path',
|
'source_path',
|
||||||
'source_script',
|
|
||||||
'source_vars',
|
'source_vars',
|
||||||
'credential',
|
'credential',
|
||||||
'enabled_var',
|
'enabled_var',
|
||||||
@@ -2018,34 +2016,6 @@ class InventorySourceOptionsSerializer(BaseSerializer):
|
|||||||
raise serializers.ValidationError(_("`{}` is a prohibited environment variable".format(env_k)))
|
raise serializers.ValidationError(_("`{}` is a prohibited environment variable".format(env_k)))
|
||||||
return ret
|
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
|
# TODO: remove when old 'credential' fields are removed
|
||||||
def get_summary_fields(self, obj):
|
def get_summary_fields(self, obj):
|
||||||
summary_fields = super(InventorySourceOptionsSerializer, self).get_summary_fields(obj)
|
summary_fields = super(InventorySourceOptionsSerializer, self).get_summary_fields(obj)
|
||||||
|
|||||||
@@ -1030,7 +1030,7 @@ class InventorySourceAccess(NotificationAttachMixin, BaseAccess):
|
|||||||
|
|
||||||
model = InventorySource
|
model = InventorySource
|
||||||
select_related = ('created_by', 'modified_by', 'inventory')
|
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):
|
def filtered_queryset(self):
|
||||||
return self.model.objects.filter(inventory__in=Inventory.accessible_pk_qs(self.user, 'read_role'))
|
return self.model.objects.filter(inventory__in=Inventory.accessible_pk_qs(self.user, 'read_role'))
|
||||||
@@ -1092,7 +1092,7 @@ class InventoryUpdateAccess(BaseAccess):
|
|||||||
'modified_by',
|
'modified_by',
|
||||||
'inventory_source',
|
'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):
|
def filtered_queryset(self):
|
||||||
return self.model.objects.filter(inventory_source__inventory__in=Inventory.accessible_pk_qs(self.user, 'read_role'))
|
return self.model.objects.filter(inventory_source__inventory__in=Inventory.accessible_pk_qs(self.user, 'read_role'))
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ class TestWFJTCopyAccess:
|
|||||||
|
|
||||||
def test_workflow_copy_no_start(self, wfjt, inventory, admin_user):
|
def test_workflow_copy_no_start(self, wfjt, inventory, admin_user):
|
||||||
# Test that un-startable resource doesn't block copy
|
# 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
|
assert not inv_src.can_update
|
||||||
wfjt.workflow_job_template_nodes.create(unified_job_template=inv_src)
|
wfjt.workflow_job_template_nodes.create(unified_job_template=inv_src)
|
||||||
access = WorkflowJobTemplateAccess(admin_user, save_messages=True)
|
access = WorkflowJobTemplateAccess(admin_user, save_messages=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user