##// 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 68 """POST ldap create and store ldap settings"""
69 69
70 70 settings_model = SettingsModel()
71 _form = LdapSettingsForm()()
71 post_data = dict(request.POST)
72 _form = LdapSettingsForm(post_data.get('ldap_active'))()
72 73
73 74 try:
74 form_result = _form.to_python(dict(request.POST))
75 form_result = _form.to_python(post_data)
75 76 try:
76 77
77 78 for k, v in form_result.items():
@@ -300,26 +300,29 b' class LdapLibValidator(formencode.valida'
300 300 raise LdapImportError
301 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):
306
307 try:
308 value % {'user':'valid'}
308 if not ldap_enable:
309 return ''
310 try:
311 value % {'user':'valid'}
309 312
310 if value.find('%(user)s') == -1:
311 raise formencode.Invalid(_("You need to specify %(user)s in "
312 "template for example uid=%(user)s "
313 ",dc=company...") ,
314 value, state)
313 if value.find('%(user)s') == -1:
314 raise formencode.Invalid(_("You need to specify %(user)s in "
315 "template for example uid=%(user)s "
316 ",dc=company...") ,
317 value, state)
315 318
316 except KeyError:
317 raise formencode.Invalid(_("Wrong template used, only %(user)s "
318 "is an valid entry") ,
319 value, state)
319 except KeyError:
320 raise formencode.Invalid(_("Wrong template used, only %(user)s "
321 "is an valid entry") ,
322 value, state)
320 323
321 return value
322
324 return value
325 return _BaseDnValidator
323 326 #===============================================================================
324 327 # FORMS
325 328 #===============================================================================
@@ -467,7 +470,7 b' def DefaultPermissionsForm(perms_choices'
467 470 return _DefaultPermissionsForm
468 471
469 472
470 def LdapSettingsForm():
473 def LdapSettingsForm(ldap_enable):
471 474 class _LdapSettingsForm(formencode.Schema):
472 475 allow_extra_fields = True
473 476 filter_extra_fields = True
@@ -478,6 +481,6 b' def LdapSettingsForm():'
478 481 ldap_ldaps = StringBoolean(if_missing=False)
479 482 ldap_dn_user = UnicodeString(strip=True,)
480 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 486 return _LdapSettingsForm
General Comments 0
You need to be logged in to leave comments. Login now