Skip to content

Proxito: always check 404/index.hmtml #9983

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 8 commits into from
Feb 7, 2023
25 changes: 5 additions & 20 deletions readthedocs/proxito/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from readthedocs.core.resolver import resolve_path
from readthedocs.core.utils.extend import SettingsOverrideObject
from readthedocs.projects import constants
from readthedocs.projects.constants import SPHINX_HTMLDIR
from readthedocs.projects.models import Feature
from readthedocs.projects.templatetags.projects_tags import sort_version_aware
from readthedocs.redirects.exceptions import InfiniteRedirectException
Expand Down Expand Up @@ -347,24 +346,14 @@ def get(self, request, proxito_path, template_name='404.html'):
# If that doesn't work, attempt to serve the 404 of the current version (version_slug)
# Secondly, try to serve the 404 page for the default version
# (project.get_default_version())
version = (
Version.objects.filter(project=final_project, slug=version_slug)
.only("documentation_type")
.first()
)
versions = []
if version:
versions.append((version.slug, version.documentation_type))
if Version.objects.filter(project=final_project, slug=version_slug).exists():
versions.append(version_slug)
default_version_slug = final_project.get_default_version()
if default_version_slug != version_slug:
default_version_doc_type = (
Version.objects.filter(project=final_project, slug=default_version_slug)
.values_list('documentation_type', flat=True)
.first()
)
versions.append((default_version_slug, default_version_doc_type))
versions.append(default_version_slug)

for version_slug_404, doc_type_404 in versions:
for version_slug_404 in versions:
if not self.allowed_user(request, final_project, version_slug_404):
continue

Expand All @@ -374,11 +363,7 @@ def get(self, request, proxito_path, template_name='404.html'):
include_file=False,
version_type=self.version_type,
)
tryfiles = ['404.html']
# SPHINX_HTMLDIR is the only builder
# that could output a 404/index.html file.
if doc_type_404 == SPHINX_HTMLDIR:
tryfiles.append('404/index.html')
tryfiles = ["404.html", "404/index.html"]
for tryfile in tryfiles:
storage_filename_path = build_media_storage.join(storage_root_path, tryfile)
if build_media_storage.exists(storage_filename_path):
Expand Down