From ab10ed0c62948890743cc2beb4146aae4f7a3498 Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Wed, 9 Aug 2023 12:17:57 +0000 Subject: [PATCH] [FIX] web_editor: images converted to public attachments Before this commit, since [1], when an image was pasted or dropped, it was converted to a public attachment on save. This was an oversight, and this commit fixes it by creating such attachment as a private one instead, much like when uploading an image via the "/image" command. Attachments created via the website remain public. [1]: https://github.com/odoo/odoo/pull/128452/commits/1b3877191ee9d97d2c50ccacb41461827b42fd56 closes odoo/odoo#131975 X-original-commit: d939fc83ab645ebced6859e04269fb65bf47f323 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/wysiwyg/wysiwyg.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index c2a7d8f1ae3..5fb93b53c54 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1153,7 +1153,7 @@ export class Wysiwyg extends Component { */ savePendingImages($editable = this.$editable) { const defs = Array.from($editable).map(async (editableEl) => { - const {oeModel: resModel, oeId: resId} = editableEl.dataset; + const {res_model: resModel, res_id: resId} = this.options.recordInfo; // When saving a webp, o_b64_image_to_save is turned into // o_modified_image_to_save by _saveB64Image to request the saving // of the pre-converted webp resizes and all the equivalent jpgs. @@ -2926,6 +2926,8 @@ export class Wysiwyg extends Component { name: el.dataset.fileName || '', data: el.getAttribute('src').split(',')[1], is_image: true, + res_model: resModel, + res_id: resId, }, ); if (attachment.mimetype === 'image/webp') { @@ -2935,7 +2937,19 @@ export class Wysiwyg extends Component { el.dataset.fileName = attachment.name; this._saveModifiedImage(el, resModel, resId); } else { - el.setAttribute('src', attachment.image_src); + let src = attachment.image_src; + if (!attachment.public) { + let accessToken = attachment.access_token; + if (!accessToken) { + [accessToken] = await this.orm.call( + 'ir.attachment', + 'generate_access_token', + [attachment.id], + ); + } + src += `?access_token=${encodeURIComponent(accessToken)}`; + } + el.setAttribute('src', src); } el.classList.remove('o_b64_image_to_save'); }