summaryrefslogtreecommitdiff
path: root/addons/web_editor/models/ir_attachment.py
diff options
context:
space:
mode:
authorSamuel Degueldre <sad@odoo.com>2020-10-29 09:59:52 +0000
committerSamuel Degueldre <sad@odoo.com>2020-10-29 10:51:07 +0000
commitb0993370b6fcec1f966e4bf2994eee7f31da82d5 (patch)
tree3d1579424ce877d4b8c1ea573c783b71b54ba734 /addons/web_editor/models/ir_attachment.py
parentdaa5011e6cc26a756a9bc5b082b846baf735c5eb (diff)
[FIX] web_editor: fix issues related to loading image info
In order to allow modifying background images, we need information on the image, this is done by creating a placeholder img and calling the loadImageInfo function on it. However this function did not account for the case where an image had not src attribute, which causes an unnecessary rpc. Other problems could arise from this as an attachment that doesn't have the correct mimetype but has a matching src could be returned, causing its image_src field to be false, which we would then attempt to load as a valid image, causing crashes. This commit fixes that by not trying to load image infos when the src of an image is empty, only looking for attachments of the supported mimetypes, and also checking that we actually did receive an image_src before setting it as the original src of the image, which will prevent accidentally trying to load a falsy src as an actual image. closes odoo/odoo#60953 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/web_editor/models/ir_attachment.py')
-rw-r--r--addons/web_editor/models/ir_attachment.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/addons/web_editor/models/ir_attachment.py b/addons/web_editor/models/ir_attachment.py
index b9a1986727a..791f919498e 100644
--- a/addons/web_editor/models/ir_attachment.py
+++ b/addons/web_editor/models/ir_attachment.py
@@ -5,6 +5,7 @@ from werkzeug.urls import url_quote
from odoo import api, models, fields, tools
+SUPPORTED_IMAGE_MIMETYPES = ['image/gif', 'image/jpe', 'image/jpeg', 'image/jpg', 'image/gif', 'image/png', 'image/svg+xml']
class IrAttachment(models.Model):
@@ -27,7 +28,7 @@ class IrAttachment(models.Model):
def _compute_image_src(self):
for attachment in self:
# Only add a src for supported images
- if attachment.mimetype not in ['image/gif', 'image/jpe', 'image/jpeg', 'image/jpg', 'image/gif', 'image/png', 'image/svg+xml']:
+ if attachment.mimetype not in SUPPORTED_IMAGE_MIMETYPES:
attachment.image_src = False
continue