Skip to content

Commit

Permalink
[MIG] auth_user_case_insensitive: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Herqs committed Apr 11, 2022
1 parent 8f26d82 commit da63b64
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 38 deletions.
10 changes: 5 additions & 5 deletions auth_user_case_insensitive/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Case Insensitive Logins
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
:target: https://github.com/OCA/server-auth/tree/14.0/auth_user_case_insensitive
:target: https://github.com/OCA/server-auth/tree/15.0/auth_user_case_insensitive
:alt: OCA/server-auth
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-auth-14-0/server-auth-14-0-auth_user_case_insensitive
:target: https://translation.odoo-community.org/projects/server-auth-15-0/server-auth-15-0-auth_user_case_insensitive
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/251/14.0
:target: https://runbot.odoo-community.org/runbot/251/15.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -54,7 +54,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_user_case_insensitive%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_user_case_insensitive%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -87,6 +87,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/14.0/auth_user_case_insensitive>`_ project on GitHub.
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/15.0/auth_user_case_insensitive>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
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
2 changes: 1 addition & 1 deletion auth_user_case_insensitive/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def pre_init_hook_login_check(cr):
users.append(login)
else:
raise ValidationError(
_("Conflicting user logins exist for `%s`" % login)
_("Conflicting user logins exist for `%s`", login)
)


Expand Down
37 changes: 37 additions & 0 deletions auth_user_case_insensitive/i18n/lt.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * auth_user_case_insensitive
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-04-07 08:58+0000\n"
"PO-Revision-Date: 2022-04-07 08:58+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: auth_user_case_insensitive
#: code:addons/auth_user_case_insensitive/hooks.py:0
#, python-format
msgid "Conflicting user logins exist for `%s`"
msgstr "Egzistuoja keli vartotojai su prisijungimu `%s`"

#. module: auth_user_case_insensitive
#: model:ir.model.fields,field_description:auth_user_case_insensitive.field_res_users__login
msgid "Login"
msgstr "Prisijungimas"

#. module: auth_user_case_insensitive
#: model:ir.model.fields,help:auth_user_case_insensitive.field_res_users__login
msgid "Used to log into the system. Case insensitive."
msgstr "Naudojamas prisijungti į sistemą. Raidžių dydis nesvarbus."

#. module: auth_user_case_insensitive
#: model:ir.model,name:auth_user_case_insensitive.model_res_users
msgid "Users"
msgstr "Vartotojai"
6 changes: 3 additions & 3 deletions auth_user_case_insensitive/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ class ResUsers(models.Model):
@classmethod
def _login(cls, db, login, password, user_agent_env):
"""Overload _login to lowercase the `login` before passing to the
super"""
super."""
login = login.lower()
return super(ResUsers, cls)._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 """
"""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)
6 changes: 3 additions & 3 deletions auth_user_case_insensitive/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Case Insensitive Logins</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-auth/tree/14.0/auth_user_case_insensitive"><img alt="OCA/server-auth" src="https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-auth-14-0/server-auth-14-0-auth_user_case_insensitive"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/251/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-auth/tree/15.0/auth_user_case_insensitive"><img alt="OCA/server-auth" src="https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-auth-15-0/server-auth-15-0-auth_user_case_insensitive"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/251/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module makes user logins case insensitive. It also overwrites the
search method to allow these case insensitive logins to work on a database
that previously had case sensitive logins.</p>
Expand Down Expand Up @@ -399,7 +399,7 @@ <h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-auth/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/server-auth/issues/new?body=module:%20auth_user_case_insensitive%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/server-auth/issues/new?body=module:%20auth_user_case_insensitive%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -426,7 +426,7 @@ <h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-auth/tree/14.0/auth_user_case_insensitive">OCA/server-auth</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-auth/tree/15.0/auth_user_case_insensitive">OCA/server-auth</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
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 """
"""Gnerate 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 """
"""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 """
"""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()
"""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 da63b64

Please sign in to comment.