From fbf5441fd6e37777c6404d07bf4113614c4f019c Mon Sep 17 00:00:00 2001 From: Guillaume-gdi Date: Thu, 7 Dec 2023 13:25:12 +0100 Subject: [PATCH] [FIX] website: prevent having multiple logos for a website Before this commit, when a user was uploading a logo for a website via the website configurator, the logo was added as an attachment but the potential previous logo was not deleted. This commit fixes this by deleting the previous logo when a new one is uploaded. Steps to reproduce the issue: - Create a new website - Fill the configurator until you can upload a logo - Upload a logo, then upload another one - Finish the configurator - Edit a page of the website - Change an image => You can see the first logo you uploaded in the list of images. task-3609329 Part-of: odoo/odoo#145047 --- .../client_actions/configurator/configurator.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/addons/website/static/src/client_actions/configurator/configurator.js b/addons/website/static/src/client_actions/configurator/configurator.js index 3360347f75f..70532286b73 100644 --- a/addons/website/static/src/client_actions/configurator/configurator.js +++ b/addons/website/static/src/client_actions/configurator/configurator.js @@ -238,6 +238,7 @@ class PaletteSelectionScreen extends Component { async changeLogo() { const logoSelectInput = this.logoInputRef.el; if (logoSelectInput.files.length === 1) { + const previousLogoAttachmentId = this.state.logoAttachmentId; const file = logoSelectInput.files[0]; const data = await getDataURLFromFile(file); const attachment = await this.rpc('/web_editor/attachment/add_data', { @@ -246,6 +247,9 @@ class PaletteSelectionScreen extends Component { 'is_image': true, }); if (!attachment.error) { + if (previousLogoAttachmentId) { + await this._removeAttachments([previousLogoAttachmentId]); + } this.state.changeLogo(data, attachment.id); this.updatePalettes(); } else { @@ -277,6 +281,16 @@ class PaletteSelectionScreen extends Component { this.state.selectPalette(paletteName); this.props.navigate(ROUTES.featuresSelectionScreen); } + + /** + * Removes the attachments from the DB. + * + * @private + * @param {Array} ids the attachment ids to remove + */ + async _removeAttachments(ids) { + this.rpc("/web_editor/attachment/remove", { ids: ids }); + } } Object.assign(PaletteSelectionScreen, {