Skip to content
Open
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
10 changes: 8 additions & 2 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
RedirectToDocsView,
RedirectToHTMLDocsView,
RedirectToHTMLToolsView,
RedirectToLibraryView,
RedirectToLibrariesView,
RedirectToReleaseView,
RedirectToToolsView,
StaticContentTemplateView,
UserGuideTemplateView,
BoostDevelopmentView,
ModernizedDocsView,
QRCodeView,
RedirectToLibraryDetailView,
)
from libraries.api import LibrarySearchView
from libraries.views import (
Expand Down Expand Up @@ -381,6 +382,11 @@
),
]
+ [
re_path(
r"^lib/(?P<library_slug>[^/]+)/?$",
RedirectToLibraryDetailView.as_view(),
name="redirect-to-library-view",
),
# Redirects for old boost.org urls.
re_path(
r"^libs/(?P<libname>[^/]+)/(?P<path>.*)/?$",
Expand All @@ -404,7 +410,7 @@
),
re_path(
r"^doc/libs/(?P<requested_version>[^/]+)/?$",
RedirectToLibraryView.as_view(),
RedirectToLibrariesView.as_view(),
name="redirect-to-library-page",
),
re_path(
Expand Down
15 changes: 15 additions & 0 deletions core/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,18 @@ def test_qrc_logs_plausible_error_but_still_redirects(tp, caplog):
tp.response_302(res)
assert res["Location"] == "/library/"
assert any("Plausible event post failed" in r.message for r in caplog.records)


def test_redirect_to_library_detail_view(tp):
"""Test that /lib/<library_slug>/ redirects to library detail page with prioritized version."""
response = tp.get("redirect-to-library-view", library_slug="algorithm")
tp.response_302(response)
assert response["Location"] == "/library/latest/algorithm/"


def test_redirect_to_library_detail_view_with_cookie(tp):
"""Test that /lib/<library_slug>/ redirects using version from cookie."""
tp.client.cookies["boost_version"] = "boost-1-86-0"
response = tp.get("redirect-to-library-view", library_slug="algorithm")
tp.response_302(response)
assert response["Location"] == "/library/1.86.0/algorithm/"
20 changes: 18 additions & 2 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
from libraries.constants import LATEST_RELEASE_URL_PATH_STR
from libraries.utils import (
legacy_path_transform,
get_prioritized_library_view,
generate_canonical_library_uri,
get_prioritized_library_view,
get_prioritized_version,
)
from versions.models import Version

Expand Down Expand Up @@ -891,7 +892,22 @@ def get(self, request, requested_version):
return HttpResponseRedirect(new_path)


class RedirectToLibraryView(BaseRedirectView):
class RedirectToLibraryDetailView(BaseRedirectView):
"""View to redirect to a library's detail page"""

def get(self, request, library_slug):
return redirect(
reverse(
"library-detail",
kwargs={
"library_slug": library_slug,
"version_slug": get_prioritized_version(request),
},
)
)


class RedirectToLibrariesView(BaseRedirectView):
"""View to redirect to a versioned libraries page."""

def get(self, request, requested_version):
Expand Down
2 changes: 1 addition & 1 deletion libraries/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_prioritized_version(request):
"""
url_version = get_version_from_url(request)
cookie_version = get_version_from_cookie(request)
default_version = None
default_version = LATEST_RELEASE_URL_PATH_STR
return url_version or cookie_version or default_version


Expand Down