changeset e5c0935843f6 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=e5c0935843f6
description:
        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
diffstat:

 CHANGELOG             |   1 +
 trytond/ir/ui/view.py |  28 ++++++++++++++++++----------
 trytond/res/ir.xml    |  18 ++++++++++++++++++
 3 files changed, 37 insertions(+), 10 deletions(-)

diffs (87 lines):

diff -r 9707d2e0f89d -r e5c0935843f6 CHANGELOG
--- a/CHANGELOG Thu Sep 24 22:49:09 2020 +0200
+++ b/CHANGELOG Thu Sep 24 23:00:52 2020 +0200
@@ -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 -r 9707d2e0f89d -r e5c0935843f6 trytond/ir/ui/view.py
--- a/trytond/ir/ui/view.py     Thu Sep 24 22:49:09 2020 +0200
+++ b/trytond/ir/ui/view.py     Thu Sep 24 23:00:52 2020 +0200
@@ -383,8 +383,7 @@
     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 @@
                 '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 -r 9707d2e0f89d -r e5c0935843f6 trytond/res/ir.xml
--- a/trytond/res/ir.xml        Thu Sep 24 22:49:09 2020 +0200
+++ b/trytond/res/ir.xml        Thu Sep 24 23:00:52 2020 +0200
@@ -836,6 +836,24 @@
             <field name="rule_group" ref="rule_group_view_search"/>
         </record>
 
+        <record model="ir.rule.group" id="rule_group_view_search_common">
+            <field name="name">Common view search</field>
+            <field name="model" search="[('model', '=', 
'ir.ui.view_search')]"/>
+            <field name="global_p" eval="False"/>
+            <field name="default_p" eval="True"/>
+            <field name="perm_read" eval="True"/>
+            <field name="perm_write" eval="False"/>
+            <field name="perm_create" eval="False"/>
+            <field name="perm_delete" eval="False"/>
+        </record>
+        <record model="ir.rule" id="rule_group_view_search_common1">
+            <field
+                name="domain"
+                eval="[('user', '=', None)]"
+                pyson="1"/>
+            <field name="rule_group" ref="rule_group_view_search_common"/>
+        </record>
+
         <record model="ir.rule.group" id="rule_group_view_search_admin">
             <field name="name">Any view search</field>
             <field name="model"

Reply via email to