Browse Source

[IMP] auth_user_insensitive: Updates per PR

* Update License
* Fix whitespace in README & Empty Keys in manifest
* Remove length declaration
* Add hooks
pull/826/head
Ted Salmon 8 years ago
parent
commit
736e908f94
No known key found for this signature in database GPG Key ID: 1E92222DD9AF3435
  1. 8
      auth_user_insensitive/README.rst
  2. 4
      auth_user_insensitive/__init__.py
  3. 5
      auth_user_insensitive/__manifest__.py
  4. 36
      auth_user_insensitive/hooks.py
  5. 2
      auth_user_insensitive/models/__init__.py
  6. 9
      auth_user_insensitive/models/res_users.py
  7. 2
      auth_user_insensitive/tests/__init__.py
  8. 2
      auth_user_insensitive/tests/test_res_users.py

8
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 <dave@laslabs.com>
* Ted Salmon <tsalmon@laslabs.com>
Maintainer
----------

4
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

5
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',
}

36
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)")

2
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

9
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()

2
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

2
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

Loading…
Cancel
Save