##// END OF EJS Templates
fixed ldap form, it doesn't validate the baseDN until enable checkbox is set
marcink -
r1145:9a994632 default
parent child Browse files
Show More
@@ -68,10 +68,11 b' class LdapSettingsController(BaseControl'
68 """POST ldap create and store ldap settings"""
68 """POST ldap create and store ldap settings"""
69
69
70 settings_model = SettingsModel()
70 settings_model = SettingsModel()
71 _form = LdapSettingsForm()()
71 post_data = dict(request.POST)
72 _form = LdapSettingsForm(post_data.get('ldap_active'))()
72
73
73 try:
74 try:
74 form_result = _form.to_python(dict(request.POST))
75 form_result = _form.to_python(post_data)
75 try:
76 try:
76
77
77 for k, v in form_result.items():
78 for k, v in form_result.items():
@@ -300,26 +300,29 b' class LdapLibValidator(formencode.valida'
300 raise LdapImportError
300 raise LdapImportError
301 return value
301 return value
302
302
303 class BaseDnValidator(formencode.validators.FancyValidator):
303 def BaseDnValidator(ldap_enable):
304 class _BaseDnValidator(formencode.validators.FancyValidator):
305
306 def to_python(self, value, state):
304
307
305 def to_python(self, value, state):
308 if not ldap_enable:
306
309 return ''
307 try:
310 try:
308 value % {'user':'valid'}
311 value % {'user':'valid'}
309
312
310 if value.find('%(user)s') == -1:
313 if value.find('%(user)s') == -1:
311 raise formencode.Invalid(_("You need to specify %(user)s in "
314 raise formencode.Invalid(_("You need to specify %(user)s in "
312 "template for example uid=%(user)s "
315 "template for example uid=%(user)s "
313 ",dc=company...") ,
316 ",dc=company...") ,
314 value, state)
317 value, state)
315
318
316 except KeyError:
319 except KeyError:
317 raise formencode.Invalid(_("Wrong template used, only %(user)s "
320 raise formencode.Invalid(_("Wrong template used, only %(user)s "
318 "is an valid entry") ,
321 "is an valid entry") ,
319 value, state)
322 value, state)
320
323
321 return value
324 return value
322
325 return _BaseDnValidator
323 #===============================================================================
326 #===============================================================================
324 # FORMS
327 # FORMS
325 #===============================================================================
328 #===============================================================================
@@ -467,7 +470,7 b' def DefaultPermissionsForm(perms_choices'
467 return _DefaultPermissionsForm
470 return _DefaultPermissionsForm
468
471
469
472
470 def LdapSettingsForm():
473 def LdapSettingsForm(ldap_enable):
471 class _LdapSettingsForm(formencode.Schema):
474 class _LdapSettingsForm(formencode.Schema):
472 allow_extra_fields = True
475 allow_extra_fields = True
473 filter_extra_fields = True
476 filter_extra_fields = True
@@ -478,6 +481,6 b' def LdapSettingsForm():'
478 ldap_ldaps = StringBoolean(if_missing=False)
481 ldap_ldaps = StringBoolean(if_missing=False)
479 ldap_dn_user = UnicodeString(strip=True,)
482 ldap_dn_user = UnicodeString(strip=True,)
480 ldap_dn_pass = UnicodeString(strip=True,)
483 ldap_dn_pass = UnicodeString(strip=True,)
481 ldap_base_dn = All(BaseDnValidator, UnicodeString(strip=True,))
484 ldap_base_dn = All(BaseDnValidator(ldap_enable), UnicodeString(strip=True,))
482
485
483 return _LdapSettingsForm
486 return _LdapSettingsForm
General Comments 0
You need to be logged in to leave comments. Login now