mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
enforce Organization ownership of Galaxy credentials
This commit is contained in:
parent
25a9a9c3ba
commit
1b4dd7c783
@ -2611,6 +2611,17 @@ class CredentialSerializer(BaseSerializer):
|
||||
ret.remove(field)
|
||||
return ret
|
||||
|
||||
def validate_organization(self, org):
|
||||
if (
|
||||
self.instance and
|
||||
self.instance.credential_type.kind == 'galaxy' and
|
||||
org is None
|
||||
):
|
||||
raise serializers.ValidationError(_(
|
||||
"Galaxy credentials must be owned by an Organization."
|
||||
))
|
||||
return org
|
||||
|
||||
def validate_credential_type(self, credential_type):
|
||||
if self.instance and credential_type.pk != self.instance.credential_type.pk:
|
||||
for related_objects in (
|
||||
@ -2675,6 +2686,14 @@ class CredentialSerializerCreate(CredentialSerializer):
|
||||
if attrs.get('team'):
|
||||
attrs['organization'] = attrs['team'].organization
|
||||
|
||||
if (
|
||||
attrs['credential_type'].kind == 'galaxy' and
|
||||
list(owner_fields) != ['organization']
|
||||
):
|
||||
raise serializers.ValidationError({"organization": _(
|
||||
"Galaxy credentials must be owned by an Organization."
|
||||
)})
|
||||
|
||||
return super(CredentialSerializerCreate, self).validate(attrs)
|
||||
|
||||
def create(self, validated_data):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user