Skip to content

Addons: return all active versions on single version project #11727

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 2 commits into from
Oct 31, 2024
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
17 changes: 14 additions & 3 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,18 @@ def test_flyout_single_version_project(self):
self.version.has_htmlzip = True
self.version.save()

# Add extra built and active versions to emulate a project that went
# from multiple versions to single version.
# These versions shouldn't be included in the `versions.active` field.
for i in range(5):
fixture.get(
Version,
privacy_level=PUBLIC,
active=True,
built=True,
project=self.project,
)

self.project.versioning_scheme = SINGLE_VERSION_WITHOUT_TRANSLATIONS
self.project.save()

Expand All @@ -400,9 +412,8 @@ def test_flyout_single_version_project(self):
},
)
assert r.status_code == 200

expected = []
assert r.json()["versions"]["active"] == expected
expected = ["latest"]
assert [v["slug"] for v in r.json()["versions"]["active"]] == expected

expected = {
"pdf": "https://project.dev.readthedocs.io/_/downloads/en/latest/pdf/",
Expand Down
21 changes: 14 additions & 7 deletions readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,21 @@ def _v1(self, project, version, build, filename, url, request):
# projects that don't have one already
AddonsConfig.objects.get_or_create(project=project)

if project.supports_multiple_versions:
versions_active_built_not_hidden = (
self._get_versions(request, project)
.select_related("project")
.order_by("-slug")
versions_active_built_not_hidden = (
self._get_versions(request, project)
.select_related("project")
.order_by("-slug")
)
sorted_versions_active_built_not_hidden = versions_active_built_not_hidden
if not project.supports_multiple_versions:
# Return only one version when the project doesn't support multiple versions.
# That version is the only one the project serves.
sorted_versions_active_built_not_hidden = (
sorted_versions_active_built_not_hidden.filter(
slug=project.get_default_version()
)
)
sorted_versions_active_built_not_hidden = versions_active_built_not_hidden

else:
if (
project.addons.flyout_sorting
== ADDONS_FLYOUT_SORTING_SEMVER_READTHEDOCS_COMPATIBLE
Expand Down