From 4b17643be7673c8dd6812797f14f235236c2bc89 Mon Sep 17 00:00:00 2001 From: herqs Date: Mon, 28 Mar 2022 14:26:59 +0300 Subject: [PATCH] [MIG] auth_user_case_insensitive: Migrate to V15 --- auth_user_case_insensitive/__manifest__.py | 2 +- .../models/res_users.py | 4 +-- .../tests/test_res_users.py | 36 ++++++------------- .../odoo/addons/auth_user_case_insensitive | 1 + setup/auth_user_case_insensitive/setup.py | 6 ++++ 5 files changed, 21 insertions(+), 28 deletions(-) create mode 120000 setup/auth_user_case_insensitive/odoo/addons/auth_user_case_insensitive create mode 100644 setup/auth_user_case_insensitive/setup.py diff --git a/auth_user_case_insensitive/__manifest__.py b/auth_user_case_insensitive/__manifest__.py index 00d1d4b864..2236d35f0a 100644 --- a/auth_user_case_insensitive/__manifest__.py +++ b/auth_user_case_insensitive/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Case Insensitive Logins", "summary": "Makes the user login field case insensitive", - "version": "14.0.1.0.0", + "version": "15.0.1.0.0", "category": "Authentication", "website": "https://github.com/OCA/server-auth", "author": "LasLabs, Odoo Community Association (OCA)", diff --git a/auth_user_case_insensitive/models/res_users.py b/auth_user_case_insensitive/models/res_users.py index 1d0569cb26..2b1b964141 100644 --- a/auth_user_case_insensitive/models/res_users.py +++ b/auth_user_case_insensitive/models/res_users.py @@ -22,13 +22,13 @@ def _login(cls, db, login, password, user_agent_env): @api.model_create_multi def create(self, vals_list): - """ Overload create multiple to lowercase login """ + """Overload create multiple to lowercase login""" for val in vals_list: val["login"] = val.get("login", "").lower() return super(ResUsers, self).create(vals_list) def write(self, vals): - """ Overload write to lowercase login """ + """Overload write to lowercase login""" if vals.get("login"): vals["login"] = vals["login"].lower() return super(ResUsers, self).write(vals) diff --git a/auth_user_case_insensitive/tests/test_res_users.py b/auth_user_case_insensitive/tests/test_res_users.py index c18741b4ce..455704bc17 100644 --- a/auth_user_case_insensitive/tests/test_res_users.py +++ b/auth_user_case_insensitive/tests/test_res_users.py @@ -2,9 +2,7 @@ # Copyright 2021 Open Source Integrators # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). -from odoo import api, registry from odoo.tests.common import TransactionCase -from odoo.tools import mute_logger class TestResUsers(TransactionCase): @@ -20,13 +18,13 @@ def setUp(self): self.model_obj = self.env["res.users"] def _new_record(self): - """ It should enerate a new record to test with """ + """It should enerate a new record to test with""" partner_id = self.env["res.partner"].create(self.partner_vals) self.vals["partner_id"] = partner_id.id return self.model_obj.create(self.vals) def test_login_is_lowercased_on_create(self): - """ It should verify the login is set to lowercase on create """ + """It should verify the login is set to lowercase on create""" rec_id = self._new_record() self.assertEqual( self.login.lower(), @@ -35,7 +33,7 @@ def test_login_is_lowercased_on_create(self): ) def test_login_is_lowercased_on_write(self): - """ It should verify the login is set to lowercase on write """ + """It should verify the login is set to lowercase on write""" rec_id = self._new_record() rec_id.write({"login": self.login}) self.assertEqual( @@ -45,26 +43,14 @@ def test_login_is_lowercased_on_write(self): ) def test_login_login_is_lowercased(self): - """ It should verify the login is set to lowercase on login """ - rec_id = self._new_record() - # We have to commit this cursor, because `_login` uses a fresh cursor - self.env.cr.commit() - with mute_logger("odoo.addons.auth_ldap.models.res_company_ldap"): - res_id = self.model_obj._login( - self.env.registry.db_name, - self.login.upper(), - "password", - {"interactive": True}, - ) - # Now clean up our mess to preserve idempotence - with api.Environment.manage(): - with registry(self.env.registry.db_name).cursor() as new_cr: - new_cr.execute( - "DELETE FROM res_users WHERE \ - login='%s'" - % self.login.lower() - ) - new_cr.commit() + """It should verify the login is set to lowercase on login""" + rec_id = self.model_obj.search([("login", "=", "admin")]) + res_id = self.model_obj._login( + self.env.registry.db_name, + "AdMiN", + "admin", + {"interactive": True}, + ) self.assertEqual( rec_id.id, res_id, diff --git a/setup/auth_user_case_insensitive/odoo/addons/auth_user_case_insensitive b/setup/auth_user_case_insensitive/odoo/addons/auth_user_case_insensitive new file mode 120000 index 0000000000..8518faeb78 --- /dev/null +++ b/setup/auth_user_case_insensitive/odoo/addons/auth_user_case_insensitive @@ -0,0 +1 @@ +../../../../auth_user_case_insensitive \ No newline at end of file diff --git a/setup/auth_user_case_insensitive/setup.py b/setup/auth_user_case_insensitive/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/auth_user_case_insensitive/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)