[FIX] website: make website selector work with scheme and port
Before this commit, if one would introduce a scheme or a port in his website domain, it would make the website selector to crash JS side. Indeed, it would replace the current url hostname by the website domain. If the website domain was introduced with `http://` it would lead to `http://http://mysite.com`. If port was introduced, `http://mysite:8069:8069`. Also, by fixing those 2, it also make `localhost` and `127.0.0.1` to work. (which would not work without `http://`. Related to #36390
This commit is contained in:
@@ -331,9 +331,9 @@ class View(models.Model):
|
||||
|
||||
cur = Website.get_current_website()
|
||||
if self.env.user.has_group('website.group_website_publisher') and self.env.user.has_group('website.group_multi_website'):
|
||||
qcontext['multi_website_websites_current'] = {'website_id': cur.id, 'name': cur.name, 'domain': cur.domain}
|
||||
qcontext['multi_website_websites_current'] = {'website_id': cur.id, 'name': cur.name, 'domain': cur._get_http_domain()}
|
||||
qcontext['multi_website_websites'] = [
|
||||
{'website_id': website.id, 'name': website.name, 'domain': website.domain}
|
||||
{'website_id': website.id, 'name': website.name, 'domain': website._get_http_domain()}
|
||||
for website in Website.search([]) if website != cur
|
||||
]
|
||||
|
||||
|
||||
@@ -182,21 +182,14 @@ var WebsiteRoot = publicRootData.PublicRoot.extend({
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onWebsiteSwitch: function (ev) {
|
||||
var websiteID = ev.currentTarget.getAttribute('website-id');
|
||||
|
||||
// need to force in each case, even if domain is set
|
||||
// Website 1: localhost; Website 2: 0.0.0.0; website 3: -
|
||||
// when you switch 3 <--> 1, you need to force the website
|
||||
|
||||
var websiteId = ev.currentTarget.getAttribute('website-id');
|
||||
var websiteDomain = ev.currentTarget.getAttribute('domain');
|
||||
var url = $.param.querystring(window.location.href, {fw: websiteID});
|
||||
var url = window.location.href;
|
||||
if (websiteDomain && window.location.hostname !== websiteDomain) {
|
||||
// if domain unchanged, this line will do a nop while we need to refresh
|
||||
// the page to load the new forced website.
|
||||
url = new URL(url);
|
||||
url.hostname = websiteDomain;
|
||||
var path = window.location.pathname + window.location.search + window.location.hash;
|
||||
url = websiteDomain + path;
|
||||
}
|
||||
window.location.href = url;
|
||||
window.location.href = $.param.querystring(url, {'fw': websiteId});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
|
||||
Reference in New Issue
Block a user