[FIX] web_editor: filter ACE views that do not belong to page

When the ACE editor was introduced in [1], it relied on the already
existing `_views_get` to obtain the list of views that could be edited.

When the `mode` of `ir.ui.view` was introduced in [2], no mechanism was
introduced in `_views_get` to avoid fetching primary views that have
nothing in common with the current view.

This commit adds a parameter to `_views_get` to request the
exclusion of unrelated primary views.
Since even before it appeared in [3], `_views_get` relies on the
following approach:
- consider the top-most parent of the `t-call`ed views
- consider the views that inherit it
I.e.: reach each node of each view hierarchy tree by starting from its
root.

Because this starts from the top-most parent, simply preventing the
call to each primary child view is wrong, because any child on the
parent path must be considered - be it primary or not.
We therefore introduced a `skipped` list that keeps track of those
"later to be processed" views - so that the filtering of primary
children does not remove them.

[1]: https://github.com/odoo/odoo/commit/7c45e5976e6caf3d7b9eb508f728062704232261
[2]: https://github.com/odoo/odoo/commit/434be479f97a32987d0817bf329183fc2bbe3bf5
[3]: https://github.com/odoo/odoo/commit/bff6e04e9536d7b80916987eb123de98b1b689b1

task-2898555

closes odoo/odoo#100625

X-original-commit: 34ac97ce96019573a6a0af968d9c90b9d0d89ae8
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
Benoit Socias
2022-09-21 02:26:01 +02:00
parent 71b62dd148
commit 37d8810235
2 changed files with 7 additions and 2 deletions
+1 -1
View File
@@ -380,7 +380,7 @@ class Web_Editor(http.Controller):
dict: views, scss, js
"""
# Related views must be fetched if the user wants the views and/or the style
views = request.env["ir.ui.view"].get_related_views(key, bundles=bundles)
views = request.env["ir.ui.view"].with_context(no_primary_children=True, __views_get_original_hierarchy=[]).get_related_views(key, bundles=bundles)
views = views.read(['name', 'id', 'key', 'xml_id', 'arch', 'active', 'inherit_id'])
scss_files_data_by_bundle = []
+6 -1
View File
@@ -207,6 +207,9 @@ class IrUiView(models.Model):
@api.model
def _view_get_inherited_children(self, view):
if self._context.get('no_primary_children', False):
original_hierarchy = self._context.get('__views_get_original_hierarchy', [])
return view.inherit_children_ids.filtered(lambda extension: extension.mode != 'primary' or extension.id in original_hierarchy)
return view.inherit_children_ids
@api.model
@@ -225,7 +228,7 @@ class IrUiView(models.Model):
@api.model
def _views_get(self, view_id, get_children=True, bundles=False, root=True, visited=None):
""" For a given view ``view_id``, should return:
* the view itself
* the view itself (starting from its top most parent)
* all views inheriting from it, enabled or not
- but not the optional children of a non-enabled child
* all views called from it (via t-call)
@@ -239,7 +242,9 @@ class IrUiView(models.Model):
if visited is None:
visited = []
original_hierarchy = self._context.get('__views_get_original_hierarchy', [])
while root and view.inherit_id:
original_hierarchy.append(view.id)
view = view.inherit_id
views_to_return = view