allow the credential type to be changed for unused credentials

see: https://github.com/ansible/ansible-tower/issues/7607
This commit is contained in:
Ryan Petrello
2017-09-20 14:27:14 -04:00
committed by Matthew Jones
parent 91ec0a4482
commit c8f4320b58
2 changed files with 54 additions and 18 deletions
+16 -4
View File
@@ -2162,10 +2162,22 @@ class CredentialSerializer(BaseSerializer):
def validate_credential_type(self, credential_type):
if self.instance and credential_type.pk != self.instance.credential_type.pk:
raise ValidationError(
_('You cannot change the credential type of the credential, as it may break the functionality'
' of the resources using it.'),
)
for rel in (
'ad_hoc_commands',
'insights_inventories',
'inventorysources',
'inventoryupdates',
'jobs',
'jobtemplates',
'projects',
'projectupdates',
'workflowjobnodes'
):
if getattr(self.instance, rel).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