[FIX] website: allow editor users to edit theme views

Currently, "Editor and Designer" can't edit the views which originate
from a theme (which are copies from the theme `theme.ir.ui.view`
records).

This error is caused by [1], which is preventing the `arch_updated`
field to be set to `True`, as this field is supposed to be set to `True`
only on manual user change, not during module update.

Indeed, restricted users don't have access to the themes records, making
the overide raising an error.

But there were actually no reason for this code to be executed outside
module operation.

Steps to reproduce:
- Create any view in a theme module.
  For example: create a custom footer view.
- As a "Editor and Designer" user, edit this view through the website
  builder.
- An access right error is raised.

[1]: https://github.com/odoo/odoo/commit/1eb7c577ecb31c2f0876b6dd76769e2b47802cb0

closes odoo/odoo#91255

X-original-commit: d2be8dc99eb99321be1172af447d5f2536c17364
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
Huy
2022-05-13 13:18:53 +02:00
committed by Huy Le
parent adc62e21e6
commit 6768e77f9b
+7
View File
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
import threading
from odoo import api, fields, models
from odoo.tools.translate import xml_translate
from odoo.modules.module import get_resource_from_path
@@ -342,6 +343,12 @@ class IrUiView(models.Model):
theme_template_id = fields.Many2one('theme.ir.ui.view', copy=False)
def write(self, vals):
# During a theme module update, theme views' copies receiving an arch
# update should not be considered as `arch_updated`, as this is not a
# user made change.
test_mode = getattr(threading.currentThread(), 'testing', False)
if not (test_mode or self.pool._init):
return super().write(vals)
no_arch_updated_views = other_views = self.env['ir.ui.view']
for record in self:
# Do not mark the view as user updated if original view arch is similar