浏览代码

[useradmin] Add non-existing LDAP user fails

See http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject.result.
Result data should be empty if no users are returned.
abec 13 年之前
父节点
当前提交
c87bb68db6
共有 2 个文件被更改,包括 2 次插入2 次删除
  1. 1 1
      apps/useradmin/src/useradmin/ldap_access.py
  2. 1 1
      apps/useradmin/src/useradmin/views.py

+ 1 - 1
apps/useradmin/src/useradmin/ldap_access.py

@@ -104,7 +104,7 @@ class LdapConnection(object):
 
     ldap_result_id = self.ldap_handle.search(base_dn, scope, ldap_filter)
     result_type, result_data = self.ldap_handle.result(ldap_result_id)
-    if result_type == ldap.RES_SEARCH_RESULT and result_data[0][0] is not None:
+    if result_data and result_type == ldap.RES_SEARCH_RESULT:
       data = result_data[0][1]
       user_info = { 'username': data[user_name_attr][0] }
 

+ 1 - 1
apps/useradmin/src/useradmin/views.py

@@ -273,7 +273,7 @@ def add_ldap_user(request):
       username = form.cleaned_data['username']
       import_by_dn = form.cleaned_data['dn']
       user = import_ldap_user(username, import_by_dn)
-      if form.cleaned_data['ensure_home_directory']:
+      if user and form.cleaned_data['ensure_home_directory']:
         try:
           ensure_home_directory(request.fs, user.username)
         except (IOError, WebHdfsException), e: