Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] auth_user_case_insensitive: Migration to 18.0 #756

Open
wants to merge 24 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a59ac30
[IMP] auth_user_case_insensitive: Update module name
May 8, 2017
963d775
[IMP] auth_user_case_insensitive: Drop `search()` override in favor o…
May 9, 2017
23752e7
Note that existing logins are converted to lowercase
dreispt May 15, 2017
e46c4d5
[FIX/IMP] Fixed code for migration from v10 to v11 as per OCA standards.
mgosai Aug 17, 2018
a1d0102
[FIX] Fixed minor missing changes
mgosai Aug 17, 2018
7a75af4
Update __manifest__.py
Aug 20, 2018
8cfcb64
[MIG] auth_user_case_insensitive: Migration to 12.0
May 31, 2019
a047daf
[FIX] auth_user_case_insensitive: LDAP error in tests
remytms Oct 1, 2019
c3248a3
Translated using Weblate (Portuguese (Brazil))
Nov 24, 2019
b24da96
[MIG][13.0] Migrated the module in v13.
Chandresh-SerpentCS Nov 27, 2019
df12611
[MIG] Module migrated in v14.
Chandresh-SerpentCS Feb 10, 2021
1a35da5
[MIG] auth_user_case_insensitive: Migration to 15.0
Herqs Apr 11, 2022
193317e
[MIG] auth_user_case_insensitive: Migration to 16.0
Feb 17, 2023
5e3c361
Translated using Weblate (Spanish)
Ivorra78 Aug 25, 2023
af6e9df
Translated using Weblate (Italian)
mymage Jan 3, 2024
cd7e05b
[IMP] auth_user_case_insensitive: pre-commit stuff
Jan 29, 2024
fe26162
[MIG] auth_user_case_insensitive: Migration to 17.0
Jan 29, 2024
b019440
[UPD] Update auth_user_case_insensitive.pot
Apr 24, 2024
9addad3
[BOT] post-merge updates
OCA-git-bot Apr 24, 2024
2f8ed3f
Update translation files
weblate Apr 25, 2024
55e9917
[IMP] auth_user_case_insensitive: pre-commit auto fixes
El-khamisi Jan 23, 2025
13f74eb
[MIG] auth_user_case_insensitive: Migration to 18.0
El-khamisi Jan 23, 2025
15afd7b
move hooks back to hooks.py
El-khamisi Jan 23, 2025
f27240d
pre-commit auto fix
El-khamisi Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions auth_user_case_insensitive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@
# Copyright 2021 Open Source Integrators
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from odoo import _
from odoo.exceptions import ValidationError
from . import models
from .hooks import pre_init_hook_login_check
from .hooks import post_init_hook_login_convert


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.
"""
with env.cr.savepoint():
users = []
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)
else:
raise ValidationError(

Check warning on line 24 in auth_user_case_insensitive/__init__.py

View check run for this annotation

Codecov / codecov/patch

auth_user_case_insensitive/__init__.py#L24

Added line #L24 was not covered by tests
_("Conflicting user logins exist for `%s`", login)
)


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.
"""
with env.cr.savepoint():
env.cr.execute("UPDATE res_users SET login=lower(login)")
El-khamisi marked this conversation as resolved.
Show resolved Hide resolved
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
34 changes: 0 additions & 34 deletions auth_user_case_insensitive/hooks.py

This file was deleted.

8 changes: 5 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,13 @@ 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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes track with core Odoo implementation of auth_passkey 1:

Footnotes

  1. https://github.com/odoo/odoo/commit/8b9bd6f88eb313dd29b05fc2decff77e6aff8bb8

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get what you mean, can you explain more, please?


@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",
)
Loading