Skip to content

Commit 0acc369

Browse files
committed
Fix for release vs latest redirect on non-boost_version_slug urls
1 parent e7826ec commit 0acc369

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

core/views.py

+26
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
)
1515
from django.shortcuts import redirect
1616
from django.template.loader import render_to_string
17+
from django.urls import reverse
1718
from django.views import View
1819
from django.views.generic import TemplateView
1920
from requests.compat import chardet
2021

2122
from libraries.constants import LATEST_RELEASE_URL_PATH_STR
23+
from libraries.utils import legacy_path_transform
2224
from versions.models import Version
2325

2426
from .asciidoc import convert_adoc_to_html
@@ -111,6 +113,14 @@ def build_path(self):
111113
Builds the path from URL kwargs
112114
"""
113115
content_path = self.kwargs.get("content_path")
116+
updated_legacy_path = legacy_path_transform(content_path)
117+
if updated_legacy_path != content_path:
118+
return redirect(
119+
reverse(
120+
self.request.resolver_match.view_name,
121+
kwargs={"content_path": updated_legacy_path},
122+
)
123+
)
114124

115125
print(self.markdown_local)
116126
if self.markdown_local:
@@ -208,6 +218,14 @@ def get(self, request, *args, **kwargs):
208218
See the *_static_config.json files for URL mappings to specific S3 keys.
209219
"""
210220
content_path = self.kwargs.get("content_path")
221+
updated_legacy_path = legacy_path_transform(content_path)
222+
if updated_legacy_path != content_path:
223+
return redirect(
224+
reverse(
225+
self.request.resolver_match.view_name,
226+
kwargs={"content_path": updated_legacy_path},
227+
)
228+
)
211229

212230
# For some reason, if a user cancels a social signup (cancelling a GitHub
213231
# signup, for example), the redirect URL comes through this view, so we
@@ -513,6 +531,14 @@ class ImageView(View):
513531
def get(self, request, *args, **kwargs):
514532
# TODO: Add caching logic
515533
content_path = self.kwargs.get("content_path")
534+
updated_legacy_path = legacy_path_transform(content_path)
535+
if updated_legacy_path != content_path:
536+
return redirect(
537+
reverse(
538+
self.request.resolver_match.view_name,
539+
kwargs={"content_path": updated_legacy_path},
540+
)
541+
)
516542

517543
client = get_s3_client()
518544
try:

libraries/utils.py

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
SELECTED_BOOST_VERSION_COOKIE_NAME,
1717
SELECTED_LIBRARY_VIEW_COOKIE_NAME,
1818
LATEST_RELEASE_URL_PATH_STR,
19+
LEGACY_LATEST_RELEASE_URL_PATH_STR,
1920
)
2021
from versions.models import Version
2122

@@ -203,3 +204,9 @@ def batched(iterable, n, *, strict=False):
203204
if strict and len(batch) != n:
204205
raise ValueError("batched(): incomplete batch")
205206
yield batch
207+
208+
209+
def legacy_path_transform(content_path):
210+
if content_path and content_path.startswith(LEGACY_LATEST_RELEASE_URL_PATH_STR):
211+
content_path = re.sub(r"([a-zA-Z0-9\.]+)/(\S+)", r"latest/\2", content_path)
212+
return content_path

0 commit comments

Comments
 (0)