[FIX] website: fix editor not starting after creating a website

Commit [1] introduced an automatic start of edit mode when
selecting a theme but didn't take into account wether the frontend lang
of the user was matching that of the website that is supposed to enter
in edit mode.

Steps to reproduce:
- Create an empty database and install website.
- Add an extra lang on website (e.g FR) and visit the website in that
lang.
- Go in settings an create a new website, skiper the configurator,
  select a theme.
- Redirect is with enable_editor but nothing happens.

The editor isn't started if not in the source's lang.

This commit redirect the user to the default_lang of the website
so that editor can always be started. It also introduces a tour
to test out the flow.

[1]: https://github.com/odoo/odoo/commit/f474eac4543712ae5b1c7d614f9eff9367445107

task-2687416

closes odoo/odoo#85058

X-original-commit: 02e08af7278cd66d768fe6a4f23aa17eb816be3c
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
Arthur Detroux (ard)
2022-02-22 15:19:34 +00:00
parent fe758ac69a
commit 2e44cb41ea
4 changed files with 116 additions and 0 deletions
+3
View File
@@ -1281,6 +1281,9 @@ class Website(models.Model):
def button_go_website(self, path='/', mode_edit=False):
self._force()
if mode_edit:
# If the user gets on a translated page (e.g /fr) the editor will
# never start. Forcing the default language fixes this issue.
path = url_for(path, self.default_lang_id.url_code)
path += '?enable_editor=1'
return {
'type': 'ir.actions.act_url',
@@ -0,0 +1,95 @@
odoo.define('website.tour.automatic_editor', function (require) {
'use strict';
const tour = require('web_tour.tour');
tour.register('automatic_editor_on_new_website', {
test: true,
url: '/',
},
[
{
content: "Select the language dropdown",
trigger: '.js_language_selector .dropdown-toggle'
},
{
content: "click on Add a language",
trigger: 'a.o_add_language',
},
{
content: "Select dropdown",
trigger: 'select[name=lang]',
run: () => {
$('select[name="lang"]').val('"pa_GB"').change();
}
},
{
content: "load parseltongue",
extra_trigger: '.modal select[name="lang"]:propValueContains(pa_GB)',
trigger: '.modal-footer button:first',
},
{
content: "Select the language dropdown",
trigger: '.js_language_selector .dropdown-toggle',
},
{
content: "Select parseltongue",
trigger: 'a.js_change_lang[data-url_code=pa_GB]',
},
{
content: "Check that we're on parseltongue and then go to settings",
trigger: 'html[lang=pa-GB]',
run: () => {
// Now go through the settings for a new website. A frontend_lang
// cookie was set during previous steps. It should not be used when
// redirecting to the frontend in the following steps.
window.location.href = '/web#action=website.action_website_configuration';
}
},
{
content: "create a new website",
trigger: 'button[name="action_website_create_new"]',
},
{
content: "insert website name",
trigger: 'input[name="name"]',
run: 'text Website EN'
},
{
content: "validate the website creation modal",
trigger: 'button.btn-primary'
},
{
content: "skip configurator",
// This trigger targets the skip button, it doesn't have a more
// explicit class or ID.
trigger: '.o_configurator_container .container-fluid .btn.btn-link'
},
{
content: "make hover button appear",
trigger: '.o_theme_preview',
run: () => {
$('.o_theme_preview .o_button_area').attr('style', 'visibility: visible; opacity: 1;');
},
},
{
content: "Install a theme",
trigger: 'button[data-name="button_choose_theme"]'
},
{
content: "Check that the editor is loaded",
trigger: 'body.editor_enable',
timeout: 30000,
run: () => null, // it's a check
},
{
content: "exit edit mode",
trigger: '.o_we_website_top_actions button.btn-primary:contains("Save")',
},
{
content: "wait for editor to close",
trigger: 'body:not(.editor_enable)',
run: () => null, // It's a check
}
]);
});
+1
View File
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_attachment
from . import test_auth_signup_uninvited
from . import test_automatic_editor
from . import test_base_url
from . import test_configurator
from . import test_controllers
@@ -0,0 +1,17 @@
from odoo.tests import tagged
from odoo.addons.website.tests.test_configurator import TestConfiguratorCommon
@tagged('post_install', '-at_install')
class TestAutomaticEditor(TestConfiguratorCommon):
def test_01_automatic_editor_on_new_website(self):
# We create a lang because if the new website is displayed in this lang
# instead of the website's default one, the editor won't automatically
# start.
self.env['res.lang'].create({
'name': 'Parseltongue',
'code': 'pa_GB',
'iso_code': 'pa_GB',
'url_code': 'pa_GB',
})
self.start_tour('/', 'automatic_editor_on_new_website', login='admin')