From fed0e69c27e9c9109dedb154cbda3b2d2be5251a Mon Sep 17 00:00:00 2001 From: Younn Olivier Date: Thu, 9 Jun 2022 10:30:11 +0200 Subject: [PATCH] [FIX] website: fix multi website redirections Before this commit, switching websites with custom domains was not properly done: the client action should redirect to the custom domain if there is one, instead of only redirecting the iframe. The redirection was not correct for the "go to website" buttons either: in that case, the url was incorrectly generated for the redirection (the custom domain was passed in the path parameter of the client action). See merge commit for more information. task-2687506 --- addons/website/models/mixins.py | 7 ++++--- .../client_actions/website_preview/website_preview.js | 10 +++++++++- .../static/src/systray_items/website_switcher.js | 8 +++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/addons/website/models/mixins.py b/addons/website/models/mixins.py index 86b1938d03f..7a195652b25 100644 --- a/addons/website/models/mixins.py +++ b/addons/website/models/mixins.py @@ -283,11 +283,12 @@ class WebsitePublishedMultiMixin(WebsitePublishedMixin): return is_published def open_website_url(self): - url = url_join(self.website_id.domain, self.website_url) if self.website_id.domain else self.website_url - url = self.env['website'].get_client_action_url(url) + client_action_url = self.env['website'].get_client_action_url(self.website_url) + if self.website_id.domain: + client_action_url = url_join(self.website_id.domain, f'{client_action_url}&website_id={self.website_id.id}') return { 'type': 'ir.actions.act_url', - 'url': url, + 'url': client_action_url, 'target': 'self', } diff --git a/addons/website/static/src/client_actions/website_preview/website_preview.js b/addons/website/static/src/client_actions/website_preview/website_preview.js index dbf5a106995..5fa7a36beee 100644 --- a/addons/website/static/src/client_actions/website_preview/website_preview.js +++ b/addons/website/static/src/client_actions/website_preview/website_preview.js @@ -62,7 +62,11 @@ export class WebsitePreview extends Component { this.isWebsitePublisher = await this.user.hasGroup('website.group_website_publisher'); await this.websiteService.fetchWebsites(); const encodedPath = encodeURIComponent(this.path); - this.initialUrl = `/website/force/${this.websiteId}?path=${encodedPath}`; + if (this.websiteDomain && this.websiteDomain !== window.location.origin) { + window.location.href = `${this.websiteDomain}/web#action=website.website_preview&path=${encodedPath}&website_id=${this.websiteId}`; + } else { + this.initialUrl = `/website/force/${this.websiteId}?path=${encodedPath}`; + } }); useEffect(() => { @@ -114,6 +118,10 @@ export class WebsitePreview extends Component { return websiteId; } + get websiteDomain() { + return this.websiteService.websites.find(website => website.id === this.websiteId).domain; + } + get path() { let path = this.websiteService.editedObjectPath; if (!path) { diff --git a/addons/website/static/src/systray_items/website_switcher.js b/addons/website/static/src/systray_items/website_switcher.js index 87137c81e1f..87e74404369 100644 --- a/addons/website/static/src/systray_items/website_switcher.js +++ b/addons/website/static/src/systray_items/website_switcher.js @@ -17,7 +17,13 @@ export class WebsiteSwitcherSystray extends Component { name: website.name, id: website.id, callback: () => { - this.websiteService.goToWebsite({ websiteId: website.id }); + if (website.domain && website.domain !== window.location.origin) { + const { location: { pathname, search, hash } } = this.websiteService.contentWindow; + const path = pathname + search + hash; + window.location.href = `${website.domain}/web#action=website.website_preview&path=${encodeURI(path)}&website_id=${website.id}`; + } else { + this.websiteService.goToWebsite({ websiteId: website.id }); + } }, })); }