[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:
Jeremy Kersten
2021-09-10 08:49:13 +00:00
parent 8e22acf5ba
commit 914fe1085e
4 changed files with 24 additions and 10 deletions
+8 -1
View File
@@ -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)
+6 -1
View File
@@ -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
+1 -1
View File
@@ -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'
+9 -7
View File
@@ -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):