Skip to content

Commit cf49d99

Browse files
authored
Addons: return all active versions on single version project (#11727)
* Addons: return all active versions on single version project We always return all the active versions no matter the versioning scheme of the project. That's how `versions.active` is expected to work. However, it seems the conditional was below where these versions are calculated. I also updated the test case that checks for the active versions on single versions projects. Closes readthedocs/sphinx_rtd_theme#1613 * Add special case for single version projects
1 parent 072212b commit cf49d99

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

readthedocs/proxito/tests/test_hosting.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,18 @@ def test_flyout_single_version_project(self):
384384
self.version.has_htmlzip = True
385385
self.version.save()
386386

387+
# Add extra built and active versions to emulate a project that went
388+
# from multiple versions to single version.
389+
# These versions shouldn't be included in the `versions.active` field.
390+
for i in range(5):
391+
fixture.get(
392+
Version,
393+
privacy_level=PUBLIC,
394+
active=True,
395+
built=True,
396+
project=self.project,
397+
)
398+
387399
self.project.versioning_scheme = SINGLE_VERSION_WITHOUT_TRANSLATIONS
388400
self.project.save()
389401

@@ -400,9 +412,8 @@ def test_flyout_single_version_project(self):
400412
},
401413
)
402414
assert r.status_code == 200
403-
404-
expected = []
405-
assert r.json()["versions"]["active"] == expected
415+
expected = ["latest"]
416+
assert [v["slug"] for v in r.json()["versions"]["active"]] == expected
406417

407418
expected = {
408419
"pdf": "https://project.dev.readthedocs.io/_/downloads/en/latest/pdf/",

readthedocs/proxito/views/hosting.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,21 @@ def _v1(self, project, version, build, filename, url, request):
342342
# projects that don't have one already
343343
AddonsConfig.objects.get_or_create(project=project)
344344

345-
if project.supports_multiple_versions:
346-
versions_active_built_not_hidden = (
347-
self._get_versions(request, project)
348-
.select_related("project")
349-
.order_by("-slug")
345+
versions_active_built_not_hidden = (
346+
self._get_versions(request, project)
347+
.select_related("project")
348+
.order_by("-slug")
349+
)
350+
sorted_versions_active_built_not_hidden = versions_active_built_not_hidden
351+
if not project.supports_multiple_versions:
352+
# Return only one version when the project doesn't support multiple versions.
353+
# That version is the only one the project serves.
354+
sorted_versions_active_built_not_hidden = (
355+
sorted_versions_active_built_not_hidden.filter(
356+
slug=project.get_default_version()
357+
)
350358
)
351-
sorted_versions_active_built_not_hidden = versions_active_built_not_hidden
352-
359+
else:
353360
if (
354361
project.addons.flyout_sorting
355362
== ADDONS_FLYOUT_SORTING_SEMVER_READTHEDOCS_COMPATIBLE

0 commit comments

Comments
 (0)