Skip to content

Do not access database from builds to check ad-free #4387

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 1 commit into from
Jul 17, 2018
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
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/backends/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def generate_rtd_data(self, docs_dir, mkdocs_config):
'docroot': docs_dir,
'source_suffix': ".md",
'api_host': getattr(settings, 'PUBLIC_API_URL', 'https://readthedocs.org'),
'ad_free': self.project.ad_free or self.project.gold_owners.exists(),
'ad_free': not self.project.show_advertising,
'commit': self.version.project.vcs_repo(self.version.slug).commit,
'global_analytics_code': getattr(settings, 'GLOBAL_ANALYTICS_CODE', 'UA-17997319-1'),
'user_analytics_code': analytics_code,
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ context = {
'using_theme': (html_theme == "default"),
'new_theme': (html_theme == "sphinx_rtd_theme"),
'source_suffix': SUFFIX,
'ad_free': {% if project.gold_owners.exists or project.ad_free %}True{% else %}False{% endif %},
'ad_free': {% if project.show_advertising %}False{% else %}True{% endif %},
'user_analytics_code': '{{ project.analytics_code|default_if_none:'' }}',
'global_analytics_code': '{{ settings.GLOBAL_ANALYTICS_CODE }}',
'commit': {% if project.repo_type == 'git' %}'{{ commit|slice:"8" }}'{% else %}'{{ commit }}'{% endif %},
Expand Down
12 changes: 12 additions & 0 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,18 @@ def get_feature_value(self, feature, positive, negative):
"""
return positive if self.has_feature(feature) else negative

@property
def show_advertising(self):
"""
Whether this project is ad-free

:return: ``True`` if advertising should be shown and ``False`` otherwise
"""
if self.ad_free or self.gold_owners.exists():
return False

return True


class APIProject(Project):

Expand Down
7 changes: 6 additions & 1 deletion readthedocs/restapi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class ProjectAdminSerializer(ProjectSerializer):
slug_field='feature_id',
)

show_advertising = serializers.SerializerMethodField()

def get_show_advertising(self, obj):
return obj.show_advertising

class Meta(ProjectSerializer.Meta):
fields = ProjectSerializer.Meta.fields + (
'enable_epub_build',
Expand All @@ -62,7 +67,7 @@ class Meta(ProjectSerializer.Meta):
'features',
'has_valid_clone',
'has_valid_webhook',
'ad_free',
'show_advertising',
)


Expand Down
2 changes: 1 addition & 1 deletion readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,6 @@ def test_get_version_by_id(self):
'id': 18,
'active': True,
'project': {
'ad_free': False,
'analytics_code': None,
'canonical_url': 'http://readthedocs.org/docs/pip/en/latest/',
'cdn_enabled': False,
Expand All @@ -932,6 +931,7 @@ def test_get_version_by_id(self):
'repo': 'https://github.com/pypa/pip',
'repo_type': 'git',
'requirements_file': None,
'show_advertising': True,
'skip': False,
'slug': 'pip',
'suffix': '.rst',
Expand Down