[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) <rde@odoo.com>
Signed-off-by: Arthur Detroux (ard) <ard@odoo.com>
This commit is contained in:
Arthur Detroux (ard)
2023-08-03 10:43:04 +02:00
parent 7c932aa6c8
commit 67d26ab8b1
3 changed files with 61 additions and 2 deletions
+23
View File
@@ -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"
@@ -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' : '',
@@ -11,12 +11,17 @@
<i class="fa fa-globe"/>
</div>
</t>
<t t-set="tooltipValue">This website does not have a domain configured.</t>
<t t-foreach="getElements()" t-as="element" t-key="element_index">
<DropdownItem
t-esc="element.name"
onSelected="element.callback"
class="element.class"
/>
dataset="!element.domain ? {'tooltip': tooltipValue, 'tooltipPosition': 'left'} : undefined">
<t t-if="!element.domain">
<span class="fa fa-warning me-2 text-warning"/>
</t>
<t t-out="element.name"/>
</DropdownItem>
</t>
</Dropdown>
</t>