Skip to content

Add redirect to about.readthedocs.com for logged out users #10570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing we don't use this view on the commercial application, as we are already adding this to the requests on commercial. But if we do, this query string could be conditional based on the application instance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, we're overriding it. Could probably stop now though, if we wanted 🤔

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