Skip to content

Commit

Permalink
Addons: prepare Proxito and dashboard to enable them by default
Browse files Browse the repository at this point in the history
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
  • Loading branch information
humitos committed Aug 5, 2024
1 parent b902983 commit fdcb280
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
14 changes: 13 additions & 1 deletion readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
"""Project forms."""

import datetime
import json
from random import choice
from re import fullmatch
from urllib.parse import urlparse

import pytz
from allauth.socialaccount.models import SocialAccount
from django import forms
from django.conf import settings
from django.contrib.auth.models import User
from django.db.models import Q
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from readthedocs.builds.constants import INTERNAL
Expand Down Expand Up @@ -662,14 +665,23 @@ class Meta:

def __init__(self, *args, **kwargs):
self.project = kwargs.pop("project", None)

tzinfo = pytz.timezone("America/Los_Angeles")
addons_enabled_by_default = timezone.now() > datetime.datetime(
2024, 10, 7, 0, 0, 0, tzinfo=tzinfo
)

addons, created = AddonsConfig.objects.get_or_create(project=self.project)
if created:
addons.enabled = False
addons.enabled = addons_enabled_by_default
addons.save()

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

if addons_enabled_by_default:
self.fields.pop("enabled")

def clean(self):
if (
self.cleaned_data["flyout_sorting"] == ADDONS_FLYOUT_SORTING_CUSTOM_PATTERN
Expand Down
12 changes: 10 additions & 2 deletions readthedocs/proxito/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
unresolver,
)
from readthedocs.core.utils import get_cache_tag
from readthedocs.projects.models import Project
from readthedocs.projects.models import Feature, Project
from readthedocs.proxito.cache import add_cache_tags, cache_response, private_response
from readthedocs.proxito.redirects import redirect_to_https

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

if project_slug:
# TODO: update this code once DISABLE_SPHINX_MANIPULATION and addons becomes the default
# https://about.readthedocs.com/blog/2024/07/addons-by-default/
disable_sphinx_manipulation_enabled = Feature.objects.filter(
feature_id=Feature.DISABLE_SPHINX_MANIPULATION,
projects__slug=Project.objects.filter(slug=project_slug).first(),
).exists()

force_addons = Project.objects.filter(
slug=project_slug,
addons__enabled=True,
).exists()
if force_addons:

if force_addons or disable_sphinx_manipulation_enabled:
response["X-RTD-Force-Addons"] = "true"
return

Expand Down

0 comments on commit fdcb280

Please sign in to comment.