mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 02:17:37 -02:30
fix a bug in team-based credential validation
when a credential is created with `team` in the payload, set the credential's `organization` *prior* to validation so that we don't miss organization-oriented validators (like the org + name + kind unique validation) see: #3303
This commit is contained in:
@@ -2117,6 +2117,10 @@ class CredentialSerializerCreate(CredentialSerializer):
|
|||||||
attrs.pop(field)
|
attrs.pop(field)
|
||||||
if not owner_fields:
|
if not owner_fields:
|
||||||
raise serializers.ValidationError({"detail": _("Missing 'user', 'team', or 'organization'.")})
|
raise serializers.ValidationError({"detail": _("Missing 'user', 'team', or 'organization'.")})
|
||||||
|
|
||||||
|
if attrs.get('team'):
|
||||||
|
attrs['organization'] = attrs['team'].organization
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return super(CredentialSerializerCreate, self).validate(attrs)
|
return super(CredentialSerializerCreate, self).validate(attrs)
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
@@ -2134,8 +2138,6 @@ class CredentialSerializerCreate(CredentialSerializer):
|
|||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
user = validated_data.pop('user', None)
|
user = validated_data.pop('user', None)
|
||||||
team = validated_data.pop('team', None)
|
team = validated_data.pop('team', None)
|
||||||
if team:
|
|
||||||
validated_data['organization'] = team.organization
|
|
||||||
|
|
||||||
# If our payload contains v1 credential fields, translate to the new
|
# If our payload contains v1 credential fields, translate to the new
|
||||||
# model
|
# model
|
||||||
|
|||||||
Reference in New Issue
Block a user