Browse Source

[MIG] base_suspend_security to 10.0 (#586)

pull/596/head
Adrien Peiffer (ACSONE) 8 years ago
committed by Pedro M. Baeza
parent
commit
3c29d07893
  1. 4
      base_suspend_security/README.rst
  2. 12
      base_suspend_security/__manifest__.py
  3. 3
      base_suspend_security/base_suspend_security.py
  4. 1
      base_suspend_security/models/__init__.py
  5. 15
      base_suspend_security/models/base.py
  6. 13
      base_suspend_security/models/ir_model_access.py
  7. 11
      base_suspend_security/models/ir_rule.py
  8. 7
      base_suspend_security/models/res_users.py
  9. 6
      base_suspend_security/tests/test_base_suspend_security.py
  10. 1
      setup/base_suspend_security/odoo/__init__.py
  11. 1
      setup/base_suspend_security/odoo/addons/__init__.py
  12. 1
      setup/base_suspend_security/odoo/addons/base_suspend_security
  13. 6
      setup/base_suspend_security/setup.py

4
base_suspend_security/README.rst

@ -29,8 +29,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported. 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 <https://github.com/OCA/server-tools/issues/new?body=module:%20base_suspend_security%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback.
Credits Credits
======= =======
@ -39,6 +38,7 @@ Contributors
------------ ------------
* Holger Brunn <hbrunn@therp.nl> * Holger Brunn <hbrunn@therp.nl>
* Laurent Mignon <laurent.mignon@acsone.eu>
Maintainer Maintainer
---------- ----------

12
base_suspend_security/__manifest__.py

@ -19,20 +19,12 @@
############################################################################## ##############################################################################
{ {
"name": "Suspend security", "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", "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': False,
"application": False,
"external_dependencies": {
'python': [],
},
} }

3
base_suspend_security/base_suspend_security.py

@ -30,6 +30,3 @@ class BaseSuspendSecurityUid(int):
def __iter__(self): def __iter__(self):
yield super(BaseSuspendSecurityUid, self).__int__() yield super(BaseSuspendSecurityUid, self).__int__()
SUSPEND_METHOD = 'suspend_security'

1
base_suspend_security/models/__init__.py

@ -20,3 +20,4 @@
from . import ir_rule from . import ir_rule
from . import ir_model_access from . import ir_model_access
from . import res_users from . import res_users
from . import base

15
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))

13
base_suspend_security/models/ir_model_access.py

@ -17,19 +17,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from openerp import models, tools
from odoo import models, api, tools
from ..base_suspend_security import BaseSuspendSecurityUid from ..base_suspend_security import BaseSuspendSecurityUid
class IrModelAccess(models.Model): class IrModelAccess(models.Model):
_inherit = 'ir.model.access' _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',)) 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 True
return super(IrModelAccess, self).check( return super(IrModelAccess, self).check(
cr, uid, model, mode=mode, raise_exception=raise_exception,
context=context)
model, mode=mode, raise_exception=raise_exception)

11
base_suspend_security/models/ir_rule.py

@ -17,8 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
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): class IrRule(models.Model):
@ -29,10 +29,3 @@ class IrRule(models.Model):
if isinstance(self.env.uid, BaseSuspendSecurityUid): if isinstance(self.env.uid, BaseSuspendSecurityUid):
return [], [], ['"%s"' % self.pool[model_name]._table] return [], [], ['"%s"' % self.pool[model_name]._table]
return super(IrRule, self).domain_get(model_name, mode=mode) 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)

7
base_suspend_security/models/res_users.py

@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from openerp import models
from odoo import models
from ..base_suspend_security import BaseSuspendSecurityUid from ..base_suspend_security import BaseSuspendSecurityUid
@ -25,12 +25,11 @@ class ResUsers(models.Model):
_inherit = 'res.users' _inherit = 'res.users'
@classmethod @classmethod
def _browse(cls, env, ids):
def _browse(cls, ids, env, prefetch=None):
"""be sure we browse ints, ids laread is normalized""" """be sure we browse ints, ids laread is normalized"""
return super(ResUsers, cls)._browse( return super(ResUsers, cls)._browse(
env,
[ [
i if not isinstance(i, BaseSuspendSecurityUid) i if not isinstance(i, BaseSuspendSecurityUid)
else super(BaseSuspendSecurityUid, i).__int__() else super(BaseSuspendSecurityUid, i).__int__()
for i in ids for i in ids
])
], env, prefetch=prefetch)

6
base_suspend_security/tests/test_base_suspend_security.py

@ -17,14 +17,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from openerp import exceptions
from openerp.tests.common import TransactionCase
from odoo import exceptions
from odoo.tests.common import TransactionCase
class TestBaseSuspendSecurity(TransactionCase): class TestBaseSuspendSecurity(TransactionCase):
def test_base_suspend_security(self): 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 user_id = self.env.ref('base.user_demo').id
other_company = self.env['res.company'].create({ other_company = self.env['res.company'].create({
'name': 'other company', 'name': 'other company',

1
setup/base_suspend_security/odoo/__init__.py

@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)

1
setup/base_suspend_security/odoo/addons/__init__.py

@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)

1
setup/base_suspend_security/odoo/addons/base_suspend_security

@ -0,0 +1 @@
../../../../base_suspend_security

6
setup/base_suspend_security/setup.py

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading…
Cancel
Save