Skip to content

Commit 32043d2

Browse files
authored
Addons: return ethicalads data on /_/addons/ endpoint (#10534)
* Addons: return `ethicalads` data on `/_/addons/` endpoint This data is consumed by the sponsorship addons to display an ad using EthicalAds. Related readthedocs/addons#67 * Addons: return whether or not EthicalAd is enabled * Lint: avoid `prospector` failing because missing import `prospector` doesn't have access to this repository because it's private. So, we are skipping the check for this line. * Sponsorship: comment explaining the required setting
1 parent 9fb226e commit 32043d2

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

readthedocs/proxito/views/hosting.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import packaging
44
import structlog
55
from django.conf import settings
6+
from django.contrib.auth.models import AnonymousUser
67
from django.http import Http404, JsonResponse
78
from django.views import View
89

@@ -296,6 +297,32 @@ def _v0(self, project, version, build, filename):
296297
if version and version.build_data:
297298
data.update(version.build_data)
298299

300+
# Update this data with ethicalads
301+
if "readthedocsext.donate" in settings.INSTALLED_APPS:
302+
from readthedocsext.donate.utils import ( # noqa
303+
get_campaign_types,
304+
get_project_keywords,
305+
get_publisher,
306+
is_ad_free_project,
307+
is_ad_free_user,
308+
)
309+
310+
data["addons"].update(
311+
{
312+
"ethicalads": {
313+
"enabled": True,
314+
# NOTE: this endpoint is not authenticated, the user checks are done over an annonymous user for now
315+
#
316+
# NOTE: it requires ``settings.USE_PROMOS=True`` to return ``ad_free=false`` here
317+
"ad_free": is_ad_free_user(AnonymousUser())
318+
or is_ad_free_project(project),
319+
"campaign_types": get_campaign_types(AnonymousUser(), project),
320+
"keywords": get_project_keywords(project),
321+
"publisher": get_publisher(project),
322+
},
323+
}
324+
)
325+
299326
return data
300327

301328
def _v1(self, project, version, build, filename):

0 commit comments

Comments
 (0)