mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
Prevent setting SCM fields for non-SCM inventory sources
This commit is contained in:
@@ -1675,6 +1675,22 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
|||||||
raise serializers.ValidationError({"detail": _("Cannot create Inventory Source for Smart Inventory")})
|
raise serializers.ValidationError({"detail": _("Cannot create Inventory Source for Smart Inventory")})
|
||||||
return value
|
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):
|
class InventorySourceUpdateSerializer(InventorySourceSerializer):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user