From 08e75d7a232d1859e09edce9be48fe6ea552fbcb Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 18 Sep 2017 07:21:10 +0200 Subject: [PATCH] [FIX] equality (#969) * [FIX] equality --- base_suspend_security/README.rst | 1 + base_suspend_security/__openerp__.py | 11 ++--------- base_suspend_security/base_suspend_security.py | 5 +++++ base_suspend_security/models/ir_model_access.py | 1 + .../tests/test_base_suspend_security.py | 9 +++++++++ 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/base_suspend_security/README.rst b/base_suspend_security/README.rst index 886d71103..2be3ec761 100644 --- a/base_suspend_security/README.rst +++ b/base_suspend_security/README.rst @@ -1,5 +1,6 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg :alt: License: AGPL-3 + Suspend security ===================== diff --git a/base_suspend_security/__openerp__.py b/base_suspend_security/__openerp__.py index 2c32e1a1d..b0a63a966 100644 --- a/base_suspend_security/__openerp__.py +++ b/base_suspend_security/__openerp__.py @@ -19,20 +19,13 @@ ############################################################################## { "name": "Suspend security", - "version": "8.0.1.0.0", - "author": "Therp BV", + "version": "8.0.1.0.1", + "author": "Therp BV,Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Hidden/Dependency", "summary": "Suspend security checks for a call", "depends": [ 'base', ], - "test": [ - ], - "auto_install": False, "installable": True, - "application": False, - "external_dependencies": { - 'python': [], - }, } diff --git a/base_suspend_security/base_suspend_security.py b/base_suspend_security/base_suspend_security.py index 991d8be80..9bd8ee96d 100644 --- a/base_suspend_security/base_suspend_security.py +++ b/base_suspend_security/base_suspend_security.py @@ -24,10 +24,15 @@ class BaseSuspendSecurityUid(int): return self def __eq__(self, other): + if isinstance(other, BaseSuspendSecurityUid): + return self * 1 == other * 1 if isinstance(other, (int, long)): return False return super(BaseSuspendSecurityUid, self).__int__() == other + def __ne__(self, other): + return not self.__eq__(other) + def __iter__(self): yield super(BaseSuspendSecurityUid, self).__int__() diff --git a/base_suspend_security/models/ir_model_access.py b/base_suspend_security/models/ir_model_access.py index 2f9ad850d..f9f9dc7a3 100644 --- a/base_suspend_security/models/ir_model_access.py +++ b/base_suspend_security/models/ir_model_access.py @@ -27,6 +27,7 @@ class IrModelAccess(models.Model): @tools.ormcache_context(accepted_keys=('lang')) def check(self, cr, uid, model, mode='read', raise_exception=True, context=None): + # pylint: disable=old-api7-method-defined if isinstance(uid, BaseSuspendSecurityUid): return True return super(IrModelAccess, self).check( diff --git a/base_suspend_security/tests/test_base_suspend_security.py b/base_suspend_security/tests/test_base_suspend_security.py index 24e2d889f..45c8278e7 100644 --- a/base_suspend_security/tests/test_base_suspend_security.py +++ b/base_suspend_security/tests/test_base_suspend_security.py @@ -20,6 +20,7 @@ from openerp import exceptions from openerp.tools import mute_logger from openerp.tests.common import TransactionCase +from ..base_suspend_security import BaseSuspendSecurityUid class TestBaseSuspendSecurity(TransactionCase): @@ -52,3 +53,11 @@ class TestBaseSuspendSecurity(TransactionCase): # this tests if _normalize_args conversion works self.env['res.users'].browse( self.env['res.users'].suspend_security().env.uid) + # check equality, that's relevant for picking the right environment + self.assertNotEqual(BaseSuspendSecurityUid(42), 42) + self.assertNotEqual( + BaseSuspendSecurityUid(42), BaseSuspendSecurityUid(43), + ) + self.assertEqual( + BaseSuspendSecurityUid(42), BaseSuspendSecurityUid(42), + )