Merge pull request #3606 from cchurch/fix-ldap-saml-defaults

Fix default value validation for LDAP/SAML settings to prevent warnings.
This commit is contained in:
Chris Church 2016-09-28 11:11:46 -04:00 committed by GitHub
commit 17f70fbc21
3 changed files with 13 additions and 1 deletions

View File

@ -34,6 +34,11 @@ class URLField(CharField):
validator_kwargs['schemes'] = schemes
self.validators.append(URLValidator(**validator_kwargs))
def to_representation(self, value):
if value is None:
return ''
return super(URLField, self).to_representation(value)
def run_validators(self, value):
if self.allow_plain_hostname:
try:

View File

@ -169,6 +169,7 @@ register(
field_class=fields.URLField,
schemes=('ldap', 'ldaps'),
allow_blank=True,
default='',
label=_('LDAP Server URI'),
help_text=_('URI to connect to LDAP server, such as "ldap://ldap.example.com:389" '
'(non-SSL) or "ldaps://ldap.example.com:636" (SSL). LDAP authentication '
@ -880,6 +881,7 @@ register(
register(
'SOCIAL_AUTH_SAML_TECHNICAL_CONTACT',
field_class=fields.SAMLContactField,
allow_blank=True,
default={},
label=_('SAML Service Provider Technical Contact'),
help_text=_('Configure this setting with your contact information.'),
@ -894,6 +896,7 @@ register(
register(
'SOCIAL_AUTH_SAML_SUPPORT_CONTACT',
field_class=fields.SAMLContactField,
allow_blank=True,
default={},
label=_('SAML Service Provider Support Contact'),
help_text=_('Configure this setting with your contact information.'),

View File

@ -349,6 +349,10 @@ class BaseDictWithChildField(fields.DictField):
}
allow_unknown_keys = False
def __init__(self, *args, **kwargs):
self.allow_blank = kwargs.pop('allow_blank', False)
super(BaseDictWithChildField, self).__init__(*args, **kwargs)
def to_representation(self, value):
value = super(BaseDictWithChildField, self).to_representation(value)
for k, v in value.items():
@ -367,7 +371,7 @@ class BaseDictWithChildField(fields.DictField):
continue
elif key not in data:
missing_keys.add(key)
if missing_keys:
if missing_keys and (data or not self.allow_blank):
keys_display = json.dumps(list(missing_keys)).lstrip('[').rstrip(']')
self.fail('missing_keys', missing_keys=keys_display)
if not self.allow_unknown_keys: