Check record rule in button decorator

In order to relax internal control of record rules, they must be enforced on
the button entry point.
This is done by just reading the id of the records already stored.

issue7638
review349381002
This commit is contained in:
Cédric Krier
2021-02-14 15:47:00 +01:00
parent 964fc0a74b
commit dcdd1707b4
2 changed files with 7 additions and 1 deletions
+1 -1
View File
@@ -25,7 +25,6 @@ from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.cache import LRUDict, LRUDictTransaction, freeze
from trytond.rpc import RPC
from .modelview import ModelView
from .descriptors import dualmethod
__all__ = ['ModelStorage', 'EvalEnvironment']
@@ -121,6 +120,7 @@ class ModelStorage(Model):
@classmethod
def __setup__(cls):
from .modelview import ModelView
super(ModelStorage, cls).__setup__()
if issubclass(cls, ModelView):
cls.__rpc__.update({
+6
View File
@@ -719,6 +719,7 @@ class ModelView(Model):
def button(func):
@wraps(func)
def wrapper(cls, records, *args, **kwargs):
from .modelstorage import ModelStorage
pool = Pool()
ModelAccess = pool.get('ir.model.access')
Button = pool.get('ir.model.button')
@@ -732,6 +733,11 @@ class ModelView(Model):
if (transaction.user != 0) and check_access:
ModelAccess.check(cls.__name__, 'read')
if issubclass(cls, ModelStorage):
# Check record rule access
cls.read([r.id for r in records
if r.id is not None and r.id >= 0],
['id'])
groups = set(User.get_groups())
button_groups = Button.get_groups(cls.__name__,
func.__name__)