Changeset - 9a9946320435
[Not reviewed]
default
0 2 0
Marcin Kuzminski - 15 years ago 2011-03-17 21:05:14
marcin@python-works.com
fixed ldap form, it doesn't validate the baseDN until enable checkbox is set
2 files changed with 24 insertions and 20 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/ldap_settings.py
Show inline comments
 
@@ -68,10 +68,11 @@ class LdapSettingsController(BaseControl
 
        """POST ldap create and store ldap settings"""
 

	
 
        settings_model = SettingsModel()
 
        _form = LdapSettingsForm()()
 
        post_data = dict(request.POST)
 
        _form = LdapSettingsForm(post_data.get('ldap_active'))()
 

	
 
        try:
 
            form_result = _form.to_python(dict(request.POST))
 
            form_result = _form.to_python(post_data)
 
            try:
 

	
 
                for k, v in form_result.items():
rhodecode/model/forms.py
Show inline comments
 
@@ -300,26 +300,29 @@ class LdapLibValidator(formencode.valida
 
            raise LdapImportError
 
        return value
 

	
 
class BaseDnValidator(formencode.validators.FancyValidator):
 
def BaseDnValidator(ldap_enable):
 
    class _BaseDnValidator(formencode.validators.FancyValidator):
 

	
 
        def to_python(self, value, state):
 

	
 
    def to_python(self, value, state):
 

	
 
        try:
 
            value % {'user':'valid'}
 
            if not ldap_enable:
 
                return ''
 
            try:
 
                value % {'user':'valid'}
 

	
 
            if value.find('%(user)s') == -1:
 
                raise formencode.Invalid(_("You need to specify %(user)s in "
 
                                           "template for example uid=%(user)s "
 
                                           ",dc=company...") ,
 
                                         value, state)
 
                if value.find('%(user)s') == -1:
 
                    raise formencode.Invalid(_("You need to specify %(user)s in "
 
                                               "template for example uid=%(user)s "
 
                                               ",dc=company...") ,
 
                                             value, state)
 

	
 
        except KeyError:
 
            raise formencode.Invalid(_("Wrong template used, only %(user)s "
 
                                       "is an valid entry") ,
 
                                         value, state)
 
            except KeyError:
 
                raise formencode.Invalid(_("Wrong template used, only %(user)s "
 
                                           "is an valid entry") ,
 
                                             value, state)
 

	
 
        return value
 

	
 
            return value
 
    return _BaseDnValidator
 
#===============================================================================
 
# FORMS        
 
#===============================================================================
 
@@ -467,7 +470,7 @@ def DefaultPermissionsForm(perms_choices
 
    return _DefaultPermissionsForm
 

	
 

	
 
def LdapSettingsForm():
 
def LdapSettingsForm(ldap_enable):
 
    class _LdapSettingsForm(formencode.Schema):
 
        allow_extra_fields = True
 
        filter_extra_fields = True
 
@@ -478,6 +481,6 @@ def LdapSettingsForm():
 
        ldap_ldaps = StringBoolean(if_missing=False)
 
        ldap_dn_user = UnicodeString(strip=True,)
 
        ldap_dn_pass = UnicodeString(strip=True,)
 
        ldap_base_dn = All(BaseDnValidator, UnicodeString(strip=True,))
 
        ldap_base_dn = All(BaseDnValidator(ldap_enable), UnicodeString(strip=True,))
 

	
 
    return _LdapSettingsForm
0 comments (0 inline, 0 general)