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 7 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
9 changes: 8 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",
"tooltips_enabled",
"tooltips_root_selector",
"tooltips_doctool_name",
"tooltips_doctool_version",
"notifications_enabled",
"notifications_show_on_latest",
"notifications_show_on_non_stable",
Expand All @@ -677,7 +681,10 @@ class Meta:
}
widgets = {
"doc_diff_root_selector": forms.TextInput(
attrs={"placeholder": "[role=main]"}
attrs={"placeholder": AddonsConfig.DOC_DIFF_DEFAULT_ROOT_SELECTOR}
),
"tooltips_root_selector": forms.TextInput(
attrs={"placeholder": AddonsConfig.TOOLTIPS_DEFAULT_ROOT_SELECTOR}
),
}

Expand Down
55 changes: 55 additions & 0 deletions readthedocs/projects/migrations/0131_addons_tooltips_fields.py
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='tooltips_doctool_name',
field=models.CharField(blank=True, choices=[('sphinx', 'Sphinx'), ('other', 'Other')], max_length=128, null=True),
),
migrations.AddField(
model_name='addonsconfig',
name='tooltips_doctool_version',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AddField(
model_name='addonsconfig',
name='tooltips_enabled',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='addonsconfig',
name='tooltips_root_selector',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AddField(
model_name='historicaladdonsconfig',
name='tooltips_doctool_name',
field=models.CharField(blank=True, choices=[('sphinx', 'Sphinx'), ('other', 'Other')], max_length=128, null=True),
),
migrations.AddField(
model_name='historicaladdonsconfig',
name='tooltips_doctool_version',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AddField(
model_name='historicaladdonsconfig',
name='tooltips_enabled',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='historicaladdonsconfig',
name='tooltips_root_selector',
field=models.CharField(blank=True, max_length=128, null=True),
),
]
16 changes: 16 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]"
TOOLTIPS_DEFAULT_ROOT_SELECTOR = "[role=main] a.internal"
TOOLTIPS_DOCTOOL_NAME_CHOICES = (
("sphinx", "Sphinx"),
("other", "Other"),
)

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

# Tooltips
tooltips_enabled = models.BooleanField(default=False)
tooltips_root_selector = models.CharField(null=True, blank=True, max_length=128)
tooltips_doctool_name = models.CharField(
choices=TOOLTIPS_DOCTOOL_NAME_CHOICES,
null=True,
blank=True,
max_length=128,
)
tooltips_doctool_version = models.CharField(null=True, blank=True, max_length=128)


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": []
},
"tooltips": {
"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_tooltips(self):
addons = fixture.get(
AddonsConfig,
project=self.project,
)

addons.tooltips_enabled = True
addons.tooltips_root_selector = "[role=main] a"
addons.tooltips_doctool_name = "sphinx"
addons.tooltips_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"]["tooltips"] == 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,
},
"tooltips": {
"enabled": project.addons.tooltips_enabled,
"root_selector": project.addons.tooltips_root_selector
or project.addons.TOOLTIPS_DEFAULT_ROOT_SELECTOR,
"doctool": {
"name": project.addons.tooltips_doctool_name,
"version": project.addons.tooltips_doctool_version,
},
},
"hotkeys": {
"enabled": project.addons.hotkeys_enabled,
"doc_diff": {
Expand Down