changeset 3632:1ec67ddcaffe beta

ldap: handle more elegantly that python-ldap isn't installed when trying to use ldap Don't fail with AttributeError: 'NoneType' object has no attribute 'SCOPE_SUBTREE' in the log.
author Mads Kiilerich <madski@unity3d.com>
date Thu, 28 Mar 2013 01:15:56 +0100
parents 10b4e34841a4
children 5917256510d7
files rhodecode/lib/auth.py rhodecode/lib/auth_ldap.py
diffstat 2 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/auth.py	Thu Mar 28 03:34:36 2013 +0100
+++ b/rhodecode/lib/auth.py	Thu Mar 28 01:15:56 2013 +0100
@@ -40,7 +40,8 @@
 from rhodecode.model.meta import Session
 
 from rhodecode.lib.utils2 import str2bool, safe_unicode
-from rhodecode.lib.exceptions import LdapPasswordError, LdapUsernameError
+from rhodecode.lib.exceptions import LdapPasswordError, LdapUsernameError,\
+    LdapImportError
 from rhodecode.lib.utils import get_repo_slug, get_repos_group_slug
 from rhodecode.lib.auth_ldap import AuthLdap
 
@@ -241,7 +242,7 @@
 
                 Session().commit()
                 return True
-            except (LdapUsernameError, LdapPasswordError,):
+            except (LdapUsernameError, LdapPasswordError, LdapImportError):
                 pass
             except (Exception,):
                 log.error(traceback.format_exc())
--- a/rhodecode/lib/auth_ldap.py	Thu Mar 28 03:34:36 2013 +0100
+++ b/rhodecode/lib/auth_ldap.py	Thu Mar 28 01:15:56 2013 +0100
@@ -26,7 +26,7 @@
 import logging
 
 from rhodecode.lib.exceptions import LdapConnectionError, LdapUsernameError, \
-    LdapPasswordError
+    LdapPasswordError, LdapImportError
 from rhodecode.lib.utils2 import safe_str
 
 log = logging.getLogger(__name__)
@@ -36,7 +36,7 @@
     import ldap
 except ImportError:
     # means that python-ldap is not installed
-    pass
+    ldap = None
 
 
 class AuthLdap(object):
@@ -45,6 +45,9 @@
                  tls_kind='PLAIN', tls_reqcert='DEMAND', ldap_version=3,
                  ldap_filter='(&(objectClass=user)(!(objectClass=computer)))',
                  search_scope='SUBTREE', attr_login='uid'):
+        if ldap is None:
+            raise LdapImportError
+
         self.ldap_version = ldap_version
         ldap_server_type = 'ldap'