Browse Source

[FIX] equality (#969)

* [FIX] equality
pull/994/head
Holger Brunn 7 years ago
committed by Stefan Rijnhart (Opener)
parent
commit
08e75d7a23
  1. 1
      base_suspend_security/README.rst
  2. 11
      base_suspend_security/__openerp__.py
  3. 5
      base_suspend_security/base_suspend_security.py
  4. 1
      base_suspend_security/models/ir_model_access.py
  5. 9
      base_suspend_security/tests/test_base_suspend_security.py

1
base_suspend_security/README.rst

@ -1,5 +1,6 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3 :alt: License: AGPL-3
Suspend security Suspend security
===================== =====================

11
base_suspend_security/__openerp__.py

@ -19,20 +19,13 @@
############################################################################## ##############################################################################
{ {
"name": "Suspend security", "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", "license": "AGPL-3",
"category": "Hidden/Dependency", "category": "Hidden/Dependency",
"summary": "Suspend security checks for a call", "summary": "Suspend security checks for a call",
"depends": [ "depends": [
'base', 'base',
], ],
"test": [
],
"auto_install": False,
"installable": True, "installable": True,
"application": False,
"external_dependencies": {
'python': [],
},
} }

5
base_suspend_security/base_suspend_security.py

@ -24,10 +24,15 @@ class BaseSuspendSecurityUid(int):
return self return self
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, BaseSuspendSecurityUid):
return self * 1 == other * 1
if isinstance(other, (int, long)): if isinstance(other, (int, long)):
return False return False
return super(BaseSuspendSecurityUid, self).__int__() == other return super(BaseSuspendSecurityUid, self).__int__() == other
def __ne__(self, other):
return not self.__eq__(other)
def __iter__(self): def __iter__(self):
yield super(BaseSuspendSecurityUid, self).__int__() yield super(BaseSuspendSecurityUid, self).__int__()

1
base_suspend_security/models/ir_model_access.py

@ -27,6 +27,7 @@ class IrModelAccess(models.Model):
@tools.ormcache_context(accepted_keys=('lang')) @tools.ormcache_context(accepted_keys=('lang'))
def check(self, cr, uid, model, mode='read', raise_exception=True, def check(self, cr, uid, model, mode='read', raise_exception=True,
context=None): context=None):
# pylint: disable=old-api7-method-defined
if isinstance(uid, BaseSuspendSecurityUid): if isinstance(uid, BaseSuspendSecurityUid):
return True return True
return super(IrModelAccess, self).check( return super(IrModelAccess, self).check(

9
base_suspend_security/tests/test_base_suspend_security.py

@ -20,6 +20,7 @@
from openerp import exceptions from openerp import exceptions
from openerp.tools import mute_logger from openerp.tools import mute_logger
from openerp.tests.common import TransactionCase from openerp.tests.common import TransactionCase
from ..base_suspend_security import BaseSuspendSecurityUid
class TestBaseSuspendSecurity(TransactionCase): class TestBaseSuspendSecurity(TransactionCase):
@ -52,3 +53,11 @@ class TestBaseSuspendSecurity(TransactionCase):
# this tests if _normalize_args conversion works # this tests if _normalize_args conversion works
self.env['res.users'].browse( self.env['res.users'].browse(
self.env['res.users'].suspend_security().env.uid) 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),
)
Loading…
Cancel
Save