From 3c29d07893b7652d189693096702dab6b0ac4494 Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Fri, 28 Oct 2016 10:00:45 +0200 Subject: [PATCH] [MIG] base_suspend_security to 10.0 (#586) --- base_suspend_security/README.rst | 4 ++-- base_suspend_security/__manifest__.py | 12 ++---------- base_suspend_security/base_suspend_security.py | 3 --- base_suspend_security/models/__init__.py | 1 + base_suspend_security/models/base.py | 15 +++++++++++++++ base_suspend_security/models/ir_model_access.py | 13 ++++++------- base_suspend_security/models/ir_rule.py | 11 ++--------- base_suspend_security/models/res_users.py | 7 +++---- .../tests/test_base_suspend_security.py | 6 ++---- setup/base_suspend_security/odoo/__init__.py | 1 + .../base_suspend_security/odoo/addons/__init__.py | 1 + .../odoo/addons/base_suspend_security | 1 + setup/base_suspend_security/setup.py | 6 ++++++ 13 files changed, 42 insertions(+), 39 deletions(-) create mode 100644 base_suspend_security/models/base.py create mode 100644 setup/base_suspend_security/odoo/__init__.py create mode 100644 setup/base_suspend_security/odoo/addons/__init__.py create mode 120000 setup/base_suspend_security/odoo/addons/base_suspend_security create mode 100644 setup/base_suspend_security/setup.py diff --git a/base_suspend_security/README.rst b/base_suspend_security/README.rst index 886d71103..3bc2cc8f1 100644 --- a/base_suspend_security/README.rst +++ b/base_suspend_security/README.rst @@ -29,8 +29,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback -`here `_. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback. Credits ======= @@ -39,6 +38,7 @@ Contributors ------------ * Holger Brunn +* Laurent Mignon Maintainer ---------- diff --git a/base_suspend_security/__manifest__.py b/base_suspend_security/__manifest__.py index 3fa4218f4..2d3d04461 100644 --- a/base_suspend_security/__manifest__.py +++ b/base_suspend_security/__manifest__.py @@ -19,20 +19,12 @@ ############################################################################## { "name": "Suspend security", - "version": "9.0.1.0.0", - "author": "Therp BV", + "version": "10.0.1.0.0", + "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': False, - "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..dc7cdc46a 100644 --- a/base_suspend_security/base_suspend_security.py +++ b/base_suspend_security/base_suspend_security.py @@ -30,6 +30,3 @@ class BaseSuspendSecurityUid(int): def __iter__(self): yield super(BaseSuspendSecurityUid, self).__int__() - - -SUSPEND_METHOD = 'suspend_security' diff --git a/base_suspend_security/models/__init__.py b/base_suspend_security/models/__init__.py index 864544856..029724b87 100644 --- a/base_suspend_security/models/__init__.py +++ b/base_suspend_security/models/__init__.py @@ -20,3 +20,4 @@ from . import ir_rule from . import ir_model_access from . import res_users +from . import base diff --git a/base_suspend_security/models/base.py b/base_suspend_security/models/base.py new file mode 100644 index 000000000..53b462b99 --- /dev/null +++ b/base_suspend_security/models/base.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models +from ..base_suspend_security import BaseSuspendSecurityUid + + +class Base(models.AbstractModel): + + _inherit = 'base' + + @api.model + def suspend_security(self): + return self.sudo(user=BaseSuspendSecurityUid(self.env.uid)) diff --git a/base_suspend_security/models/ir_model_access.py b/base_suspend_security/models/ir_model_access.py index 9a0afa3d9..f67d86321 100644 --- a/base_suspend_security/models/ir_model_access.py +++ b/base_suspend_security/models/ir_model_access.py @@ -17,19 +17,18 @@ # along with this program. If not, see . # ############################################################################## -from openerp import models, tools +from odoo import models, api, tools from ..base_suspend_security import BaseSuspendSecurityUid class IrModelAccess(models.Model): _inherit = 'ir.model.access' - @tools.ormcache_context('uid', 'model', 'mode', 'raise_exception', + @api.model + @tools.ormcache_context('self._uid', 'model', 'mode', 'raise_exception', keys=('lang',)) - def check(self, cr, uid, model, mode='read', raise_exception=True, - context=None): - if isinstance(uid, BaseSuspendSecurityUid): + def check(self, model, mode='read', raise_exception=True): + if isinstance(self.env.uid, BaseSuspendSecurityUid): return True return super(IrModelAccess, self).check( - cr, uid, model, mode=mode, raise_exception=raise_exception, - context=context) + model, mode=mode, raise_exception=raise_exception) diff --git a/base_suspend_security/models/ir_rule.py b/base_suspend_security/models/ir_rule.py index 86c0ff2d8..21a121ec1 100644 --- a/base_suspend_security/models/ir_rule.py +++ b/base_suspend_security/models/ir_rule.py @@ -17,8 +17,8 @@ # along with this program. If not, see . # ############################################################################## -from openerp import models, api -from ..base_suspend_security import BaseSuspendSecurityUid, SUSPEND_METHOD +from odoo import models, api +from ..base_suspend_security import BaseSuspendSecurityUid class IrRule(models.Model): @@ -29,10 +29,3 @@ class IrRule(models.Model): if isinstance(self.env.uid, BaseSuspendSecurityUid): return [], [], ['"%s"' % self.pool[model_name]._table] return super(IrRule, self).domain_get(model_name, mode=mode) - - def _register_hook(self, cr): - if not hasattr(models.BaseModel, SUSPEND_METHOD): - setattr(models.BaseModel, SUSPEND_METHOD, - lambda self: self.sudo( - user=BaseSuspendSecurityUid(self.env.uid))) - return super(IrRule, self)._register_hook(cr) diff --git a/base_suspend_security/models/res_users.py b/base_suspend_security/models/res_users.py index be402570a..a5e3b2426 100644 --- a/base_suspend_security/models/res_users.py +++ b/base_suspend_security/models/res_users.py @@ -17,7 +17,7 @@ # along with this program. If not, see . # ############################################################################## -from openerp import models +from odoo import models from ..base_suspend_security import BaseSuspendSecurityUid @@ -25,12 +25,11 @@ class ResUsers(models.Model): _inherit = 'res.users' @classmethod - def _browse(cls, env, ids): + def _browse(cls, ids, env, prefetch=None): """be sure we browse ints, ids laread is normalized""" return super(ResUsers, cls)._browse( - env, [ i if not isinstance(i, BaseSuspendSecurityUid) else super(BaseSuspendSecurityUid, i).__int__() for i in ids - ]) + ], env, prefetch=prefetch) diff --git a/base_suspend_security/tests/test_base_suspend_security.py b/base_suspend_security/tests/test_base_suspend_security.py index 7621c052a..8e1bb5a6e 100644 --- a/base_suspend_security/tests/test_base_suspend_security.py +++ b/base_suspend_security/tests/test_base_suspend_security.py @@ -17,14 +17,12 @@ # along with this program. If not, see . # ############################################################################## -from openerp import exceptions -from openerp.tests.common import TransactionCase +from odoo import exceptions +from odoo.tests.common import TransactionCase class TestBaseSuspendSecurity(TransactionCase): def test_base_suspend_security(self): - # tests are called before register_hook - self.env['ir.rule']._register_hook() user_id = self.env.ref('base.user_demo').id other_company = self.env['res.company'].create({ 'name': 'other company', diff --git a/setup/base_suspend_security/odoo/__init__.py b/setup/base_suspend_security/odoo/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/base_suspend_security/odoo/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/base_suspend_security/odoo/addons/__init__.py b/setup/base_suspend_security/odoo/addons/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/base_suspend_security/odoo/addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/base_suspend_security/odoo/addons/base_suspend_security b/setup/base_suspend_security/odoo/addons/base_suspend_security new file mode 120000 index 000000000..5b117c634 --- /dev/null +++ b/setup/base_suspend_security/odoo/addons/base_suspend_security @@ -0,0 +1 @@ +../../../../base_suspend_security \ No newline at end of file diff --git a/setup/base_suspend_security/setup.py b/setup/base_suspend_security/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/base_suspend_security/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)