From eded0294ab1c5dfc6eb268f84d53ada9ba775352 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten <jke@odoo.com> Date: Tue, 1 Oct 2019 14:48:24 +0000 Subject: [PATCH] [FIX] base, website: fix routing redirect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Redirect_type was renamed from 3xx to redirect_3xx, but name is used as http status code. It is better a redirect(301) instead of redirect(redirect_301) Re-add the bind_to_environ, it was removed because it seems not useful, but once you are behind a proxy, werkzeug need the environ to find the correct hostname and more ... Transformed relative url into absolute by werkzeug was wrong. closes odoo/odoo#37733 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com> --- addons/website/models/ir_http.py | 8 ++++---- addons/website/models/website_rewrite.py | 12 ++++++------ odoo/addons/base/models/ir_http.py | 6 +----- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index 2ad541d3e336..6d421357c90c 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -90,7 +90,7 @@ class Http(models.AbstractModel): def _generate_routing_rules(cls, modules, converters): website_id = request.website_routing logger.debug("_generate_routing_rules for website: %s", website_id) - domain = [('redirect_type', 'in', ('rewrite', 'not_found')), '|', ('website_id', '=', False), ('website_id', '=', website_id)] + domain = [('redirect_type', 'in', ('308', '404')), '|', ('website_id', '=', False), ('website_id', '=', website_id)] rewrites = dict([(x.url_from, x) for x in request.env['website.rewrite'].sudo().search(domain)]) cls._rewrite_len[website_id] = len(rewrites) @@ -100,7 +100,7 @@ class Http(models.AbstractModel): if url in rewrites: rewrite = rewrites[url] url_to = rewrite.url_to - if rewrite.redirect_type == 'rewrite': + if rewrite.redirect_type == '308': logger.debug('Add rule %s for %s' % (url_to, website_id)) yield url_to, endpoint, routing # yield new url @@ -109,7 +109,7 @@ class Http(models.AbstractModel): _slug_matching = partial(cls._slug_matching, endpoint=endpoint) routing['redirect_to'] = _slug_matching yield url, endpoint, routing # yield original redirected to new url - elif rewrite.redirect_type == 'not_found': + elif rewrite.redirect_type == '404': logger.debug('Return 404 for %s for website %s' % (url, website_id)) continue else: @@ -245,7 +245,7 @@ class Http(models.AbstractModel): def _serve_redirect(cls): req_page = request.httprequest.path domain = [ - ('redirect_type', 'in', ('redirect_301', 'redirect_302')), + ('redirect_type', 'in', ('301', '302')), ('url_from', '=', req_page) ] domain += request.website.website_domain() diff --git a/addons/website/models/website_rewrite.py b/addons/website/models/website_rewrite.py index 77acdb8c1200..5c3096cb5b37 100644 --- a/addons/website/models/website_rewrite.py +++ b/addons/website/models/website_rewrite.py @@ -54,11 +54,11 @@ class WebsiteRewrite(models.Model): route_id = fields.Many2one('website.route') url_to = fields.Char("URL to") redirect_type = fields.Selection([ - ('not_found', '404 Not Found'), - ('redirect_301', '301 Moved permanently'), - ('redirect_302', '302 Moved temporarily'), - ('rewrite', '308 Redirect / Rewrite'), - ], string='Action', default="redirect_302", + ('404', '404 Not Found'), + ('301', '301 Moved permanently'), + ('302', '302 Moved temporarily'), + ('308', '308 Redirect / Rewrite'), + ], string='Action', default="302", help='''Type of redirect/Rewrite:\n 301 Moved permanently: The browser will keep in cache the new url. 302 Moved temporarily: The browser will not keep in cache the new url and ask again the next time the new url. @@ -76,7 +76,7 @@ class WebsiteRewrite(models.Model): def name_get(self): result = [] for rewrite in self: - name = rewrite.redirect_type + ' - ' + rewrite.name + name = "%s - %s" % (rewrite.redirect_type, rewrite.name) result.append((rewrite.id, name)) return result diff --git a/odoo/addons/base/models/ir_http.py b/odoo/addons/base/models/ir_http.py index f2c87db5fa4f..780c02908259 100644 --- a/odoo/addons/base/models/ir_http.py +++ b/odoo/addons/base/models/ir_http.py @@ -88,11 +88,7 @@ class IrHttp(models.AbstractModel): @classmethod def _match(cls, path_info, key=None): - return cls.routing_map(key=key).bind('').match( - return_rule=True, - method=request.httprequest.method, - path_info=path_info - ) + return cls.routing_map().bind_to_environ(request.httprequest.environ).match(path_info=path_info, return_rule=True) @classmethod def _auth_method_user(cls): -- GitLab