Skip to content

Commit fdcb280

Browse files
committed
Addons: prepare Proxito and dashboard to enable them by default
Prepare Proxito's code and dashboard to enable addons by default starting on October 7th, as planned: https://about.readthedocs.com/blog/2024/07/addons-by-default/ Note this code is temporary and can be deployed _before_ reaching that particular date. The idea is to remove this code once this behavior becomes the default. Related #11474
1 parent b902983 commit fdcb280

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

readthedocs/projects/forms.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
"""Project forms."""
22

3+
import datetime
34
import json
45
from random import choice
56
from re import fullmatch
67
from urllib.parse import urlparse
78

9+
import pytz
810
from allauth.socialaccount.models import SocialAccount
911
from django import forms
1012
from django.conf import settings
1113
from django.contrib.auth.models import User
1214
from django.db.models import Q
1315
from django.urls import reverse
16+
from django.utils import timezone
1417
from django.utils.translation import gettext_lazy as _
1518

1619
from readthedocs.builds.constants import INTERNAL
@@ -662,14 +665,23 @@ class Meta:
662665

663666
def __init__(self, *args, **kwargs):
664667
self.project = kwargs.pop("project", None)
668+
669+
tzinfo = pytz.timezone("America/Los_Angeles")
670+
addons_enabled_by_default = timezone.now() > datetime.datetime(
671+
2024, 10, 7, 0, 0, 0, tzinfo=tzinfo
672+
)
673+
665674
addons, created = AddonsConfig.objects.get_or_create(project=self.project)
666675
if created:
667-
addons.enabled = False
676+
addons.enabled = addons_enabled_by_default
668677
addons.save()
669678

670679
kwargs["instance"] = addons
671680
super().__init__(*args, **kwargs)
672681

682+
if addons_enabled_by_default:
683+
self.fields.pop("enabled")
684+
673685
def clean(self):
674686
if (
675687
self.cleaned_data["flyout_sorting"] == ADDONS_FLYOUT_SORTING_CUSTOM_PATTERN

readthedocs/proxito/middleware.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
unresolver,
3232
)
3333
from readthedocs.core.utils import get_cache_tag
34-
from readthedocs.projects.models import Project
34+
from readthedocs.projects.models import Feature, Project
3535
from readthedocs.proxito.cache import add_cache_tags, cache_response, private_response
3636
from readthedocs.proxito.redirects import redirect_to_https
3737

@@ -289,11 +289,19 @@ def add_hosting_integrations_headers(self, request, response):
289289
version_slug = getattr(request, "path_version_slug", "")
290290

291291
if project_slug:
292+
# TODO: update this code once DISABLE_SPHINX_MANIPULATION and addons becomes the default
293+
# https://about.readthedocs.com/blog/2024/07/addons-by-default/
294+
disable_sphinx_manipulation_enabled = Feature.objects.filter(
295+
feature_id=Feature.DISABLE_SPHINX_MANIPULATION,
296+
projects__slug=Project.objects.filter(slug=project_slug).first(),
297+
).exists()
298+
292299
force_addons = Project.objects.filter(
293300
slug=project_slug,
294301
addons__enabled=True,
295302
).exists()
296-
if force_addons:
303+
304+
if force_addons or disable_sphinx_manipulation_enabled:
297305
response["X-RTD-Force-Addons"] = "true"
298306
return
299307

0 commit comments

Comments
 (0)