[FIX] web_editor: upload CORS images by URL
- Install E-commerce app
- Go to Website > Shop, and open a product
- Click on edit on the upper right corner.
- Double click the product image to change it. A popup is shown.
- In the popup, click on Add URL and place this URL [1]
- Click Save. The image disappears!
- The issue was introduced here [2]
- As URL now starts with `/web/image/` which will be later used here [3]
- The condition to enter this line is `url_object.path.startswith('/web/image')`
- `item[field]` is used which equals to `attachment[datas]`
- But actually `datas` is empty as the image upload fails because of CORS
- `add_url` is called [4] saving attachment without `datas` but with type URL
- The commit solves the issue by fetching the remote data from the server
if the url is a remote redirection, which still happens when the image
data cannot be fetched by the client browser at upload time.
[1]: https://lowendbox.com/wp-content/uploads/2022/09/odoo_logo_1200.png
[2]: https://github.com/odoo/odoo/commit/943944dd249c15de870d6800d89e48d54a422e5a#diff-0897c80484208197b0aff67f2b06509e864c3976de1589e3cebad2788eef008fR49
[3]: https://github.com/odoo/odoo/blob/f72968561acec164697a7a9ee0965ec304854dd5/addons/web_editor/models/ir_qweb_fields.py#L473
[4]: https://github.com/odoo/odoo/blob/f72968561acec164697a7a9ee0965ec304854dd5/addons/web_editor/controllers/main.py#L268
opw-3746245
closes odoo/odoo#160085
Signed-off-by: Benoit Socias (bso) <bso@odoo.com>
This commit is contained in:
@@ -447,6 +447,7 @@ class Image(models.AbstractModel):
|
||||
_inherit = 'ir.qweb.field.image'
|
||||
|
||||
local_url_re = re.compile(r'^/(?P<module>[^]]+)/static/(?P<rest>.+)$')
|
||||
redirect_url_re = re.compile(r'\/web\/image\/\d+-redirect\/')
|
||||
|
||||
@api.model
|
||||
def from_html(self, model, field, element):
|
||||
@@ -470,6 +471,8 @@ class Image(models.AbstractModel):
|
||||
oid = query.get('id', fragments[4])
|
||||
field = query.get('field', fragments[5])
|
||||
item = self.env[model].browse(int(oid))
|
||||
if self.redirect_url_re.match(url_object.path):
|
||||
return self.load_remote_url(item.url)
|
||||
return item[field]
|
||||
|
||||
if self.local_url_re.match(url_object.path):
|
||||
|
||||
Reference in New Issue
Block a user