Skip to content

Commit

Permalink
[FIX] base: Make user lookup by email case insensitive.
Browse files Browse the repository at this point in the history
This avoids user frustration when attempting to reset password
via email address.
  • Loading branch information
amh-mw committed Apr 18, 2024
1 parent 4e53ef2 commit 410ca55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion odoo/addons/base/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from odoo.osv import expression
from odoo.service.db import check_super
from odoo.tools import partition, collections, frozendict, lazy_property, image_process
from odoo.tools.mail import email_escape_char

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -699,7 +700,7 @@ def _get_login_domain(self, login):

@api.model
def _get_email_domain(self, email):
return [('email', '=', email)]
return [('email', '=ilike', email_escape_char(email))]

@api.model
def _get_login_order(self):
Expand Down
7 changes: 7 additions & 0 deletions odoo/addons/base/tests/test_res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,10 @@ def test_read_group_with_reified_field(self):
# Verify that the read_group is raising an error if reified field is used as groupby
with self.assertRaises(ValueError):
User.read_group([], fnames + [reified_fname], [reified_fname])

def test_get_email_domain(self):
""" Check that _get_email_domain escapes wildcards """
User = self.env['res.users']
self.assertEqual(User._get_email_domain('\\[email protected]'), [('email', '=ilike', '\\\\[email protected]')], "backslashes should be escaped")
self.assertEqual(User._get_email_domain('%[email protected]'), [('email', '=ilike', '\\%[email protected]')], "percents should be escaped")
self.assertEqual(User._get_email_domain('[email protected]'), [('email', '=ilike', '\\[email protected]')], "underscores should be escaped")

0 comments on commit 410ca55

Please sign in to comment.