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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user