mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[MIG] base_suspend_security to 10.0 (#586)
This commit is contained in:
committed by
Frédéric Garbely
parent
a34ecbfb0e
commit
c36c7e4f0e
@@ -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
|
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**>`_.
|
|
||||||
|
|
||||||
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
|
||||||
----------
|
----------
|
||||||
|
|||||||
@@ -19,20 +19,12 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
{
|
{
|
||||||
"name": "Suspend security",
|
"name": "Suspend security",
|
||||||
"version": "9.0.1.0.0",
|
"version": "10.0.1.0.0",
|
||||||
"author": "Therp BV",
|
"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': [],
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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'
|
|
||||||
|
|||||||
@@ -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
Normal file
15
base_suspend_security/models/base.py
Normal file
@@ -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))
|
||||||
@@ -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,
|
def check(self, model, mode='read', raise_exception=True):
|
||||||
context=None):
|
if isinstance(self.env.uid, BaseSuspendSecurityUid):
|
||||||
if isinstance(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,
|
model, mode=mode, raise_exception=raise_exception)
|
||||||
context=context)
|
|
||||||
|
|||||||
@@ -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 odoo import models, api
|
||||||
from ..base_suspend_security import BaseSuspendSecurityUid, SUSPEND_METHOD
|
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)
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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 odoo import exceptions
|
||||||
from openerp.tests.common import TransactionCase
|
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',
|
||||||
|
|||||||
Reference in New Issue
Block a user