fix a bug for "users should be able to change type of unused credential"

see: https://github.com/ansible/ansible-tower/issues/7516
related: https://github.com/ansible/tower/pull/441
This commit is contained in:
Ryan Petrello
2018-02-08 15:12:08 -05:00
parent 7e400413db
commit 72715df751
2 changed files with 112 additions and 0 deletions

View File

@@ -2192,6 +2192,19 @@ class CredentialSerializer(BaseSerializer):
_('You cannot change the credential type of the credential, as it may break the functionality'
' of the resources using it.'),
)
# TODO: When this code lands in awx, these relationships won't exist
# anymore, so we need to remove this code and make sure the related
# tests still pass.
for cls in (JobTemplate, Job):
for rel in ('extra_credentials__id', 'vault_credential_id'):
if cls.objects.filter(**{
rel: self.instance.pk
}).count() > 0:
raise ValidationError(
_('You cannot change the credential type of the credential, as it may break the functionality'
' of the resources using it.'),
)
return credential_type