From 67d26ab8b1a16192c2134a25ef1a6ffb02ad4de1 Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Wed, 19 Jul 2023 08:41:09 +0000 Subject: [PATCH] [IMP] website: warn users when a website has no domain Prior to this commit, if a website does not have a domain, nothing tells the user that this is a misconfiguration that can lead to broken behaviours. For example, here are the steps to reproduce: - Have two website (X and Y) - Website Y does not have a domain - Tab 1 has Website X selected - User opens a new tab - Tab 2 has Website X selected as well - User switches tab 2 to Website Y - No redirection happens - User switches back to tab 1 - User opens the HTML editor for Website X - Website X content is displayed - User saves - Content is saved on Website Y This is pretty hard to fix as a lot of the python flow for Website uses `get_current_website` which will uses the session's "force_website_id" in priority. In any case, we consider having multiple websites sharing the same domain (or having no domains at all) a misconfiguration. Therefore, we should warn the user of so. This commit adds a tooltip on the website switcher for websites that do not have a domain set. It also adds a notification recommending users close other tabs if they switch website. opw-3374214 closes odoo/odoo#130448 X-original-commit: bc0c33e3d0026a14af40ed683fe27092a97e71a7 Related: odoo/design-themes#684 Signed-off-by: Romain Derie (rde) Signed-off-by: Arthur Detroux (ard) --- addons/website/i18n/website.pot | 23 ++++++++++++++ .../src/systray_items/website_switcher.js | 31 +++++++++++++++++++ .../src/systray_items/website_switcher.xml | 9 ++++-- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/addons/website/i18n/website.pot b/addons/website/i18n/website.pot index 420b44e4a4e..e930b3a589c 100644 --- a/addons/website/i18n/website.pot +++ b/addons/website/i18n/website.pot @@ -6803,6 +6803,13 @@ msgstr "" msgid "No support" msgstr "" +#. module: website +#. odoo-javascript +#: code:addons/website/static/src/systray_items/website_switcher.js:0 +#, python-format +msgid "No website domain configured for this website." +msgstr "" + #. module: website #: model_terms:ir.ui.view,arch_db:website.s_chart_options #: model_terms:ir.ui.view,arch_db:website.s_countdown_options @@ -9515,6 +9522,22 @@ msgstr "" msgid "This view arch has been modified" msgstr "" +#. module: website +#. odoo-javascript +#: code:addons/website/static/src/systray_items/website_switcher.js:0 +#, python-format +msgid "" +"This website does not have a domain configured. To avoid unexpected behaviours during website edition, we recommend closing (or refreshing) other browser tabs.\n" +"To remove this message please set a domain in your website settings" +msgstr "" + +#. module: website +#. odoo-javascript +#: code:addons/website/static/src/systray_items/website_switcher.xml:0 +#, python-format +msgid "This website does not have a domain configured." +msgstr "" + #. module: website #: model_terms:ir.ui.view,arch_db:website.snippet_options msgid "Thumbnails" diff --git a/addons/website/static/src/systray_items/website_switcher.js b/addons/website/static/src/systray_items/website_switcher.js index 5ab3cb0047c..90f175cb84f 100644 --- a/addons/website/static/src/systray_items/website_switcher.js +++ b/addons/website/static/src/systray_items/website_switcher.js @@ -1,5 +1,6 @@ /** @odoo-module **/ +import { browser } from "@web/core/browser/browser"; import { registry } from "@web/core/registry"; import { useService } from "@web/core/utils/hooks"; import { Dropdown } from "@web/core/dropdown/dropdown"; @@ -11,12 +12,15 @@ const { Component } = owl; export class WebsiteSwitcherSystray extends Component { setup() { this.websiteService = useService('website'); + this.notificationService = useService("notification"); + this.actionService = useService("action"); } getElements() { return this.websiteService.websites.map((website) => ({ name: website.name, id: website.id, + domain: website.domain, callback: () => { if (website.domain && !wUtils.isHTTPSorNakedDomainRedirection(website.domain, window.location.origin)) { const { location: { pathname, search, hash } } = this.websiteService.contentWindow; @@ -24,6 +28,33 @@ export class WebsiteSwitcherSystray extends Component { window.location.href = `${encodeURI(website.domain)}/web#action=website.website_preview&path=${encodeURIComponent(path)}&website_id=${encodeURIComponent(website.id)}`; } else { this.websiteService.goToWebsite({ websiteId: website.id }); + if (!website.domain) { + const closeFn = this.notificationService.add( + this.env._t( + "This website does not have a domain configured. To avoid unexpected behaviours during website edition, we recommend closing (or refreshing) other browser tabs.\nTo remove this message please set a domain in your website settings" + ), + { + type: "warning", + title: this.env._t( + "No website domain configured for this website." + ), + sticky: true, + buttons: [ + { + onClick: () => { + this.actionService.doAction( + "website.action_website_configuration" + ); + closeFn(); + }, + primary: true, + name: "Go to Settings", + }, + ], + } + ); + browser.setTimeout(closeFn, 7000); + } } }, class: website.id === this.websiteService.currentWebsite.id ? 'active' : '', diff --git a/addons/website/static/src/systray_items/website_switcher.xml b/addons/website/static/src/systray_items/website_switcher.xml index d60233f572e..5d0a3d00b2c 100644 --- a/addons/website/static/src/systray_items/website_switcher.xml +++ b/addons/website/static/src/systray_items/website_switcher.xml @@ -11,12 +11,17 @@ + This website does not have a domain configured. + dataset="!element.domain ? {'tooltip': tooltipValue, 'tooltipPosition': 'left'} : undefined"> + + + + +