|
5 | 5 |
|
6 | 6 | Additional processing is done to get the project from the URL in the ``views.py`` as well.
|
7 | 7 | """
|
| 8 | +import datetime |
8 | 9 | import re
|
9 | 10 | from urllib.parse import urlparse
|
10 | 11 |
|
| 12 | +import pytz |
11 | 13 | import structlog
|
12 | 14 | from corsheaders.middleware import (
|
13 | 15 | ACCESS_CONTROL_ALLOW_METHODS,
|
|
17 | 19 | from django.core.exceptions import SuspiciousOperation
|
18 | 20 | from django.shortcuts import redirect
|
19 | 21 | from django.urls import reverse
|
| 22 | +from django.utils import timezone |
20 | 23 | from django.utils.deprecation import MiddlewareMixin
|
21 | 24 | from django.utils.encoding import iri_to_uri
|
22 | 25 | from django.utils.html import escape
|
|
31 | 34 | unresolver,
|
32 | 35 | )
|
33 | 36 | from readthedocs.core.utils import get_cache_tag
|
34 |
| -from readthedocs.projects.models import Project |
| 37 | +from readthedocs.projects.models import Feature, Project |
35 | 38 | from readthedocs.proxito.cache import add_cache_tags, cache_response, private_response
|
36 | 39 | from readthedocs.proxito.redirects import redirect_to_https
|
37 | 40 |
|
@@ -289,23 +292,51 @@ def add_hosting_integrations_headers(self, request, response):
|
289 | 292 | version_slug = getattr(request, "path_version_slug", "")
|
290 | 293 |
|
291 | 294 | if project_slug:
|
292 |
| - force_addons = Project.objects.filter( |
293 |
| - slug=project_slug, |
294 |
| - addons__enabled=True, |
295 |
| - ).exists() |
296 |
| - if force_addons: |
297 |
| - response["X-RTD-Force-Addons"] = "true" |
298 |
| - return |
299 |
| - |
300 |
| - if version_slug: |
301 |
| - addons = Version.objects.filter( |
302 |
| - project__slug=project_slug, |
303 |
| - slug=version_slug, |
304 |
| - addons=True, |
| 295 | + tzinfo = pytz.timezone("America/Los_Angeles") |
| 296 | + addons_enabled_by_default = timezone.now() > datetime.datetime( |
| 297 | + 2024, |
| 298 | + 10, |
| 299 | + 7, |
| 300 | + 0, |
| 301 | + 0, |
| 302 | + 0, |
| 303 | + tzinfo=tzinfo, |
| 304 | + ) |
| 305 | + if addons_enabled_by_default: |
| 306 | + addons = Project.objects.filter( |
| 307 | + slug=project_slug, addons__enabled=True |
| 308 | + ).exists() |
| 309 | + |
| 310 | + if addons: |
| 311 | + response["X-RTD-Force-Addons"] = "true" |
| 312 | + return |
| 313 | + |
| 314 | + else: |
| 315 | + # TODO: remove "else" code once DISABLE_SPHINX_MANIPULATION and addons becomes the default |
| 316 | + # https://about.readthedocs.com/blog/2024/07/addons-by-default/ |
| 317 | + disable_sphinx_manipulation_enabled = Feature.objects.filter( |
| 318 | + feature_id=Feature.DISABLE_SPHINX_MANIPULATION, |
| 319 | + projects__slug=Project.objects.filter(slug=project_slug).first(), |
305 | 320 | ).exists()
|
306 | 321 |
|
307 |
| - if addons: |
308 |
| - response["X-RTD-Hosting-Integrations"] = "true" |
| 322 | + force_addons = Project.objects.filter( |
| 323 | + slug=project_slug, |
| 324 | + addons__enabled=True, |
| 325 | + ).exists() |
| 326 | + |
| 327 | + if force_addons or disable_sphinx_manipulation_enabled: |
| 328 | + response["X-RTD-Force-Addons"] = "true" |
| 329 | + return |
| 330 | + |
| 331 | + if version_slug: |
| 332 | + addons = Version.objects.filter( |
| 333 | + project__slug=project_slug, |
| 334 | + slug=version_slug, |
| 335 | + addons=True, |
| 336 | + ).exists() |
| 337 | + |
| 338 | + if addons: |
| 339 | + response["X-RTD-Hosting-Integrations"] = "true" |
309 | 340 |
|
310 | 341 | def add_cors_headers(self, request, response):
|
311 | 342 | """
|
|
0 commit comments