Skip to content

Commit

Permalink
[MIG] auth_user_case_insensitive: Migrate to V15
Browse files Browse the repository at this point in the history
  • Loading branch information
Herqs committed Mar 28, 2022
1 parent 8f26d82 commit 4b17643
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion auth_user_case_insensitive/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
4 changes: 2 additions & 2 deletions auth_user_case_insensitive/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
36 changes: 11 additions & 25 deletions auth_user_case_insensitive/tests/test_res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(),
Expand All @@ -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(
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions setup/auth_user_case_insensitive/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 4b17643

Please sign in to comment.