[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
This commit is contained in:
@@ -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<number>} ids the attachment ids to remove
|
||||
*/
|
||||
async _removeAttachments(ids) {
|
||||
this.rpc("/web_editor/attachment/remove", { ids: ids });
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(PaletteSelectionScreen, {
|
||||
|
||||
Reference in New Issue
Block a user