Skip to content

Commit 3f6aec3

Browse files
authored
Add redirect to about.readthedocs.com for logged out users (#10570)
* Add redirect to ``about.readthedocs.com`` for logged out users This is the last step in our migration to a new marketing page, showing it to logged out users on readthedocs.org. Currently logged in users will hit a homepage at the root, but this change makes that page redirect to the dashboard for community users. * Fix tests * Remove featured projects from homepage to simplify logic
1 parent 475f0d0 commit 3f6aec3

File tree

5 files changed

+18
-72
lines changed

5 files changed

+18
-72
lines changed

readthedocs/core/views/__init__.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from django.views.generic import TemplateView, View
1414

1515
from readthedocs.core.mixins import CDNCacheControlMixin, PrivateViewMixin
16-
from readthedocs.projects.models import Project
1716

1817
log = structlog.get_logger(__name__)
1918

@@ -45,15 +44,26 @@ class HomepageView(TemplateView):
4544
template_name = 'homepage.html'
4645

4746
def get(self, request, *args, **kwargs):
47+
# Redirect to login page for new dashboard
4848
if settings.RTD_EXT_THEME_ENABLED:
4949
return redirect(reverse("account_login"))
50-
return super().get(request, *args, **kwargs)
5150

52-
def get_context_data(self, **kwargs):
53-
"""Add latest builds and featured projects."""
54-
context = super().get_context_data(**kwargs)
55-
context['featured_list'] = Project.objects.filter(featured=True)
56-
return context
51+
# Redirect to user dashboard for logged in users
52+
if request.user.is_authenticated:
53+
return redirect("projects_dashboard")
54+
55+
# Redirect to ``about.`` in production
56+
if not settings.DEBUG:
57+
query_string = "?ref=dotorg-homepage"
58+
if request.META["QUERY_STRING"]:
59+
# Small hack to not append `&` to URLs without a query_string
60+
query_string += "&" + request.META["QUERY_STRING"]
61+
return redirect(
62+
f"https://about.readthedocs.com{query_string}", permanent=False
63+
)
64+
65+
# Show the homepage for local dev
66+
return super().get(request, *args, **kwargs)
5767

5868

5969
class SupportView(PrivateViewMixin, TemplateView):

readthedocs/rtd_tests/tests/test_privacy.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _create_kong(
7070

7171
def test_private_repo(self):
7272
"""Check that private projects don't show up in: builds, downloads,
73-
detail, homepage
73+
detail
7474
7575
"""
7676
self._create_kong('private', 'private')
@@ -88,8 +88,6 @@ def test_private_repo(self):
8888
self.assertEqual(r.status_code, 200)
8989

9090
self.client.login(username='tester', password='test')
91-
r = self.client.get('/')
92-
self.assertNotContains(r, 'Django Kong')
9391
r = self.client.get('/projects/django-kong/')
9492
self.assertEqual(r.status_code, 404)
9593
r = self.client.get('/projects/django-kong/builds/')

readthedocs/rtd_tests/tests/test_views.py

-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from urllib.parse import urlsplit
44

55
from django.contrib.auth.models import User
6-
from django.core.cache import cache
76
from django.test import TestCase, override_settings
87
from django.urls import reverse
98
from django.utils import timezone
@@ -437,22 +436,3 @@ def test_generated_csv_data(self):
437436
self.assertEqual(body[0][0], 'Created Date')
438437
self.assertEqual(body[1][1], 'advertising')
439438
self.assertEqual(body[-1][1], 'hello world')
440-
441-
442-
class TestHomepageCache(TestCase):
443-
444-
def setUp(self):
445-
cache.clear()
446-
447-
def tearDown(self):
448-
cache.clear()
449-
450-
def test_homepage_queries(self):
451-
with self.assertNumQueries(1):
452-
r = self.client.get('/')
453-
self.assertEqual(r.status_code, 200)
454-
455-
# Cache
456-
with self.assertNumQueries(0):
457-
r = self.client.get('/')
458-
self.assertEqual(r.status_code, 200)

readthedocs/templates/core/project_list_featured.html

-24
This file was deleted.

readthedocs/templates/homepage.html

-18
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,6 @@ <h3>{% trans "Multiple versions" %}</h3>
116116
{% include "core/widesearchbar.html" with form_action=search_form_action %}
117117
</section>
118118

119-
{% get_current_language as language %}
120-
{% cache 600 homepage_featured_list language %}
121-
{% if featured_list %}
122-
<!-- BEGIN projects list -->
123-
<section>
124-
<h3>{% trans "Featured Projects" %}</h3>
125-
<div class="module-list">
126-
<div class="module-list-wrapper">
127-
<ul style="margin-bottom: 0">
128-
{% include "core/project_list_featured.html" %}
129-
</ul>
130-
</div>
131-
</div>
132-
</section>
133-
<!-- END projects list -->
134-
{% endif %}
135-
{% endcache %}
136-
137119
<section>
138120
<h2>{% trans 'About Read the Docs' %}</h2>
139121

0 commit comments

Comments
 (0)