summaryrefslogtreecommitdiff
path: root/addons/website/controllers/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'addons/website/controllers/main.py')
-rw-r--r--addons/website/controllers/main.py36
1 files changed, 32 insertions, 4 deletions
diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py
index 86de3cf7414..e89f9375173 100644
--- a/addons/website/controllers/main.py
+++ b/addons/website/controllers/main.py
@@ -12,6 +12,7 @@ import werkzeug.utils
import werkzeug.wrappers
from itertools import islice
+from werkzeug import urls
from xml.etree import ElementTree as ET
import odoo
@@ -85,10 +86,37 @@ class Website(Home):
raise request.not_found()
- @http.route('/website/force_website', type='json', auth="user")
- def force_website(self, website_id):
- request.env['website']._force_website(website_id)
- return True
+ @http.route('/website/force/<int:website_id>', type='http', auth="user", website=True, sitemap=False, multilang=False)
+ def website_force(self, website_id, path='/', isredir=False, **kw):
+ """ To switch from a website to another, we need to force the website in
+ session, AFTER landing on that website domain (if set) as this will be a
+ different session.
+ """
+ parse = werkzeug.urls.url_parse
+ safe_path = parse(path).path
+
+ if not (request.env.user.has_group('website.group_multi_website')
+ and request.env.user.has_group('website.group_website_publisher')):
+ # The user might not be logged in on the forced website, so he won't
+ # have rights. We just redirect to the path as the user is already
+ # on the domain (basically a no-op as it won't change domain or
+ # force website).
+ # Website 1 : 127.0.0.1 (admin)
+ # Website 2 : 127.0.0.2 (not logged in)
+ # Click on "Website 2" from Website 1
+ return request.redirect(safe_path)
+
+ website = request.env['website'].browse(website_id)
+
+ if not isredir and website.domain:
+ domain_from = request.httprequest.environ.get('HTTP_HOST', '')
+ domain_to = parse(website._get_http_domain()).netloc
+ if domain_from != domain_to:
+ # redirect to correct domain for a correct routing map
+ url_to = urls.url_join(website._get_http_domain(), '/website/force/%s?isredir=1&path=%s' % (website.id, safe_path))
+ return request.redirect(url_to)
+ website._force()
+ return request.redirect(safe_path)
# ------------------------------------------------------
# Login - overwrite of the web login so that regular users are redirected to the backend