Skip to content

Commit c9df70b

Browse files
authored
Condiontally homepage redirect based on domain and logged in status (#12147)
Related readthedocs/readthedocs-ops#1626 Closes readthedocs/readthedocs-ops#1602
1 parent caa2175 commit c9df70b

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

readthedocs/core/views/__init__.py

+29-19
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,45 @@ def get(self, request, *_, **__):
3838

3939
class HomepageView(TemplateView):
4040
"""
41-
Conditionally show the home page or redirect to the login page.
41+
Conditionally redirect to website home page or to dashboard.
4242
43-
On the current dashboard, this shows the application homepage. However, we
44-
no longer require this page in our application as we have a similar page on
45-
our website. Instead, redirect to our login page on the new dashboard.
43+
44+
User hitting readthedocs.org / readthedocs.com
45+
1. when user is logged in, redirect to dashboard
46+
2. when user is logged off, redirect to https://about.readthedocs.com/
47+
48+
User hitting app.readthedocs.org / app.readthedocs.com
49+
1. when user is logged in, redirect to dashboard
50+
2. when user is logged off, redirect to login page
4651
"""
4752

4853
template_name = "homepage.html"
4954

5055
def get(self, request, *args, **kwargs):
51-
# Redirect to login page
52-
return redirect(reverse("account_login"))
53-
56+
# Request hitting the old domain (readthedocs.org / readthedocs.com)
57+
if request.get_host() == settings.PRODUCTION_DOMAIN.replace("app.", ""):
58+
# Redirect to user dashboard for logged in users
59+
if request.user.is_authenticated:
60+
return redirect("projects_dashboard")
61+
62+
# Redirect to ``about.`` in production
63+
if not settings.DEBUG:
64+
query_string = f"?ref={settings.PRODUCTION_DOMAIN}"
65+
if request.META["QUERY_STRING"]:
66+
# Small hack to not append `&` to URLs without a query_string
67+
query_string += "&" + request.META["QUERY_STRING"]
68+
69+
# Do a 302 here so that it varies on logged in status
70+
return redirect(f"https://about.readthedocs.com/{query_string}", permanent=False)
71+
72+
# Request hitting app.readthedocs.org / app.readthedocs.com
73+
#
5474
# Redirect to user dashboard for logged in users
5575
if request.user.is_authenticated:
5676
return redirect("projects_dashboard")
5777

58-
# Redirect to ``about.`` in production
59-
if not settings.DEBUG:
60-
query_string = f"?ref={settings.PRODUCTION_DOMAIN}"
61-
if request.META["QUERY_STRING"]:
62-
# Small hack to not append `&` to URLs without a query_string
63-
query_string += "&" + request.META["QUERY_STRING"]
64-
65-
# Do a 302 here so that it varies on logged in status
66-
return redirect(f"https://about.readthedocs.com{query_string}", permanent=False)
67-
68-
# Show the homepage for local dev
69-
return super().get(request, *args, **kwargs)
78+
# Redirect to login page
79+
return redirect(reverse("account_login"))
7080

7181

7282
class SupportView(PrivateViewMixin, TemplateView):

0 commit comments

Comments
 (0)