Avoid the use of CredentialType.kind

This commit is contained in:
Jeff Bradberry 2019-09-26 15:18:38 -04:00
parent d4c8167b1b
commit fea7f914d2

View File

@ -2831,15 +2831,15 @@ class JobTemplateMixin(object):
webhook_service = attrs.get('webhook_service', getattr(self.instance, 'webhook_service', None))
webhook_credential = attrs.get('webhook_credential', getattr(self.instance, 'webhook_credential', None))
if webhook_credential and webhook_credential.credential_type.kind != 'token':
raise serializers.ValidationError({
'webhook_credential': _("Must be a Personal Access Token."),
})
if webhook_credential:
if not webhook_credential.credential_type.namespace.endswith('_token'):
raise serializers.ValidationError({
'webhook_credential': _("Must be a Personal Access Token."),
})
msg = {'webhook_credential': _("Must match the selected webhook service.")}
if webhook_service:
if webhook_credential.kind != '{}_token'.format(webhook_service):
if webhook_credential.credential_type.namespace != '{}_token'.format(webhook_service):
raise serializers.ValidationError(msg)
else:
raise serializers.ValidationError(msg)