Browse Source

[FIX] strange behavior of users_ldap_populate

when the LDAP search returns values for a user existing in Odoo but
deactivated, the 'deactivate unknown users' feature was silently disabled.

This commit changes the behavior to reactivate the user in Odoo
pull/1194/head
Alexandre Fayolle 6 years ago
committed by Holger Brunn
parent
commit
7ddc4c7300
  1. 23
      users_ldap_populate/models/users_ldap.py

23
users_ldap_populate/models/users_ldap.py

@ -69,13 +69,28 @@ class CompanyLDAP(models.Model):
conf['ldap_filter']) conf['ldap_filter'])
results = self.get_ldap_entry_dicts(conf) results = self.get_ldap_entry_dicts(conf)
for result in results: for result in results:
login = result[1][login_attr][0].lower().strip()
user_id = self.with_context( user_id = self.with_context(
no_reset_password=True no_reset_password=True
).get_or_create_user(conf, result[1][login_attr][0], result)
# this happens if something goes wrong while creating the user
# or fetching information from ldap
).get_or_create_user(conf, login, result)
if not user_id: if not user_id:
deactivate_unknown = False
# this happens if the user exists but is active = False
# -> fetch the user again and reactivate it
self.env.cr.execute(
"SELECT id FROM res_users "
"WHERE lower(login)=%s",
(login,))
res = self.env.cr.fetchone()
if res:
self.env['res.users'].sudo().browse(
res[0]
).write(
{'active': True}
)
else:
raise UserError(
'Unable to process user with login %s' % login
)
known_user_ids.append(user_id) known_user_ids.append(user_id)
users_created = users_model.search_count([]) - users_count_before users_created = users_model.search_count([]) - users_count_before

Loading…
Cancel
Save