From 81bade4035d7e01a2a64dd1b4f0c9e3313643d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 24 Sep 2020 23:00:52 +0200 Subject: [PATCH] Allow sharing view searches We add a rule to give read access to all view searches without a user. We manage the delete access on client side thanks to the _delete attribute. If the user does not have the delete right, the bookmark star is disabled. issue9515 review323751002 --- CHANGELOG | 1 + trytond/ir/ui/view.py | 28 ++++++++++++++++++---------- trytond/res/ir.xml | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e4dbc52522..27ef81acfe 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Allow sharing view searches * Allow overriding digits in Lang.currency and Report.format_currency * Add record name in report filename * Add deletable and writable state from ir.rule to read diff --git a/trytond/ir/ui/view.py b/trytond/ir/ui/view.py index 9d1e1448c6..176ac6bf49 100644 --- a/trytond/ir/ui/view.py +++ b/trytond/ir/ui/view.py @@ -383,8 +383,7 @@ class ViewSearch(ModelSQL, ModelView): name = fields.Char('Name', required=True) model = fields.Char('Model', required=True) domain = fields.Char('Domain', help="The PYSON domain.") - user = fields.Many2One('res.user', 'User', required=True, - ondelete='CASCADE') + user = fields.Many2One('res.user', 'User', ondelete='CASCADE') @classmethod def __setup__(cls): @@ -393,20 +392,29 @@ class ViewSearch(ModelSQL, ModelView): 'get_search': RPC(), }) + @classmethod + def __register__(cls, module): + super().__register__(module) + table_h = cls.__table_handler__(module) + + # Migration from 5.6: remove user required + table_h.not_null_action('user', 'remove') + @staticmethod def default_user(): return Transaction().user @classmethod - def get_search(cls, user_id=None): - if user_id is None: - user_id = Transaction().user + def get_search(cls): decoder = PYSONDecoder() - searches = cls.search([ - ('user', '=', user_id), - ], order=[('model', 'ASC'), ('name', 'ASC')]) + searches = cls.search_read( + [], order=[('model', 'ASC'), ('name', 'ASC')], + fields_names=['id', 'name', 'model', 'domain', '_delete']) result = {} for search in searches: - result.setdefault(search.model, []).append( - (search.id, search.name, decoder.decode(search.domain))) + result.setdefault(search['model'], []).append(( + search['id'], + search['name'], + decoder.decode(search['domain']), + search['_delete'])) return result diff --git a/trytond/res/ir.xml b/trytond/res/ir.xml index 98c630cf5f..6b80fe87bc 100644 --- a/trytond/res/ir.xml +++ b/trytond/res/ir.xml @@ -836,6 +836,24 @@ this repository contains the full copyright notices and license terms. --> + + Common view search + + + + + + + + + + + + + Any view search