USERS_LDAP: fix when module not installed

bzr revid: ced-4293a339237c7b8fa33f8000e79b1f1651fc1f57
This commit is contained in:
ced 2007-03-07 20:00:04 +00:00
parent 34add232ae
commit cb3ecb3b1a
1 changed files with 64 additions and 57 deletions

View File

@ -53,6 +53,11 @@ res_company()
def ldap_login(oldfnc):
def _ldap_login(db, login, passwd):
cr = pooler.get_db(db).cursor()
module_obj = pooler.get_pool(cr.dbname).get('ir.module.module')
module_ids = module_obj.search(cr, 1, [('name', '=', 'users_ldap')])
if module_ids:
state = module_obj.read(cr, 1, module_ids, ['state'])[0]['state']
if state in ('installed', 'to upgrade', 'to remove'):
cr.execute("select id, name, ldap_server, ldap_binddn, ldap_password, ldap_filter, ldap_base from res_company where ldap_server != '' and ldap_binddn != ''")
for res_company in cr.dictfetchall():
try:
@ -83,10 +88,7 @@ def ldap_login(oldfnc):
cr.commit()
cr.close()
return res
else:
print "failed"
except Exception, e:
print e
continue
cr.close()
return oldfnc(db, login, passwd)
@ -99,6 +101,11 @@ def ldap_check(oldfnc):
if security._uid_cache.has_key(uid) and (security._uid_cache[uid]==passwd):
return True
cr = pooler.get_db(db).cursor()
module_obj = pooler.get_pool(cr.dbname).get('ir.module.module')
module_ids = module_obj.search(cr, 1, [('name', '=', 'users_ldap')])
if module_ids:
state = module_obj.read(cr, 1, module_ids, ['state'])[0]['state']
if state in ('installed', 'to upgrade', 'to remove'):
users_obj = pooler.get_pool(cr.dbname).get('res.users')
user = users_obj.browse(cr, 1, uid)
if user and user.company_id.ldap_server and user.company_id.ldap_binddn:
@ -121,7 +128,7 @@ def ldap_check(oldfnc):
cr.close()
return True
except Exception, e:
print e
pass
cr.close()
return oldfnc(db, uid, passwd)
return _ldap_check