Browse Source

Add case insensitive username module

pull/826/head
Dave Lasley 9 years ago
committed by Ted Salmon
parent
commit
048d5c0178
  1. 32
      res_users_case_insensitive/README.rst
  2. 3
      res_users_case_insensitive/__init__.py
  3. 32
      res_users_case_insensitive/__openerp__.py
  4. 3
      res_users_case_insensitive/models/__init__.py
  5. 52
      res_users_case_insensitive/models/fields.py
  6. 34
      res_users_case_insensitive/models/res_users.py
  7. BIN
      res_users_case_insensitive/static/description/icon.png
  8. 12745
      res_users_case_insensitive/static/description/icon.svg
  9. 2
      res_users_case_insensitive/tests/__init__.py
  10. 51
      res_users_case_insensitive/tests/test_res_users.py

32
res_users_case_insensitive/README.rst

@ -0,0 +1,32 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
==========================
Case Insensitive Usernames
==========================
This module extends the functionality of res.users to make logins case
insensitive.
Credits
=======
Images
------
* LasLabs: `Icon <https://repo.laslabs.com/projects/TEM/repos/odoo-module_template/browse/module_name/static/description/icon.svg?raw>`_.
Contributors
------------
* Firstname Lastname <email.address@laslabs.com>
Maintainer
----------
.. image:: https://laslabs.com/logo.png
:alt: LasLabs Inc.
:target: https://laslabs.com
This module is maintained by LasLabs Inc.

3
res_users_case_insensitive/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models
from . import tests

32
res_users_case_insensitive/__openerp__.py

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Dave Lasley <dave@laslabs.com>
# Copyright: 2016-TODAY LasLabs, Inc. [https://laslabs.com]
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name": "Case Insensitive Logins",
"summary": "Makes the login field of res.users case insensitive.",
"version": "9.0.1.0.0",
"category": "Base",
"website": "https://laslabs.com/",
"author": "LasLabs",
"license": "AGPL-3",
"application": False,
"installable": True,
}

3
res_users_case_insensitive/models/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import fields
from . import res_users

52
res_users_case_insensitive/models/fields.py

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Dave Lasley <dave@laslabs.com>
# Copyright: 2015 LasLabs, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import fields
import base64
from Crypto.Cipher import AES
from Crypto import Random
class CharLower(fields.Char):
"""
Identical to fields.Char, except lower cased
:param int size: the maximum size of values stored for that field
:param translate: whether the value of this field can be translated
"""
def convert_to_cache(self, value, record, validate=True):
"""
convert ``value`` to the cache level in ``env``; ``value`` may come
from an assignment, or have the format of methods
:meth:`BaseModel.read` or :meth:`BaseModel.write`
:param record: the target record for the assignment,
or an empty recordset
:param bool validate: when True, field-specific validation of
``value`` will be performed
"""
res = super(CharLower, self).convert_to_cache(value, record, validate)
if not res:
return res
return res.lower()

34
res_users_case_insensitive/models/res_users.py

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Dave Lasley <dave@laslabs.com>
# Copyright: 2016-TODAY LasLabs, Inc. [https://laslabs.com]
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, api
from openerp.exceptions import ValidationError
from openerp.addons.res_users_case_insensitive.models.fields import CharLower
class ResUsers(models.Model):
_inherit = 'res.users'
login = CharLower(
'Login',
size=64,
required=True,
help='Used to log into the system. Case insensitive.',
)

BIN
res_users_case_insensitive/static/description/icon.png

After

Width: 600  |  Height: 518  |  Size: 10 KiB

12745
res_users_case_insensitive/static/description/icon.svg
File diff suppressed because it is too large
View File

2
res_users_case_insensitive/tests/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import test_something

51
res_users_case_insensitive/tests/test_res_users.py

@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Dave Lasley <dave@laslabs.com>
# Copyright: 2016-TODAY LasLabs, Inc. [https://laslabs.com]
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tests.common import TransactionCase
class TestResUsers(TransactionCase):
def setUp(self, *args, **kwargs):
result = super(SomethingCase, self).setUp(*args, **kwargs)
self.login = 'TeSt@ExAmPlE.CoM'
self.partner_vals = {
'name': 'Partner',
'is_company': False,
'email': self.login,
}
self.vals = {
'name': 'User',
'login': self.login,
'password': 'password',
}
self.model_obj = self.env['res.users']
def _new_record(self, ):
partner_id = self.env['res.partner'].create(self.partner_vals)
return self.model_obj.create(self.vals)
def test_login_is_lowercased_on_save(self, ):
rec_id = self._new_record()
self.assertEqual(
self.login.lower(), rec_id.login,
'Login was not lowercased when saved to cache',
)
Loading…
Cancel
Save