Skip to content

Support single version subprojects URLs to serve from Django #5690

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 5 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions readthedocs/core/urls/subdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
serve_docs,
name='docs_detail',
),

]

groups = [subdomain_urls]
Expand Down
17 changes: 16 additions & 1 deletion readthedocs/core/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,26 @@ def inner_view( # noqa
def redirect_project_slug(request, project, subproject): # pylint: disable=unused-argument
"""Handle / -> /en/latest/ directs on subdomains."""
urlparse_result = urlparse(request.get_full_path())

# When accessing docs.customdomain.org/projects/subproject/ and the
# ``subproject`` is a single-version, we don't have to redirect but to serve
# the index file instead.
if subproject and subproject.single_version:
try:
# HACK: this only affects corporate site and won't be hit on the
# community. This can be removed once the middleware incorporates
# more data or redirects happen outside this application
# See: https://github.com/rtfd/readthedocs.org/pull/5690
from readthedocsinc.core.views import serve_docs as corporate_serve_docs # noqa
return corporate_serve_docs(request, project, project.slug, subproject, subproject.slug)
except Exception:
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should log here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I added logs in both cases.


return HttpResponseRedirect(
resolve(
subproject or project,
query_params=urlparse_result.query,
)
),
)


Expand Down