Raise a validation error if a credential is set while the service is not

This commit is contained in:
Jeff Bradberry
2019-09-24 17:27:19 -04:00
parent efe4ea6575
commit a4873d97d8
3 changed files with 64 additions and 6 deletions

View File

@@ -2836,11 +2836,13 @@ class JobTemplateMixin(object):
'webhook_credential': _("Must be a Personal Access Token."),
})
if webhook_service and webhook_credential:
if webhook_credential.kind != '{}_token'.format(webhook_service):
raise serializers.ValidationError({
'webhook_credential': _("Must match the selected webhook service."),
})
if webhook_credential:
msg = {'webhook_credential': _("Must match the selected webhook service.")}
if webhook_service:
if webhook_credential.kind != '{}_token'.format(webhook_service):
raise serializers.ValidationError(msg)
else:
raise serializers.ValidationError(msg)
return super().validate(attrs)