Skip to content

Commit

Permalink
Add redirect to about.readthedocs.com for logged out users (#10570)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ericholscher authored Aug 1, 2023
1 parent 475f0d0 commit 3f6aec3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 72 deletions.
24 changes: 17 additions & 7 deletions readthedocs/core/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from django.views.generic import TemplateView, View

from readthedocs.core.mixins import CDNCacheControlMixin, PrivateViewMixin
from readthedocs.projects.models import Project

log = structlog.get_logger(__name__)

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

def get(self, request, *args, **kwargs):
# Redirect to login page for new dashboard
if settings.RTD_EXT_THEME_ENABLED:
return redirect(reverse("account_login"))
return super().get(request, *args, **kwargs)

def get_context_data(self, **kwargs):
"""Add latest builds and featured projects."""
context = super().get_context_data(**kwargs)
context['featured_list'] = Project.objects.filter(featured=True)
return context
# Redirect to user dashboard for logged in users
if request.user.is_authenticated:
return redirect("projects_dashboard")

# Redirect to ``about.`` in production
if not settings.DEBUG:
query_string = "?ref=dotorg-homepage"
if request.META["QUERY_STRING"]:
# Small hack to not append `&` to URLs without a query_string
query_string += "&" + request.META["QUERY_STRING"]
return redirect(
f"https://about.readthedocs.com{query_string}", permanent=False
)

# Show the homepage for local dev
return super().get(request, *args, **kwargs)


class SupportView(PrivateViewMixin, TemplateView):
Expand Down
4 changes: 1 addition & 3 deletions readthedocs/rtd_tests/tests/test_privacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _create_kong(

def test_private_repo(self):
"""Check that private projects don't show up in: builds, downloads,
detail, homepage
detail
"""
self._create_kong('private', 'private')
Expand All @@ -88,8 +88,6 @@ def test_private_repo(self):
self.assertEqual(r.status_code, 200)

self.client.login(username='tester', password='test')
r = self.client.get('/')
self.assertNotContains(r, 'Django Kong')
r = self.client.get('/projects/django-kong/')
self.assertEqual(r.status_code, 404)
r = self.client.get('/projects/django-kong/builds/')
Expand Down
20 changes: 0 additions & 20 deletions readthedocs/rtd_tests/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from urllib.parse import urlsplit

from django.contrib.auth.models import User
from django.core.cache import cache
from django.test import TestCase, override_settings
from django.urls import reverse
from django.utils import timezone
Expand Down Expand Up @@ -437,22 +436,3 @@ def test_generated_csv_data(self):
self.assertEqual(body[0][0], 'Created Date')
self.assertEqual(body[1][1], 'advertising')
self.assertEqual(body[-1][1], 'hello world')


class TestHomepageCache(TestCase):

def setUp(self):
cache.clear()

def tearDown(self):
cache.clear()

def test_homepage_queries(self):
with self.assertNumQueries(1):
r = self.client.get('/')
self.assertEqual(r.status_code, 200)

# Cache
with self.assertNumQueries(0):
r = self.client.get('/')
self.assertEqual(r.status_code, 200)
24 changes: 0 additions & 24 deletions readthedocs/templates/core/project_list_featured.html

This file was deleted.

18 changes: 0 additions & 18 deletions readthedocs/templates/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,6 @@ <h3>{% trans "Multiple versions" %}</h3>
{% include "core/widesearchbar.html" with form_action=search_form_action %}
</section>

{% get_current_language as language %}
{% cache 600 homepage_featured_list language %}
{% if featured_list %}
<!-- BEGIN projects list -->
<section>
<h3>{% trans "Featured Projects" %}</h3>
<div class="module-list">
<div class="module-list-wrapper">
<ul style="margin-bottom: 0">
{% include "core/project_list_featured.html" %}
</ul>
</div>
</div>
</section>
<!-- END projects list -->
{% endif %}
{% endcache %}

<section>
<h2>{% trans 'About Read the Docs' %}</h2>

Expand Down

0 comments on commit 3f6aec3

Please sign in to comment.