From 834e3f8f9b74da35820fd728006a95c7b7c8dc4f Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Wed, 6 Jan 2021 09:30:13 +0000 Subject: [PATCH] [IMP] base, *: remove read_template and review colorpicker template *: web_editor, website In stable versions, [1] was made as a fix to allow access to read the colorpicker template for mass mailing users when they do not have the read access right on ir.ui.view records. This commit, for master, remove the need of using the confusing read_template method by using render_public_asset instead (thus turning the read into a render, which is the same for our colorpicker but might be a change for potential custo). At the same time, this allows to remove the read_template public method entirely. Related to task-2412544 [1]: 8af75e00bdcda3d5ff4facd2f5f146e1d6bf79e4 closes odoo/odoo#64100 Related: odoo/enterprise#15580 Signed-off-by: Quentin Smetz (qsm) --- .../src/js/wysiwyg/widgets/color_palette.js | 16 +++--- addons/web_editor/static/tests/test_utils.js | 51 +++++++++---------- addons/website/models/ir_ui_view.py | 7 --- odoo/addons/base/models/ir_ui_view.py | 9 ---- 4 files changed, 31 insertions(+), 52 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/color_palette.js b/addons/web_editor/static/src/js/wysiwyg/widgets/color_palette.js index 25e8dfa2835..b55d8aed6e0 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/color_palette.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/color_palette.js @@ -11,6 +11,8 @@ const weUtils = require('web_editor.utils'); const qweb = core.qweb; +let colorpickerArch; + const ColorPaletteWidget = Widget.extend({ // ! for xmlDependencies, see loadDependencies function template: 'web_editor.snippet.option.colorpicker', @@ -67,9 +69,7 @@ const ColorPaletteWidget = Widget.extend({ const res = this._super.apply(this, arguments); const $colorSection = this.$('.o_colorpicker_sections[data-color-tab="theme-colors"]'); - const $clpicker = qweb.has_template('web_editor.colorpicker') - ? $(qweb.render('web_editor.colorpicker')) - : $(`
`); + const $clpicker = $(colorpickerArch || `
`); $clpicker.find('button').addClass('o_we_color_btn'); $clpicker.appendTo($colorSection); @@ -371,14 +371,12 @@ ColorPaletteWidget.loadDependencies = async function (rpcCapableObj) { // the default summernote ones. if (!session.is_website_user) { // We can call the colorPalette multiple times but only need 1 rpc - if (!colorpickerTemplateProm && !qweb.has_template('web_editor.colorpicker')) { + if (!colorpickerTemplateProm && !colorpickerArch) { colorpickerTemplateProm = rpcCapableObj._rpc({ model: 'ir.ui.view', - method: 'read_template', - args: ['web_editor.colorpicker'], - }).then(template => { - return qweb.add_template('' + template + ''); - }); + method: 'render_public_asset', + args: ['web_editor.colorpicker', {}], + }).then(arch => colorpickerArch = arch); } proms.push(colorpickerTemplateProm); } diff --git a/addons/web_editor/static/tests/test_utils.js b/addons/web_editor/static/tests/test_utils.js index 1aa4a79c573..cf2157495a8 100644 --- a/addons/web_editor/static/tests/test_utils.js +++ b/addons/web_editor/static/tests/test_utils.js @@ -9,27 +9,26 @@ var Wysiwyg = require('web_editor.wysiwyg'); var options = require('web_editor.snippets.options'); const COLOR_PICKER_TEMPLATE = ` - - -
-
-
-
-
- - `; + +
+
+
+
+
+ +`; const SNIPPETS_TEMPLATE = `

Add blocks

@@ -92,11 +91,11 @@ MockServer.include({ * @returns {Promise} */ async _performRpc(route, args) { - if (args.model === "ir.ui.view") { - if (args.method === 'read_template' && args.args[0] === "web_editor.colorpicker") { + if (args.model === "ir.ui.view" && args.method === 'render_public_asset') { + if (args.args[0] === "web_editor.colorpicker") { return COLOR_PICKER_TEMPLATE; } - if (args.method === 'render_public_asset' && args.args[0] === "web_editor.snippets") { + if (args.args[0] === "web_editor.snippets") { return SNIPPETS_TEMPLATE; } } @@ -192,12 +191,10 @@ function wysiwygData(data) { }, }, records: [], - read_template(args) { + render_template(args) { if (args[0] === 'web_editor.colorpicker') { return COLOR_PICKER_TEMPLATE; } - }, - render_template(args) { if (args[0] === 'web_editor.snippets') { return SNIPPETS_TEMPLATE; } diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index e51c6eff524..7f03985b13e 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -324,13 +324,6 @@ class View(models.Model): return view.id return super(View, self.sudo()).get_view_id(xml_id) - @api.model - def read_template(self, xml_id): - view = self._view_obj(self.get_view_id(xml_id)) - if view.visibility and view._handle_visibility(do_raise=False): - self = self.sudo() - return super(View, self).read_template(xml_id) - def _get_original_view(self): """Given a view, retrieve the original view it was COW'd from. The given view might already be the original one. In that case it will diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index ddf8f7ae9f0..d7f2aeaf8c3 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -1588,15 +1588,6 @@ actual arch. arch = etree.tostring(arch_tree, encoding='unicode') return arch - @api.model - def read_template(self, xml_id): - """ Return a template content based on external id - Read access on ir.ui.view required - """ - template_id = self.get_view_id(xml_id) - self.browse(template_id)._check_view_access() - return self._read_template(template_id) - @api.model def get_view_id(self, template): """ Return the view ID corresponding to ``template``, which may be a