mirror of
https://github.com/ansible/awx.git
synced 2026-04-13 22:19:27 -02:30
Enforce single owner field when serializing creds
The CredentialSerializerCreate expect a single owner field according to its help text but was not validating that. This makes it validate for a single owner field when creating a Credential.
This commit is contained in:
@@ -2644,9 +2644,17 @@ class CredentialSerializerCreate(CredentialSerializer):
|
||||
owner_fields.add(field)
|
||||
else:
|
||||
attrs.pop(field)
|
||||
|
||||
if not owner_fields:
|
||||
raise serializers.ValidationError({"detail": _("Missing 'user', 'team', or 'organization'.")})
|
||||
|
||||
if len(owner_fields) > 1:
|
||||
received = ", ".join(sorted(owner_fields))
|
||||
raise serializers.ValidationError({"detail": _(
|
||||
"Only one of 'user', 'team', or 'organization' should be provided, "
|
||||
"received {} fields.".format(received)
|
||||
)})
|
||||
|
||||
if attrs.get('team'):
|
||||
attrs['organization'] = attrs['team'].organization
|
||||
|
||||
|
||||
Reference in New Issue
Block a user