Skip to content

Commit 28d1ea3

Browse files
authored
Proxito: make use un project from unresolved_domain in some views (#10029)
These views need only the project from the unresolved domain, they don't capture a project slug from the URL or anything related.
1 parent 0912c0c commit 28d1ea3

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

readthedocs/proxito/views/serve.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from readthedocs.redirects.exceptions import InfiniteRedirectException
2525
from readthedocs.storage import build_media_storage
2626

27-
from .decorators import map_project_slug
2827
from .mixins import (
2928
InvalidPathError,
3029
ServeDocsMixin,
@@ -437,16 +436,15 @@ class ServeError404(SettingsOverrideObject):
437436

438437
class ServeRobotsTXTBase(ServeDocsMixin, View):
439438

440-
@method_decorator(map_project_slug)
441439
@method_decorator(cache_page(60 * 60)) # 1 hour
442-
def get(self, request, project):
440+
def get(self, request):
443441
"""
444442
Serve custom user's defined ``/robots.txt``.
445443
446444
If the user added a ``robots.txt`` in the "default version" of the
447445
project, we serve it directly.
448446
"""
449-
447+
project = request.unresolved_domain.project
450448
# Verify if the project is marked as spam and return a custom robots.txt
451449
if 'readthedocsext.spamfighting' in settings.INSTALLED_APPS:
452450
from readthedocsext.spamfighting.utils import is_robotstxt_denied # noqa
@@ -527,9 +525,8 @@ class ServeRobotsTXT(SettingsOverrideObject):
527525

528526
class ServeSitemapXMLBase(View):
529527

530-
@method_decorator(map_project_slug)
531528
@method_decorator(cache_page(60 * 60 * 12)) # 12 hours
532-
def get(self, request, project):
529+
def get(self, request):
533530
"""
534531
Generate and serve a ``sitemap.xml`` for a particular ``project``.
535532
@@ -587,6 +584,7 @@ def changefreqs_generator():
587584
changefreqs = ['weekly', 'daily']
588585
yield from itertools.chain(changefreqs, itertools.repeat('monthly'))
589586

587+
project = request.unresolved_domain.project
590588
public_versions = Version.internal.public(
591589
project=project,
592590
only_active=True,
@@ -673,12 +671,7 @@ class ServeStaticFiles(CDNCacheControlMixin, CDNCacheTagsMixin, ServeDocsMixin,
673671

674672
project_cache_tag = "rtd-staticfiles"
675673

676-
@method_decorator(map_project_slug)
677-
def get(self, request, filename, project):
678-
# This is needed for the _get_project
679-
# method for the CDNCacheTagsMixin class.
680-
self.project = project
681-
674+
def get(self, request, filename):
682675
try:
683676
return self._serve_static_file(request=request, filename=filename)
684677
except InvalidPathError:
@@ -700,7 +693,8 @@ def _get_cache_tags(self):
700693
return tags
701694

702695
def _get_project(self):
703-
return getattr(self, "project", None)
696+
# Method used by the CDNCacheTagsMixin class.
697+
return self.request.unresolved_domain.project
704698

705699
def _get_version(self):
706700
# This view isn't attached to a version.

0 commit comments

Comments
 (0)