[FIX] http_routing: avoid extra redirect on logout in multi lang
context: Connected in /fr on a website with /en as default lang. Before this commit, /web/session/logout?redirect=/ / /fr_FR/ /fr_FR Now /web/session/logout?redirect=/ /fr_FR Part 1 -> to say that we are in multilang context and use url_lang. multilang=False to avoid /web/session -> /fr/web/session website=True to have url_lang done in the request.redirect. Part 2 -> to remove the trailing '/' that will be only useful for '/' closes odoo/odoo#76290 X-original-commit: ae35117ee1e019c3c0c333f291478825a5722706 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
from odoo.addons.web.controllers.main import WebClient, Home
|
||||
from odoo.addons.web.controllers.main import WebClient, Home, Session
|
||||
|
||||
|
||||
class Routing(Home):
|
||||
@@ -15,3 +15,10 @@ class Routing(Home):
|
||||
if mods:
|
||||
modules += mods
|
||||
return WebClient().translations(unique, mods=','.join(modules), lang=lang)
|
||||
|
||||
|
||||
class SessionWebsite(Session):
|
||||
|
||||
@http.route('/web/session/logout', type='http', auth="none", website=True, multilang=False, sitemap=False)
|
||||
def logout(self, redirect='/web'):
|
||||
return super().logout(redirect=redirect)
|
||||
|
||||
@@ -166,7 +166,12 @@ def url_lang(path_or_uri, lang_code=None):
|
||||
# Insert the context language or the provided language
|
||||
elif lang_url_code != default_lg.url_code or force_lang:
|
||||
ps.insert(1, lang_url_code)
|
||||
location = u'/'.join(ps) + sep + qs
|
||||
|
||||
# remove trailing /
|
||||
# ['', fr', ''] => /fr/ instead of /fr
|
||||
if ps[-1] == '':
|
||||
ps.pop(-1)
|
||||
location = (u'/'.join(ps) or u'/') + sep + qs
|
||||
return location
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class TestLangUrl(HttpCase):
|
||||
|
||||
def test_01_url_lang(self):
|
||||
with MockRequest(self.env, website=self.website):
|
||||
self.assertEqual(url_lang('', '[lang]'), '/[lang]/hello/', "`[lang]` is used to be replaced in the url_return after installing a language, it should not be replaced or removed.")
|
||||
self.assertEqual(url_lang('', '[lang]'), '/[lang]/hello', "`[lang]` is used to be replaced in the url_return after installing a language, it should not be replaced or removed.")
|
||||
|
||||
def test_02_url_redirect(self):
|
||||
url = '/fr_WHATEVER/contactus'
|
||||
|
||||
@@ -114,8 +114,8 @@ class TestQwebProcessAtt(TransactionCase):
|
||||
def test_process_att_no_request(self):
|
||||
# no request so no URL rewriting
|
||||
self._test_att('/', {'href': '/'})
|
||||
self._test_att('/en/', {'href': '/en/'})
|
||||
self._test_att('/fr/', {'href': '/fr/'})
|
||||
self._test_att('/en', {'href': '/en'})
|
||||
self._test_att('/fr', {'href': '/fr'})
|
||||
# no URL rewritting for CDN
|
||||
self._test_att('/a', {'href': '/a'})
|
||||
|
||||
@@ -123,8 +123,8 @@ class TestQwebProcessAtt(TransactionCase):
|
||||
with MockRequest(self.env):
|
||||
# no website so URL rewriting
|
||||
self._test_att('/', {'href': '/'})
|
||||
self._test_att('/en/', {'href': '/en/'})
|
||||
self._test_att('/fr/', {'href': '/fr/'})
|
||||
self._test_att('/en', {'href': '/en'})
|
||||
self._test_att('/fr', {'href': '/fr'})
|
||||
# no URL rewritting for CDN
|
||||
self._test_att('/a', {'href': '/a'})
|
||||
|
||||
@@ -140,13 +140,15 @@ class TestQwebProcessAtt(TransactionCase):
|
||||
with MockRequest(self.env, website=self.website):
|
||||
self._test_att('/', {'href': '/'})
|
||||
self._test_att('/en/', {'href': '/'})
|
||||
self._test_att('/fr/', {'href': '/fr/'})
|
||||
self._test_att('/fr/', {'href': '/fr'})
|
||||
self._test_att('/fr', {'href': '/fr'})
|
||||
|
||||
def test_process_att_with_request_lang(self):
|
||||
with MockRequest(self.env, website=self.website, context={'lang': 'fr_FR'}):
|
||||
self._test_att('/', {'href': '/fr/'})
|
||||
self._test_att('/', {'href': '/fr'})
|
||||
self._test_att('/en/', {'href': '/'})
|
||||
self._test_att('/fr/', {'href': '/fr/'})
|
||||
self._test_att('/fr/', {'href': '/fr'})
|
||||
self._test_att('/fr', {'href': '/fr'})
|
||||
|
||||
def test_process_att_matching_cdn_and_lang(self):
|
||||
with MockRequest(self.env, website=self.website):
|
||||
|
||||
Reference in New Issue
Block a user