Skip to content

Commit

Permalink
[MIG] auth_user_case_insensitive: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
El-khamisi committed Jan 24, 2025
1 parent 55e9917 commit 2c59d4a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 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": "18.0.0.0.0",
"version": "18.0.1.0.0",
"category": "Authentication",
"website": "https://github.com/OCA/server-auth",
"author": "LasLabs, Odoo Community Association (OCA)",
Expand Down
7 changes: 4 additions & 3 deletions auth_user_case_insensitive/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ class ResUsers(models.Model):
login = fields.Char(help="Used to log into the system. Case insensitive.")

@classmethod
def _login(cls, db, login, password, user_agent_env):
def _login(cls, db, credential, user_agent_env):
"""Overload _login to lowercase the `login` before passing to the
super."""
login = login.lower()
return super()._login(db, login, password, user_agent_env=user_agent_env)
if credential.get("type") and credential["type"] == "password":
credential["login"] = credential["login"].lower()
return super()._login(db, credential, user_agent_env=user_agent_env)

@api.model_create_multi
def create(self, vals_list):
Expand Down
8 changes: 4 additions & 4 deletions auth_user_case_insensitive/tests/test_res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def test_login_is_lowercased_on_write(self):
def test_login_login_is_lowercased(self):
"""verify the login is set to lowercase on login."""
rec_id = self.model_obj.search([("login", "=", "admin")])
res_id = self.model_obj._login(
credential = {"login": "AdMiN", "password": "admin", "type": "password"}
auth_info = self.model_obj._login(
self.env.registry.db_name,
"AdMiN",
"admin",
credential,
{"interactive": True},
)
self.assertEqual(
rec_id.id,
res_id,
auth_info["uid"],
"Login with with uppercase chars was not \
successful",
)

0 comments on commit 2c59d4a

Please sign in to comment.