Skip to content

Commit

Permalink
[MIG] auth_user_case_insensitive: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyas caluwe committed Jan 29, 2024
1 parent 4a827de commit 8ec115e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 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": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Authentication",
"website": "https://github.com/OCA/server-auth",
"author": "LasLabs, Odoo Community Association (OCA)",
Expand Down
24 changes: 11 additions & 13 deletions auth_user_case_insensitive/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
from odoo.exceptions import ValidationError


def pre_init_hook_login_check(cr):
def pre_init_hook_login_check(env):
"""This hook will look to see if any conflicting logins exist before
the module is installed
:param openerp.sql_db.Cursor cr:
Database cursor.
:param env:
Environment.
"""
with cr.savepoint():
with env.cr.savepoint():
users = []
cr.execute("SELECT login FROM res_users")
for user in cr.fetchall():
env.cr.execute("SELECT login FROM res_users")
for user in env.cr.fetchall():
login = user[0].lower()
if login not in users:
users.append(login)
Expand All @@ -25,12 +25,10 @@ def pre_init_hook_login_check(cr):
)


def post_init_hook_login_convert(cr, registry):
def post_init_hook_login_convert(env):
"""After the module is installed, set all logins to lowercase
:param openerp.sql_db.Cursor cr:
Database cursor.
:param openerp.modules.registry.RegistryManager registry:
Database registry, using v7 api.
:param env:
Environment.
"""
with cr.savepoint():
cr.execute("UPDATE res_users SET login=lower(login)")
with env.cr.savepoint():
env.cr.execute("UPDATE res_users SET login=lower(login)")
8 changes: 3 additions & 5 deletions auth_user_case_insensitive/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ def _login(cls, db, login, password, user_agent_env):
"""Overload _login to lowercase the `login` before passing to the
super."""
login = login.lower()
return super(ResUsers, cls)._login(
db, login, password, user_agent_env=user_agent_env
)
return super()._login(db, login, password, user_agent_env=user_agent_env)

@api.model_create_multi
def create(self, vals_list):
"""Overload create multiple to lowercase login."""
for val in vals_list:
val["login"] = val.get("login", "").lower()
return super(ResUsers, self).create(vals_list)
return super().create(vals_list)

def write(self, vals):
"""Overload write to lowercase login."""
if vals.get("login"):
vals["login"] = vals["login"].lower()
return super(ResUsers, self).write(vals)
return super().write(vals)
2 changes: 1 addition & 1 deletion auth_user_case_insensitive/tests/test_res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class TestResUsers(TransactionCase):
def setUp(self):
super(TestResUsers, self).setUp()
super().setUp()
self.login = "[email protected]"
self.partner_vals = {
"name": "Partner",
Expand Down

0 comments on commit 8ec115e

Please sign in to comment.