Skip to content
Snippets Groups Projects
Commit b8ce93e4 authored by Jeremy Kersten's avatar Jeremy Kersten Committed by Olivier Dony
Browse files

[FIX] ir_http: support redirect pitcure for theme

Missing / wrong indented code during rewrite of binary controller:
https://github.com/odoo/odoo/commit/7d85ab1#diff-1407a8ce197a04eefaefa26c127a4418L343-L348



In case you have:

    <record id="s_cover_default_image" model="theme.ir.attachment">
        <field name="key">website.s_cover_default_image</field>
        <field name="url">/web/image/theme_treehouse.bg_img_15</field>
    </record>

theme_treehouse.bg_img_15 will be not found in /web addons.
So we need a 301 redirect too.

opw-live

How to reproduce:
odoo.com/trial > Website > Install theme Clean
Drop first snippet > background is 404

closes odoo/odoo#40483

Signed-off-by: default avatarOlivier Dony (odo) <odo@openerp.com>
parent 4d35059a
Branches
Tags
No related merge requests found
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_attachment
from . import test_base_url
from . import test_converter
from . import test_crawl
......
import odoo.tests
from odoo.tests.common import HOST, PORT
@odoo.tests.common.tagged('post_install', '-at_install')
class TestWebsiteAttachment(odoo.tests.HttpCase):
def test_01_type_url_301_image(self):
IMD = self.env['ir.model.data']
IrAttachment = self.env['ir.attachment']
img1 = IrAttachment.create({
'public': True,
'name': 's_banner_default_image.jpg',
'type': 'url',
'url': '/website/static/src/img/snippets_demo/s_banner.jpg'
})
img2 = IrAttachment.create({
'public': True,
'name': 's_banner_default_image.jpg',
'type': 'url',
'url': '/web/image/test.an_image_url'
})
IMD.create({
'name': 'an_image_url',
'module': 'test',
'model': img1._name,
'res_id': img1.id,
})
IMD.create({
'name': 'an_image_redirect_301',
'module': 'test',
'model': img2._name,
'res_id': img2.id,
})
req = self.url_open('/web/image/test.an_image_url')
self.assertEquals(req.status_code, 200)
base = "http://%s:%s" % (HOST, PORT)
req = self.opener.get(base + '/web/image/test.an_image_redirect_301', allow_redirects=False)
self.assertEquals(req.status_code, 301)
self.assertEquals(req.headers['Location'], base + '/web/image/test.an_image_url')
req = self.opener.get(base + '/web/image/test.an_image_redirect_301', allow_redirects=True)
self.assertEquals(req.status_code, 200)
......@@ -346,7 +346,8 @@ class IrHttp(models.AbstractModel):
filename = os.path.basename(module_resource_path)
mimetype = guess_mimetype(base64.b64decode(content), default=default_mimetype)
filehash = '"%s"' % hashlib.md5(pycompat.to_text(content).encode('utf-8')).hexdigest()
else:
if not content:
status = 301
content = record.url
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment