1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Merge pull request #165 from jangsutsr/7352_prevent_setting_scm_fields_for_non_scm_is

Prevent setting SCM fields for non-SCM inventory sources
This commit is contained in:
Aaron Tan 2017-08-03 18:04:13 -04:00 committed by GitHub
commit 19bd051011

View File

@ -1675,6 +1675,22 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
raise serializers.ValidationError({"detail": _("Cannot create Inventory Source for Smart Inventory")})
return value
def validate(self, attrs):
def get_field_from_model_or_attrs(fd):
return attrs.get(fd, self.instance and getattr(self.instance, fd) or None)
if get_field_from_model_or_attrs('source') != 'scm':
redundant_scm_fields = filter(
lambda x: attrs.get(x, None),
['source_project', 'source_path', 'update_on_project_update']
)
if redundant_scm_fields:
raise serializers.ValidationError(
{"detail": _("Cannot set %s if not SCM type." % ' '.join(redundant_scm_fields))}
)
return super(InventorySourceSerializer, self).validate(attrs)
class InventorySourceUpdateSerializer(InventorySourceSerializer):