[IMP] http_routing: server_redirect in case of 404
It is a tradeoff since we will add extra requests in case of 404 to check if a redirect exists. But it will allow to redirect old unlinked record to a new record. Until now, if you delete e.g. a product instead to archive it, you have no way to redirect old url to the new product. closes odoo/odoo#125828 X-original-commit: 95dd21c4d69a06b56b908e138f7746ef3d131d82 Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
This commit is contained in:
@@ -640,7 +640,7 @@ class IrHttp(models.AbstractModel):
|
||||
code, values = cls._get_exception_code_values(exception)
|
||||
|
||||
request.cr.rollback()
|
||||
if code == 403:
|
||||
if code in (404, 403):
|
||||
try:
|
||||
response = cls._serve_fallback()
|
||||
if response:
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
import odoo
|
||||
from odoo.tests import HttpCase, tagged
|
||||
from odoo.tests.common import HOST
|
||||
from odoo.tools import mute_logger
|
||||
from odoo.addons.http_routing.models.ir_http import slug
|
||||
|
||||
@@ -210,3 +209,25 @@ class TestRedirect(HttpCase):
|
||||
self.assertTrue(
|
||||
r.url.endswith(url_rec2),
|
||||
"Unpublished record should redirect to published record set in redirect")
|
||||
|
||||
@mute_logger('odoo.http')
|
||||
def test_05_redirect_404_notfound_record(self):
|
||||
# 1. Accessing unexisting record: raise 404
|
||||
url_rec1 = '/test_website/200/unexisting-100000'
|
||||
r = self.url_open(url_rec1)
|
||||
self.assertEqual(r.status_code, 404)
|
||||
|
||||
# 2. Accessing unpublished record with redirect to a 404: expecting 404
|
||||
redirect = self.env['website.rewrite'].create({
|
||||
'name': 'Test 301 Redirect route unexisting record',
|
||||
'redirect_type': '301',
|
||||
'url_from': url_rec1,
|
||||
'url_to': '/get',
|
||||
})
|
||||
r = self.url_open(url_rec1, allow_redirects=False)
|
||||
self.assertEqual(r.status_code, 301)
|
||||
self.assertTrue(r.headers.get('Location', '').endswith(redirect.url_to))
|
||||
|
||||
r = self.url_open(url_rec1, allow_redirects=True)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertTrue(r.url.endswith(redirect.url_to))
|
||||
|
||||
Reference in New Issue
Block a user