diff --git a/auth_user_insensitive/README.rst b/auth_user_insensitive/README.rst index 4fe0046c4..2e3d450ad 100644 --- a/auth_user_insensitive/README.rst +++ b/auth_user_insensitive/README.rst @@ -1,6 +1,6 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 +.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 ======================= Case Insensitive Logins @@ -38,8 +38,6 @@ Contributors * Dave Lasley * Ted Salmon - - Maintainer ---------- diff --git a/auth_user_insensitive/__init__.py b/auth_user_insensitive/__init__.py index 1bfd9cc43..1fc495145 100644 --- a/auth_user_insensitive/__init__.py +++ b/auth_user_insensitive/__init__.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # Copyright 2015-2017 LasLabs Inc. -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). from . import models +from .hooks import pre_init_hook_login_check +from .hooks import post_init_hook_login_convert diff --git a/auth_user_insensitive/__manifest__.py b/auth_user_insensitive/__manifest__.py index d6863109e..be2d7a0b7 100644 --- a/auth_user_insensitive/__manifest__.py +++ b/auth_user_insensitive/__manifest__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Copyright 2015-2017 LasLabs Inc. -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). { "name": "Case Insensitive Logins", "summary": "Makes the user login field case insensitive", @@ -14,5 +14,6 @@ "depends": [ "mail", ], - "data": [], + 'pre_init_hook': 'pre_init_hook_login_check', + 'post_init_hook': 'post_init_hook_login_convert', } diff --git a/auth_user_insensitive/hooks.py b/auth_user_insensitive/hooks.py new file mode 100644 index 000000000..330ecac88 --- /dev/null +++ b/auth_user_insensitive/hooks.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import _ +from odoo.exceptions import ValidationError + + +def pre_init_hook_login_check(cr): + """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 cr.savepoint(): + users = [] + cr.execute("SELECT login FROM res_users") + for user in cr.fetchall(): + login = user[0].lower() + if login not in users: + users.append(login) + else: + raise ValidationError( + _('Conflicting user logins exist for `%s`' % login) + ) + + +def post_init_hook_login_convert(cr, registry): + """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 cr.savepoint(): + cr.execute("UPDATE res_users SET login=lower(login)") diff --git a/auth_user_insensitive/models/__init__.py b/auth_user_insensitive/models/__init__.py index dbdca428b..ee30f654a 100644 --- a/auth_user_insensitive/models/__init__.py +++ b/auth_user_insensitive/models/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- # Copyright 2015-2017 LasLabs Inc. -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). from . import res_users diff --git a/auth_user_insensitive/models/res_users.py b/auth_user_insensitive/models/res_users.py index 6e4fcd4a1..5ec8cf817 100644 --- a/auth_user_insensitive/models/res_users.py +++ b/auth_user_insensitive/models/res_users.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Copyright 2015-2017 LasLabs Inc. -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). from odoo import api, fields, models @@ -10,9 +10,6 @@ class ResUsers(models.Model): _inherit = 'res.users' login = fields.Char( - 'Login', - size=64, - required=True, help='Used to log into the system. Case insensitive.', ) @@ -28,13 +25,13 @@ class ResUsers(models.Model): return super(ResUsers, self).search(domain, *args, **kwargs) @api.model - def create(self, vals, ): + def create(self, vals): """ Overload create to lowercase login """ vals['login'] = vals.get('login', '').lower() return super(ResUsers, self).create(vals) @api.multi - def write(self, vals, ): + def write(self, vals): """ Overload write to lowercase login """ if vals.get('login'): vals['login'] = vals['login'].lower() diff --git a/auth_user_insensitive/tests/__init__.py b/auth_user_insensitive/tests/__init__.py index b25ca249c..ea6bf27c9 100644 --- a/auth_user_insensitive/tests/__init__.py +++ b/auth_user_insensitive/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- # Copyright 2015-2017 LasLabs Inc. -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). from . import test_res_users diff --git a/auth_user_insensitive/tests/test_res_users.py b/auth_user_insensitive/tests/test_res_users.py index f3c94b67f..31f28c1e5 100644 --- a/auth_user_insensitive/tests/test_res_users.py +++ b/auth_user_insensitive/tests/test_res_users.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Copyright 2015-2017 LasLabs Inc. -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). from odoo.tests.common import TransactionCase