From 89e530dbaa51d48d4785877e70b17785db2b7e53 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Wed, 30 Oct 2024 12:45:30 +0100 Subject: [PATCH 1/2] 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 https://github.com/readthedocs/sphinx_rtd_theme/issues/1613 --- readthedocs/proxito/tests/test_hosting.py | 5 ++--- readthedocs/proxito/views/hosting.py | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/readthedocs/proxito/tests/test_hosting.py b/readthedocs/proxito/tests/test_hosting.py index ee1d53f6d83..eea41d709ed 100644 --- a/readthedocs/proxito/tests/test_hosting.py +++ b/readthedocs/proxito/tests/test_hosting.py @@ -400,9 +400,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/", diff --git a/readthedocs/proxito/views/hosting.py b/readthedocs/proxito/views/hosting.py index 370e2e4a0c8..2441ac1c892 100644 --- a/readthedocs/proxito/views/hosting.py +++ b/readthedocs/proxito/views/hosting.py @@ -342,14 +342,14 @@ 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") - ) - sorted_versions_active_built_not_hidden = versions_active_built_not_hidden + 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 project.supports_multiple_versions: if ( project.addons.flyout_sorting == ADDONS_FLYOUT_SORTING_SEMVER_READTHEDOCS_COMPATIBLE From 58f9d5d663357deb3cc4f99d48e9f1550de28ab7 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Thu, 31 Oct 2024 11:29:38 +0100 Subject: [PATCH 2/2] Add special case for single version projects --- readthedocs/proxito/tests/test_hosting.py | 12 ++++++++++++ readthedocs/proxito/views/hosting.py | 11 +++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/readthedocs/proxito/tests/test_hosting.py b/readthedocs/proxito/tests/test_hosting.py index eea41d709ed..f35f2004d8d 100644 --- a/readthedocs/proxito/tests/test_hosting.py +++ b/readthedocs/proxito/tests/test_hosting.py @@ -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() diff --git a/readthedocs/proxito/views/hosting.py b/readthedocs/proxito/views/hosting.py index 2441ac1c892..108fe7f344d 100644 --- a/readthedocs/proxito/views/hosting.py +++ b/readthedocs/proxito/views/hosting.py @@ -348,8 +348,15 @@ def _v1(self, project, version, build, filename, url, request): .order_by("-slug") ) sorted_versions_active_built_not_hidden = versions_active_built_not_hidden - - if project.supports_multiple_versions: + 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() + ) + ) + else: if ( project.addons.flyout_sorting == ADDONS_FLYOUT_SORTING_SEMVER_READTHEDOCS_COMPATIBLE