changeset 2193:3ea397063fc7 beta

fixed #374 LDAP config is now saved but deactivated if python-ldap lib is missing
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 15 Apr 2012 20:30:17 +0200
parents a801c4542f48
children ec6691dd9e94
files docs/changelog.rst rhodecode/controllers/admin/ldap_settings.py rhodecode/model/forms.py
diffstat 3 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/docs/changelog.rst	Sun Apr 15 03:21:04 2012 +0200
+++ b/docs/changelog.rst	Sun Apr 15 20:30:17 2012 +0200
@@ -22,6 +22,7 @@
   IP for pull/push logs. - moved all to base controller  
 - #415: Adding comment to changeset causes reload. 
   Comments are now added via ajax and doesn't reload the page
+- #374 LDAP config is discarded when LDAP can't be activated
 
 fixes
 +++++
--- a/rhodecode/controllers/admin/ldap_settings.py	Sun Apr 15 03:21:04 2012 +0200
+++ b/rhodecode/controllers/admin/ldap_settings.py	Sun Apr 15 20:30:17 2012 +0200
@@ -100,25 +100,37 @@
         _form = LdapSettingsForm([x[0] for x in self.tls_reqcert_choices],
                                  [x[0] for x in self.search_scope_choices],
                                  [x[0] for x in self.tls_kind_choices])()
+        # check the ldap lib
+        ldap_active = False
+        try:
+            import ldap
+            ldap_active = True
+        except ImportError:
+            pass
 
         try:
             form_result = _form.to_python(dict(request.POST))
+
             try:
 
                 for k, v in form_result.items():
                     if k.startswith('ldap_'):
+                        if k == 'ldap_active':
+                            v = ldap_active
                         setting = RhodeCodeSetting.get_by_name(k)
                         setting.app_settings_value = v
                         self.sa.add(setting)
 
                 self.sa.commit()
                 h.flash(_('Ldap settings updated successfully'),
-                    category='success')
+                        category='success')
+                if not ldap_active:
+                    #if ldap is missing send an info to user
+                    h.flash(_('Unable to activate ldap. The "python-ldap" library '
+                              'is missing.'), category='warning')
+
             except (DatabaseError,):
                 raise
-        except LdapImportError:
-            h.flash(_('Unable to activate ldap. The "python-ldap" library '
-                      'is missing.'), category='warning')
 
         except formencode.Invalid, errors:
             e = errors.error_dict or {}
--- a/rhodecode/model/forms.py	Sun Apr 15 03:21:04 2012 +0200
+++ b/rhodecode/model/forms.py	Sun Apr 15 20:30:17 2012 +0200
@@ -754,7 +754,7 @@
     class _LdapSettingsForm(formencode.Schema):
         allow_extra_fields = True
         filter_extra_fields = True
-        pre_validators = [LdapLibValidator]
+        #pre_validators = [LdapLibValidator]
         ldap_active = StringBoolean(if_missing=False)
         ldap_host = UnicodeString(strip=True,)
         ldap_port = Number(strip=True,)