[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) <qsm@odoo.com>
This commit is contained in:
qsm-odoo
2021-01-06 09:30:13 +00:00
parent 27a2701ff0
commit 834e3f8f9b
4 changed files with 31 additions and 52 deletions
@@ -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'))
: $(`<colorpicker><div class="o_colorpicker_section" data-name="common"></div></colorpicker>`);
const $clpicker = $(colorpickerArch || `<colorpicker><div class="o_colorpicker_section" data-name="common"></div></colorpicker>`);
$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('<templates>' + template + '</templates>');
});
method: 'render_public_asset',
args: ['web_editor.colorpicker', {}],
}).then(arch => colorpickerArch = arch);
}
proms.push(colorpickerTemplateProm);
}
+24 -27
View File
@@ -9,27 +9,26 @@ var Wysiwyg = require('web_editor.wysiwyg');
var options = require('web_editor.snippets.options');
const COLOR_PICKER_TEMPLATE = `
<t t-name="web_editor.colorpicker">
<colorpicker>
<div class="o_colorpicker_section" data-name="theme" data-display="Theme Colors" data-icon-class="fa fa-flask">
<button data-color="o-color-1"/>
<button data-color="o-color-2"/>
<button data-color="o-color-3"/>
<button data-color="o-color-4"/>
<button data-color="o-color-5"/>
</div>
<div class="o_colorpicker_section" data-name="transparent_grayscale" data-display="Transparent Colors" data-icon-class="fa fa-eye-slash">
<button class="o_btn_transparent"/>
<button data-color="black-25"/>
<button data-color="black-50"/>
<button data-color="black-75"/>
<button data-color="white-25"/>
<button data-color="white-50"/>
<button data-color="white-75"/>
</div>
<div class="o_colorpicker_section" data-name="common" data-display="Common Colors" data-icon-class="fa fa-paint-brush"/>
</colorpicker>
</t>`;
<colorpicker>
<div class="o_colorpicker_section" data-name="theme" data-display="Theme Colors" data-icon-class="fa fa-flask">
<button data-color="o-color-1"/>
<button data-color="o-color-2"/>
<button data-color="o-color-3"/>
<button data-color="o-color-4"/>
<button data-color="o-color-5"/>
</div>
<div class="o_colorpicker_section" data-name="transparent_grayscale" data-display="Transparent Colors" data-icon-class="fa fa-eye-slash">
<button class="o_btn_transparent"/>
<button data-color="black-25"/>
<button data-color="black-50"/>
<button data-color="black-75"/>
<button data-color="white-25"/>
<button data-color="white-50"/>
<button data-color="white-75"/>
</div>
<div class="o_colorpicker_section" data-name="common" data-display="Common Colors" data-icon-class="fa fa-paint-brush"/>
</colorpicker>
`;
const SNIPPETS_TEMPLATE = `
<h2 id="snippets_menu">Add blocks</h2>
<div id="o_scroll">
@@ -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;
}
-7
View File
@@ -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
-9
View File
@@ -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