From 7ddc4c7300afa8fe3ef60d1585a629cb2cfb39f9 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Thu, 10 Jan 2019 13:41:51 +0100 Subject: [PATCH] [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 --- users_ldap_populate/models/users_ldap.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/users_ldap_populate/models/users_ldap.py b/users_ldap_populate/models/users_ldap.py index 818d0291d..dcf610490 100644 --- a/users_ldap_populate/models/users_ldap.py +++ b/users_ldap_populate/models/users_ldap.py @@ -69,13 +69,28 @@ class CompanyLDAP(models.Model): conf['ldap_filter']) results = self.get_ldap_entry_dicts(conf) for result in results: + login = result[1][login_attr][0].lower().strip() user_id = self.with_context( 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: - 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) users_created = users_model.search_count([]) - users_count_before