Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addons: API response for tooltips #11746

Merged
merged 8 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,10 @@ class Meta:
"flyout_sorting_custom_pattern",
"hotkeys_enabled",
"search_enabled",
"linkpreviews_enabled",
"linkpreviews_root_selector",
"linkpreviews_doctool_name",
"linkpreviews_doctool_version",
"notifications_enabled",
"notifications_show_on_latest",
"notifications_show_on_non_stable",
Expand All @@ -674,10 +678,17 @@ class Meta:
"Show a notification on non-stable versions"
),
"notifications_show_on_latest": _("Show a notification on latest version"),
"linkpreviews_enabled": _("Enabled"),
"linkpreviews_root_selector": _("Root selector"),
"linkpreviews_doctool_name": _("Documentation tool name"),
"linkpreviews_doctool_version": _("Documentation tool version"),
}
widgets = {
"doc_diff_root_selector": forms.TextInput(
attrs={"placeholder": "[role=main]"}
attrs={"placeholder": AddonsConfig.DOC_DIFF_DEFAULT_ROOT_SELECTOR}
),
"linkpreviews_root_selector": forms.TextInput(
attrs={"placeholder": AddonsConfig.LINKPREVIEWS_DEFAULT_ROOT_SELECTOR}
),
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Generated by Django 4.2.16 on 2024-11-06 09:18

from django.db import migrations, models
from django_safemigrate import Safe


class Migration(migrations.Migration):
safe = Safe.before_deploy

dependencies = [
('projects', '0130_addons_remove_old_fields'),
]

operations = [
migrations.AddField(
model_name='addonsconfig',
name='linkpreviews_doctool_name',
field=models.CharField(blank=True, choices=[('sphinx', 'Sphinx'), ('other', 'Other')], max_length=128, null=True),
),
migrations.AddField(
model_name='addonsconfig',
name='linkpreviews_doctool_version',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AddField(
model_name='addonsconfig',
name='linkpreviews_enabled',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='addonsconfig',
name='linkpreviews_root_selector',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AddField(
model_name='historicaladdonsconfig',
name='linkpreviews_doctool_name',
field=models.CharField(blank=True, choices=[('sphinx', 'Sphinx'), ('other', 'Other')], max_length=128, null=True),
),
migrations.AddField(
model_name='historicaladdonsconfig',
name='linkpreviews_doctool_version',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AddField(
model_name='historicaladdonsconfig',
name='linkpreviews_enabled',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='historicaladdonsconfig',
name='linkpreviews_root_selector',
field=models.CharField(blank=True, max_length=128, null=True),
),
]
20 changes: 20 additions & 0 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class AddonsConfig(TimeStampedModel):
"""

DOC_DIFF_DEFAULT_ROOT_SELECTOR = "[role=main]"
LINKPREVIEWS_DEFAULT_ROOT_SELECTOR = "[role=main] a.internal"
LINKPREVIEWS_DOCTOOL_NAME_CHOICES = (
("sphinx", "Sphinx"),
("other", "Other"),
)

# Model history
history = ExtraHistoricalRecords()
Expand Down Expand Up @@ -218,6 +223,21 @@ class AddonsConfig(TimeStampedModel):
notifications_show_on_non_stable = models.BooleanField(default=True)
notifications_show_on_external = models.BooleanField(default=True)

# Link Previews
linkpreviews_enabled = models.BooleanField(default=False)
linkpreviews_root_selector = models.CharField(null=True, blank=True, max_length=128)
linkpreviews_doctool_name = models.CharField(
choices=LINKPREVIEWS_DOCTOOL_NAME_CHOICES,
null=True,
blank=True,
max_length=128,
)
linkpreviews_doctool_version = models.CharField(
null=True,
blank=True,
max_length=128,
)

Comment on lines +229 to +240
Copy link
Member

@ericholscher ericholscher Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we planning to auto-fill this via the build config or something? Feels odd that users would have to define this in multiple places. In particular a version number feels super weird to have to keep updated, and definitely won't be modified by the user in any ongoing way.


class AddonSearchFilter(TimeStampedModel):

Expand Down
8 changes: 8 additions & 0 deletions readthedocs/proxito/tests/responses/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@
"enabled": true,
"default_filter": "project:project/latest",
"filters": []
},
"linkpreviews": {
"enabled": false,
"root_selector": "[role=main] a.internal",
"doctool": {
"name": null,
"version": null
}
}
}
}
36 changes: 36 additions & 0 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,42 @@ def test_custom_domain_url(self):
== "https://docs.example.com/en/latest/"
)

def test_linkpreviews(self):
addons = fixture.get(
AddonsConfig,
project=self.project,
)

addons.linkpreviews_enabled = True
addons.linkpreviews_root_selector = "[role=main] a"
addons.linkpreviews_doctool_name = "sphinx"
addons.linkpreviews_doctool_version = "8.0.1"
addons.save()

r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{
"api-version": "1.0.0",
"client-version": "0.6.0",
"url": "https://project.dev.readthedocs.io/en/latest/",
},
secure=True,
headers={
"host": "project.dev.readthedocs.io",
},
)
expected = {
"enabled": True,
"root_selector": "[role=main] a",
"doctool": {
"name": "sphinx",
"version": "8.0.1",
},
}

assert r.status_code == 200
assert r.json()["addons"]["linkpreviews"] == expected

def test_non_existent_project(self):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
Expand Down
9 changes: 9 additions & 0 deletions readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,15 @@ def _v1(self, project, version, build, filename, url, request):
if version
else None,
},
"linkpreviews": {
"enabled": project.addons.linkpreviews_enabled,
"root_selector": project.addons.linkpreviews_root_selector
or project.addons.LINKPREVIEWS_DEFAULT_ROOT_SELECTOR,
"doctool": {
"name": project.addons.linkpreviews_doctool_name,
"version": project.addons.linkpreviews_doctool_version,
},
},
"hotkeys": {
"enabled": project.addons.hotkeys_enabled,
"doc_diff": {
Expand Down