diff --git a/readthedocs/proxito/tests/responses/v0.json b/readthedocs/proxito/tests/responses/v0.json index ca979c98fc5..4049979aeef 100644 --- a/readthedocs/proxito/tests/responses/v0.json +++ b/readthedocs/proxito/tests/responses/v0.json @@ -110,7 +110,7 @@ "flyout": { "enabled": true, "translations": [], - "versions": [{ "slug": "latest", "url": "/en/latest/" }], + "versions": [{ "slug": "latest", "url": "https://project.dev.readthedocs.io/en/latest/" }], "downloads": [] }, "search": { diff --git a/readthedocs/proxito/tests/test_hosting.py b/readthedocs/proxito/tests/test_hosting.py index d55734a72f0..99a79572a7b 100644 --- a/readthedocs/proxito/tests/test_hosting.py +++ b/readthedocs/proxito/tests/test_hosting.py @@ -282,8 +282,11 @@ def test_flyout_versions(self): assert r.status_code == 200 expected = [ - {"slug": "latest", "url": "/en/latest/"}, - {"slug": "public-built", "url": "/en/public-built/"}, + {"slug": "latest", "url": "https://project.dev.readthedocs.io/en/latest/"}, + { + "slug": "public-built", + "url": "https://project.dev.readthedocs.io/en/public-built/", + }, ] assert r.json()["addons"]["flyout"]["versions"] == expected @@ -310,7 +313,7 @@ def test_flyout_translations(self): assert r.status_code == 200 expected = [ - {"slug": "ja", "url": "/ja/"}, + {"slug": "ja", "url": "https://project.dev.readthedocs.io/ja/latest/"}, ] assert r.json()["addons"]["flyout"]["translations"] == expected @@ -426,3 +429,68 @@ def test_project_subproject(self): r.json()["projects"]["current"]["repository"]["url"] == "https://github.com/readthedocs/subproject" ) + + def test_flyout_subproject_urls(self): + translation = fixture.get( + Project, + slug="translation", + language="es", + repo="https://github.com/readthedocs/subproject", + ) + translation.versions.update( + built=True, + active=True, + ) + subproject = fixture.get( + Project, slug="subproject", repo="https://github.com/readthedocs/subproject" + ) + self.project.add_subproject(subproject) + subproject.translations.add(translation) + subproject.save() + + fixture.get(Version, slug="v1", project=subproject) + fixture.get(Version, slug="v2.3", project=subproject) + subproject.versions.update( + privacy_level=PUBLIC, + built=True, + active=True, + hidden=False, + ) + + r = self.client.get( + reverse("proxito_readthedocs_docs_addons"), + { + "url": "https://project.dev.readthedocs.io/projects/subproject/en/latest/", + "client-version": "0.6.0", + "api-version": "0.1.0", + }, + secure=True, + headers={ + "host": "project.dev.readthedocs.io", + }, + ) + assert r.status_code == 200 + + expected_versions = [ + { + "slug": "latest", + "url": "https://project.dev.readthedocs.io/projects/subproject/en/latest/", + }, + { + "slug": "v1", + "url": "https://project.dev.readthedocs.io/projects/subproject/en/v1/", + }, + { + "slug": "v2.3", + "url": "https://project.dev.readthedocs.io/projects/subproject/en/v2.3/", + }, + ] + assert r.json()["addons"]["flyout"]["versions"] == expected_versions + + expected_translations = [ + { + "slug": "es", + "url": "https://project.dev.readthedocs.io/projects/subproject/es/latest/", + }, + ] + assert r.json()["addons"]["flyout"]["translations"] == expected_translations diff --git a/readthedocs/proxito/views/hosting.py b/readthedocs/proxito/views/hosting.py index 986d8fc1ade..d1e986010ed 100644 --- a/readthedocs/proxito/views/hosting.py +++ b/readthedocs/proxito/views/hosting.py @@ -17,7 +17,7 @@ ProjectSerializer, VersionSerializer, ) -from readthedocs.builds.constants import LATEST +from readthedocs.builds.constants import EXTERNAL, LATEST from readthedocs.builds.models import Version from readthedocs.core.resolver import resolver from readthedocs.core.unresolver import UnresolverError, unresolver @@ -329,7 +329,12 @@ def _v0(self, project, version, build, filename, user): { # TODO: name this field "display_name" "slug": translation.language, - "url": f"/{translation.language}/", + "url": resolver.resolve( + project=project, + version_slug=version.slug, + language=translation.language, + external=version.type == EXTERNAL, + ), } for translation in project_translations ], @@ -337,7 +342,11 @@ def _v0(self, project, version, build, filename, user): { # TODO: name this field "display_name" "slug": version.slug, - "url": f"/{project.language}/{version.slug}/", + "url": resolver.resolve( + project=project, + version_slug=version.slug, + external=version.type == EXTERNAL, + ), } for version in versions_active_built_not_hidden ],