From 964aa3d6965bc1cc8757e64cefd9535e991aa1df Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 3 Sep 2019 13:09:12 +0000 Subject: [PATCH] [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 --- addons/website/models/ir_ui_view.py | 4 ++-- .../static/src/js/content/website_root.js | 17 +++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index 4b5b3a3fa3a..5440052ba6e 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -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 ] diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js index dc2b2f679d7..22363f04129 100644 --- a/addons/website/static/src/js/content/website_root.js +++ b/addons/website/static/src/js/content/website_root.js @@ -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