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
This commit is contained in:
Cédric Krier
2020-09-24 23:00:52 +02:00
parent 05b53fa6c9
commit 81bade4035
3 changed files with 37 additions and 10 deletions
+1
View File
@@ -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
+18 -10
View File
@@ -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
+18
View File
@@ -836,6 +836,24 @@ this repository contains the full copyright notices and license terms. -->
<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"