Skip to content

Commit 2f97d8b

Browse files
authored
Merge pull request #6353 from stsewd/dont-link-to-dashboard-from-footer
Dont link to dashboard from footer
2 parents b9ada63 + e90ea84 commit 2f97d8b

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

readthedocs/api/v2/views/footer_views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def get_version_compare_data(project, base_version=None):
4444
'is_highest': True,
4545
}
4646
if highest_version_obj:
47-
ret_val['url'] = highest_version_obj.get_absolute_url()
47+
# Never link to the dashboard,
48+
# users reading the docs may don't have access to the dashboard.
49+
ret_val['url'] = highest_version_obj.get_absolute_url(link_to_dashboard=False)
4850
ret_val['slug'] = highest_version_obj.slug
4951
if base_version and base_version.slug != LATEST:
5052
try:

readthedocs/builds/models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
from readthedocs.projects.models import APIProject, Project
7979
from readthedocs.projects.version_handling import determine_stable_version
8080

81-
8281
log = logging.getLogger(__name__)
8382

8483

@@ -290,7 +289,13 @@ def commit_name(self):
290289
)
291290
return self.identifier
292291

293-
def get_absolute_url(self):
292+
def get_absolute_url(self, link_to_dashboard=True):
293+
"""
294+
Get absolute url to the docs of the version.
295+
296+
:param link_to_dashboard: If `False` we never try to link to the dashboard,
297+
we link to the docs even if they result in a 404.
298+
"""
294299
# Hack external versions for now.
295300
# TODO: We can integrate them into the resolver
296301
# but this is much simpler to handle since we only link them a couple places for now
@@ -300,7 +305,7 @@ def get_absolute_url(self):
300305
f'{self.project.slug}/{self.slug}/index.html'
301306
return url
302307

303-
if not self.built and not self.uploaded:
308+
if not self.built and not self.uploaded and link_to_dashboard:
304309
return reverse(
305310
'project_version_detail',
306311
kwargs={

readthedocs/rtd_tests/tests/test_footer.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import mock
22
from django.contrib.sessions.backends.base import SessionBase
33
from django.test import TestCase
4+
from django.test.utils import override_settings
45
from rest_framework.test import APIRequestFactory, APITestCase
56

67
from readthedocs.api.v2.views.footer_views import (
@@ -114,6 +115,10 @@ def test_not_show_edit_on_github(self):
114115
self.assertNotIn('Edit', response.data['html'])
115116

116117

118+
@override_settings(
119+
USE_SUBDOMAIN=True,
120+
PUBLIC_DOMAIN='readthedocs.io',
121+
)
117122
class TestVersionCompareFooter(TestCase):
118123
fixtures = ['test_data']
119124

@@ -124,7 +129,7 @@ def test_highest_version_from_stable(self):
124129
base_version = self.pip.get_stable_version()
125130
valid_data = {
126131
'project': 'Version 0.8.1 of Pip (19)',
127-
'url': '/dashboard/pip/version/0.8.1/',
132+
'url': 'http://pip.readthedocs.io/en/0.8.1/',
128133
'slug': '0.8.1',
129134
'version': '0.8.1',
130135
'is_highest': True,
@@ -136,7 +141,7 @@ def test_highest_version_from_lower(self):
136141
base_version = self.pip.versions.get(slug='0.8')
137142
valid_data = {
138143
'project': 'Version 0.8.1 of Pip (19)',
139-
'url': '/dashboard/pip/version/0.8.1/',
144+
'url': 'http://pip.readthedocs.io/en/0.8.1/',
140145
'slug': '0.8.1',
141146
'version': '0.8.1',
142147
'is_highest': False,
@@ -149,7 +154,7 @@ def test_highest_version_from_latest(self):
149154
base_version = self.pip.versions.get(slug=LATEST)
150155
valid_data = {
151156
'project': 'Version 0.8.1 of Pip (19)',
152-
'url': '/dashboard/pip/version/0.8.1/',
157+
'url': 'http://pip.readthedocs.io/en/0.8.1/',
153158
'slug': '0.8.1',
154159
'version': '0.8.1',
155160
'is_highest': True,
@@ -177,7 +182,7 @@ def test_highest_version_over_branches(self):
177182
base_version = self.pip.versions.get(slug='0.8.1')
178183
valid_data = {
179184
'project': 'Version 1.0.0 of Pip ({})'.format(version.pk),
180-
'url': '/dashboard/pip/version/1.0.0/',
185+
'url': 'http://pip.readthedocs.io/en/1.0.0/',
181186
'slug': '1.0.0',
182187
'version': '1.0.0',
183188
'is_highest': False,
@@ -191,7 +196,7 @@ def test_highest_version_without_tags(self):
191196
base_version = self.pip.versions.get(slug='0.8.1')
192197
valid_data = {
193198
'project': 'Version 0.8.1 of Pip (19)',
194-
'url': '/dashboard/pip/version/0.8.1/',
199+
'url': 'http://pip.readthedocs.io/en/0.8.1/',
195200
'slug': '0.8.1',
196201
'version': '0.8.1',
197202
'is_highest': True,
@@ -202,7 +207,7 @@ def test_highest_version_without_tags(self):
202207
base_version = self.pip.versions.get(slug='0.8')
203208
valid_data = {
204209
'project': 'Version 0.8.1 of Pip (19)',
205-
'url': '/dashboard/pip/version/0.8.1/',
210+
'url': 'http://pip.readthedocs.io/en/0.8.1/',
206211
'slug': '0.8.1',
207212
'version': '0.8.1',
208213
'is_highest': False,
@@ -219,7 +224,7 @@ def test_highest_version_without_tags(self):
219224
)
220225
valid_data = {
221226
'project': 'Version 2.0.0 of Pip ({})'.format(version.pk),
222-
'url': '/dashboard/pip/version/2.0.0/',
227+
'url': 'http://pip.readthedocs.io/en/2.0.0/',
223228
'slug': '2.0.0',
224229
'version': '2.0.0',
225230
'is_highest': False,
@@ -235,11 +240,12 @@ class TestFooterPerformance(APITestCase):
235240

236241
# The expected number of queries for generating the footer
237242
# This shouldn't increase unless we modify the footer API
238-
EXPECTED_QUERIES = 9
243+
EXPECTED_QUERIES = 13
239244

240245
def setUp(self):
241246
self.pip = Project.objects.get(slug='pip')
242247
self.pip.versions.create_latest()
248+
self.pip.versions.update(built=True)
243249

244250
def render(self):
245251
request = self.factory.get(self.url)

0 commit comments

Comments
 (0)