[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
This commit is contained in:
Younn Olivier
2022-06-24 10:28:07 +02:00
committed by qsm-odoo
parent dacc17ba2d
commit fed0e69c27
3 changed files with 20 additions and 5 deletions
+4 -3
View File
@@ -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',
}
@@ -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) {
@@ -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 });
}
},
}));
}