Mercurial > kallithea
comparison rhodecode/model/forms.py @ 1145:9a9946320435
fixed ldap form, it doesn't validate the baseDN until enable checkbox is set
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 17 Mar 2011 21:05:14 +0100 |
parents | af6ca51fb80f |
children | bf263968da47 |
comparison
equal
deleted
inserted
replaced
1144:cf5761b37af9 | 1145:9a9946320435 |
---|---|
298 import ldap | 298 import ldap |
299 except ImportError: | 299 except ImportError: |
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 | 304 class _BaseDnValidator(formencode.validators.FancyValidator): |
305 def to_python(self, value, state): | 305 |
306 | 306 def to_python(self, value, state): |
307 try: | 307 |
308 value % {'user':'valid'} | 308 if not ldap_enable: |
309 | 309 return '' |
310 if value.find('%(user)s') == -1: | 310 try: |
311 raise formencode.Invalid(_("You need to specify %(user)s in " | 311 value % {'user':'valid'} |
312 "template for example uid=%(user)s " | 312 |
313 ",dc=company...") , | 313 if value.find('%(user)s') == -1: |
314 value, state) | 314 raise formencode.Invalid(_("You need to specify %(user)s in " |
315 | 315 "template for example uid=%(user)s " |
316 except KeyError: | 316 ",dc=company...") , |
317 raise formencode.Invalid(_("Wrong template used, only %(user)s " | 317 value, state) |
318 "is an valid entry") , | 318 |
319 value, state) | 319 except KeyError: |
320 | 320 raise formencode.Invalid(_("Wrong template used, only %(user)s " |
321 return value | 321 "is an valid entry") , |
322 | 322 value, state) |
323 | |
324 return value | |
325 return _BaseDnValidator | |
323 #=============================================================================== | 326 #=============================================================================== |
324 # FORMS | 327 # FORMS |
325 #=============================================================================== | 328 #=============================================================================== |
326 class LoginForm(formencode.Schema): | 329 class LoginForm(formencode.Schema): |
327 allow_extra_fields = True | 330 allow_extra_fields = True |
465 default_create = OneOf(create_choices) | 468 default_create = OneOf(create_choices) |
466 | 469 |
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 |
474 pre_validators = [LdapLibValidator] | 477 pre_validators = [LdapLibValidator] |
475 ldap_active = StringBoolean(if_missing=False) | 478 ldap_active = StringBoolean(if_missing=False) |
476 ldap_host = UnicodeString(strip=True,) | 479 ldap_host = UnicodeString(strip=True,) |
477 ldap_port = Number(strip=True,) | 480 ldap_port = Number(strip=True,) |
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 |