From 2083e592812866591e235752cdae72bd0ed75543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20De=20Caluw=C3=A9?= Date: Mon, 6 Sep 2021 19:27:23 +0000 Subject: [PATCH] [FIX] website: open the editor from a translated homepage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bug currently prevents opening the editor from a translated version of the homepage, for example /nl_BE (it works for other paths though). Before this commit the url computed by _goToMasterPage was: /website/lang/default?r=/nl_BE?enable_editor=1&rde=2 which will first redirect to the default language and then again to the translated version. The bug was introduced by commit 119d9437e076026edddd3da6bc3c945285602517 which chose an url without a trailing slash as the canonical one for the homepage. However, the bug can already be reproduced in 13.0 since commit 269aa594111a152ad4b7714856ea745bfef57155 if the user manually navigates to /nl_BE instead of /nl_BE/. No flows are redirecting to the url without trailing slash in our codebase before 14.4, so the problem is rarely seen. When clicking on the "Edit in master" button, _goToMasterPage now correctly removes the language code and redirects to the master version, solving the problem. task-2622270 closes odoo/odoo#76837 X-original-commit: 141c15d5dae137df11a73146ff4c991add7a2ff3 Signed-off-by: Jérémy Kersten (jke) --- .../website/static/src/js/menu/translate.js | 7 ++-- .../tests/tours/edit_translated_page.js | 32 +++++++++++++++++++ addons/website/tests/test_ui.py | 5 +++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 addons/website/static/tests/tours/edit_translated_page.js diff --git a/addons/website/static/src/js/menu/translate.js b/addons/website/static/src/js/menu/translate.js index dbc45d268ef..dd12fa2914b 100644 --- a/addons/website/static/src/js/menu/translate.js +++ b/addons/website/static/src/js/menu/translate.js @@ -146,8 +146,11 @@ var TranslatePageMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ var current = document.createElement('a'); current.href = window.location.toString(); current.search += (current.search ? '&' : '?') + 'enable_editor=1'; - // we are in translate mode, the pathname starts with '/'. By + // adding a trailing slash we can simply search for the first slash + // after the language code to remove the language part. + const startPath = (current.pathname + '/').indexOf('/', 1); + current.pathname = current.pathname.substring(startPath); var link = document.createElement('a'); link.href = '/website/lang/default'; diff --git a/addons/website/static/tests/tours/edit_translated_page.js b/addons/website/static/tests/tours/edit_translated_page.js new file mode 100644 index 00000000000..432676f475f --- /dev/null +++ b/addons/website/static/tests/tours/edit_translated_page.js @@ -0,0 +1,32 @@ +/** @odoo-module **/ + +import tour from "web_tour.tour"; + +tour.register('edit_translated_page_redirect', { + test: true, + url: '/nl/contactus', +}, [ + { + content: 'click edit master', + trigger: 'a[data-action="edit_master"]', + }, + { + content: 'check editor dashboard', + trigger: '#oe_snippets', + run: () => { + // After checking the presence of the editor dashboard, we visit a + // translated version of the homepage. The homepage is a special + // case (there is no trailing slash), so we test it separately. + location.href = '/nl'; + }, + }, + { + content: 'click edit master', + trigger: 'a[data-action="edit_master"]', + }, + { + content: 'check editor dashboard', + trigger: '#oe_snippets', + run: () => {}, + }, +]); diff --git a/addons/website/tests/test_ui.py b/addons/website/tests/test_ui.py index c42647ba849..ab56ea7a6e4 100644 --- a/addons/website/tests/test_ui.py +++ b/addons/website/tests/test_ui.py @@ -216,3 +216,8 @@ class TestUi(odoo.tests.HttpCase): 'mimetype': 'image/png', }) self.start_tour('/', 'snippet_background_edition', login='admin') + + def test_12_edit_translated_page_redirect(self): + lang = self.env['res.lang']._activate_lang('nl_NL') + self.env['website'].browse(1).write({'language_ids': [(4, lang.id, 0)]}) + self.start_tour("/nl/contactus", 'edit_translated_page_redirect', login='admin')