Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base_suspend_security/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======
Expand All @@ -39,6 +38,7 @@ Contributors
------------

* Holger Brunn <hbrunn@therp.nl>
* Laurent Mignon <laurent.mignon@acsone.eu>

Maintainer
----------
Expand Down
12 changes: 2 additions & 10 deletions base_suspend_security/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [],
},
}
3 changes: 0 additions & 3 deletions base_suspend_security/base_suspend_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,3 @@ def __eq__(self, other):

def __iter__(self):
yield super(BaseSuspendSecurityUid, self).__int__()


SUSPEND_METHOD = 'suspend_security'
1 change: 1 addition & 0 deletions base_suspend_security/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
from . import ir_rule
from . import ir_model_access
from . import res_users
from . import base
15 changes: 15 additions & 0 deletions base_suspend_security/models/base.py
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 7 deletions base_suspend_security/models/ir_model_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hbrunn Why is the 'lang' value into the context a discriminant value to use as cache key?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmignon AFAIK, this is the same as the standard method definition

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adrienpeiffer it's a curiosity 😏

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adrienpeiffer that's a good reason, but not a good explanation ;-) - I believe https://github.com/OCA/OCB/blob/10.0/odoo/addons/base/ir/ir_model.py#L828-L831 phrases it sufficiently. Given it's still only the returns decorator which is propagated in inheritance (https://github.com/OCA/OCB/blob/10.0/odoo/api.py#L99, https://github.com/OCA/OCB/blob/10.0/odoo/api.py#L127, https://github.com/OCA/OCB/blob/10.0/odoo/api.py#L77), I think it's the right thing to do to copy the original, even though it doesn't have an effect currently save for being slightly less efficient in cases of switching language

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hbrunn Thank you for the explanation!

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)
11 changes: 2 additions & 9 deletions base_suspend_security/models/ir_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -29,10 +29,3 @@ def domain_get(self, model_name, mode='read'):
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)
7 changes: 3 additions & 4 deletions base_suspend_security/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@
# 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


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)
6 changes: 2 additions & 4 deletions base_suspend_security/tests/test_base_suspend_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions setup/base_suspend_security/odoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
1 change: 1 addition & 0 deletions setup/base_suspend_security/odoo/addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
6 changes: 6 additions & 0 deletions setup/base_suspend_security/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)