diff --git a/readthedocs/projects/migrations/0135_addons_customscript.py b/readthedocs/projects/migrations/0135_addons_customscript.py new file mode 100644 index 00000000000..d82ab66cc0a --- /dev/null +++ b/readthedocs/projects/migrations/0135_addons_customscript.py @@ -0,0 +1,35 @@ +# Generated by Django 4.2.16 on 2024-11-13 13:34 + +from django.db import migrations, models +from django_safemigrate import Safe + + +class Migration(migrations.Migration): + safe = Safe.before_deploy + + dependencies = [ + ('projects', '0134_addons_load_when_embedded_notnull'), + ] + + operations = [ + migrations.AddField( + model_name='addonsconfig', + name='customscript_enabled', + field=models.BooleanField(default=False, null=True), + ), + migrations.AddField( + model_name='addonsconfig', + name='customscript_src', + field=models.CharField(blank=True, help_text='URL to a JavaScript file to inject at serve time', max_length=512, null=True), + ), + migrations.AddField( + model_name='historicaladdonsconfig', + name='customscript_enabled', + field=models.BooleanField(default=False, null=True), + ), + migrations.AddField( + model_name='historicaladdonsconfig', + name='customscript_src', + field=models.CharField(blank=True, help_text='URL to a JavaScript file to inject at serve time', max_length=512, null=True), + ), + ] diff --git a/readthedocs/projects/migrations/0136_addons_customscript_notnull.py b/readthedocs/projects/migrations/0136_addons_customscript_notnull.py new file mode 100644 index 00000000000..18ea9b495ac --- /dev/null +++ b/readthedocs/projects/migrations/0136_addons_customscript_notnull.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.16 on 2024-11-13 13:36 + +from django.db import migrations, models +from django_safemigrate import Safe + + +class Migration(migrations.Migration): + safe = Safe.after_deploy + + dependencies = [ + ('projects', '0135_addons_customscript'), + ] + + operations = [ + migrations.AlterField( + model_name='addonsconfig', + name='customscript_enabled', + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name='historicaladdonsconfig', + name='customscript_enabled', + field=models.BooleanField(default=False), + ), + ] diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py index d4d655ff0cb..285035f2a48 100644 --- a/readthedocs/projects/models.py +++ b/readthedocs/projects/models.py @@ -222,6 +222,18 @@ class AddonsConfig(TimeStampedModel): search_enabled = models.BooleanField(default=True) search_default_filter = models.CharField(null=True, blank=True, max_length=128) + # User JavaScript File + customscript_enabled = models.BooleanField(default=False) + + # This is a user-defined file that will be injected at serve time by our + # Cloudflare Worker if defined + customscript_src = models.CharField( + max_length=512, + null=True, + blank=True, + help_text="URL to a JavaScript file to inject at serve time", + ) + # Notifications notifications_enabled = models.BooleanField(default=True) notifications_show_on_latest = models.BooleanField(default=True) diff --git a/readthedocs/proxito/tests/responses/v1.json b/readthedocs/proxito/tests/responses/v1.json index 9739d2e614c..f6a293be783 100644 --- a/readthedocs/proxito/tests/responses/v1.json +++ b/readthedocs/proxito/tests/responses/v1.json @@ -164,6 +164,10 @@ "default_filter": "project:project/latest", "filters": [] }, + "customscript": { + "enabled": false, + "src": null + }, "linkpreviews": { "enabled": false, "root_selector": "[role=main] a.internal", diff --git a/readthedocs/proxito/views/hosting.py b/readthedocs/proxito/views/hosting.py index 3df2c3d37f6..b24cdcd4237 100644 --- a/readthedocs/proxito/views/hosting.py +++ b/readthedocs/proxito/views/hosting.py @@ -490,6 +490,10 @@ def _v1(self, project, version, build, filename, url, request): # "filepath": "/docs/index.rst", # }, }, + "customscript": { + "enabled": project.addons.customscript_enabled, + "src": project.addons.customscript_src, + }, "search": { "enabled": project.addons.search_enabled, # TODO: figure it out where this data comes from.