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
Holger Brunn
parent
1a5194c152
commit
e719bc627e
@@ -29,8 +29,7 @@ Bug Tracker
|
||||
|
||||
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.
|
||||
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
|
||||
=======
|
||||
@@ -39,6 +38,7 @@ Contributors
|
||||
------------
|
||||
|
||||
* Holger Brunn <hbrunn@therp.nl>
|
||||
* Laurent Mignon <laurent.mignon@acsone.eu>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
@@ -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': [],
|
||||
},
|
||||
}
|
||||
|
||||
@@ -30,6 +30,3 @@ class BaseSuspendSecurityUid(int):
|
||||
|
||||
def __iter__(self):
|
||||
yield super(BaseSuspendSecurityUid, self).__int__()
|
||||
|
||||
|
||||
SUSPEND_METHOD = 'suspend_security'
|
||||
|
||||
@@ -20,3 +20,4 @@
|
||||
from . import ir_rule
|
||||
from . import ir_model_access
|
||||
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/>.
|
||||
#
|
||||
##############################################################################
|
||||
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)
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
# 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):
|
||||
@@ -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)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# 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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -17,14 +17,12 @@
|
||||
# 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):
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user