Skip to content

Addons: return ethicalads data on /_/addons/ endpoint #10534

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

Merged
merged 4 commits into from
Jul 12, 2023
Merged
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
27 changes: 27 additions & 0 deletions readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import packaging
import structlog
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.http import Http404, JsonResponse
from django.views import View

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

# Update this data with ethicalads
if "readthedocsext.donate" in settings.INSTALLED_APPS:
from readthedocsext.donate.utils import ( # noqa
get_campaign_types,
get_project_keywords,
get_publisher,
is_ad_free_project,
is_ad_free_user,
)

data["addons"].update(
{
"ethicalads": {
"enabled": True,
# NOTE: this endpoint is not authenticated, the user checks are done over an annonymous user for now
#
# NOTE: it requires ``settings.USE_PROMOS=True`` to return ``ad_free=false`` here
"ad_free": is_ad_free_user(AnonymousUser())
or is_ad_free_project(project),
"campaign_types": get_campaign_types(AnonymousUser(), project),
"keywords": get_project_keywords(project),
"publisher": get_publisher(project),
},
}
)

return data

def _v1(self, project, version, build, filename):
Expand Down