diff --git a/readthedocs/gold/models.py b/readthedocs/gold/models.py index 3fa2f20691c..386311ab4da 100644 --- a/readthedocs/gold/models.py +++ b/readthedocs/gold/models.py @@ -2,9 +2,11 @@ """Django models for recurring donations aka Gold Membership.""" import math +from datetime import datetime from django.db import models from django.utils.translation import ugettext_lazy as _ +import pytz from readthedocs.projects.models import Project @@ -27,6 +29,9 @@ class GoldUser(models.Model): """A user subscription for gold membership.""" + # Gold members created after this date can no longer sponsor projects to be ad-free + SPONSOR_PROJECT_CUTOFF = pytz.utc.localize(datetime(year=2019, month=5, day=1)) + pub_date = models.DateTimeField(_('Publication date'), auto_now_add=True) modified_date = models.DateTimeField(_('Modified date'), auto_now=True) @@ -61,3 +66,9 @@ def num_supported_projects(self): dollars = int(self.level.split('-')[-1]) num_projects = int(math.floor(dollars // DOLLARS_PER_PROJECT)) return num_projects + + def can_sponsor_projects(self): + if self.pub_date < self.SPONSOR_PROJECT_CUTOFF or self.projects.exists(): + return True + + return False diff --git a/readthedocs/gold/templates/gold/projects.html b/readthedocs/gold/templates/gold/projects.html index e832b53ee67..ea4f47924c1 100644 --- a/readthedocs/gold/templates/gold/projects.html +++ b/readthedocs/gold/templates/gold/projects.html @@ -11,6 +11,13 @@ {% block edit_content %} +

+ {% blocktrans trimmed %} + Note: this is a legacy feature. + New gold members cannot sponsor projects to be ad-free. + {% endblocktrans %} +

+

{% trans "Choose projects that will have all promos removed, and extra features added to them. You get to pick one for every $5/mo you support Read the Docs with." %}

@@ -24,17 +31,16 @@

{% trans "Existing Projects" %}

{% endblocktrans %}

- -

+

{% trans "Add a project" %}

diff --git a/readthedocs/gold/templates/gold/subscription_detail.html b/readthedocs/gold/templates/gold/subscription_detail.html index fe791753bfb..84c30961582 100644 --- a/readthedocs/gold/templates/gold/subscription_detail.html +++ b/readthedocs/gold/templates/gold/subscription_detail.html @@ -54,17 +54,19 @@

{% trans "Gold Subscription" %}

-

{% trans "Projects" %}

-

- {% blocktrans trimmed count projects=golduser.num_supported_projects %} - You can adopt one project with your subscription. - {% plural %} - You can adopt {{ projects }} projects with your subscription. - {% endblocktrans %} -

+ {% if golduser.can_sponsor_projects %} +

{% trans "Projects" %}

+

+ {% blocktrans trimmed count projects=golduser.num_supported_projects %} + You can adopt one project with your subscription. + {% plural %} + You can adopt {{ projects }} projects with your subscription. + {% endblocktrans %} +

-
- -
+
+ +
+ {% endif %} {% endblock %} diff --git a/readthedocs/gold/views.py b/readthedocs/gold/views.py index d5f0d6121c5..b37697c5da8 100644 --- a/readthedocs/gold/views.py +++ b/readthedocs/gold/views.py @@ -103,6 +103,10 @@ def projects(request): gold_user = get_object_or_404(GoldUser, user=request.user) gold_projects = gold_user.projects.all() + if not gold_user.can_sponsor_projects(): + messages.error(request, _('New gold users are no longer allowed to sponsor projects')) + return HttpResponseRedirect(reverse('gold_detail')) + if request.method == 'POST': form = GoldProjectForm( active_user=request.user, diff --git a/readthedocs/rtd_tests/tests/test_gold.py b/readthedocs/rtd_tests/tests/test_gold.py index b52ec2938ae..640ea3259fb 100644 --- a/readthedocs/rtd_tests/tests/test_gold.py +++ b/readthedocs/rtd_tests/tests/test_gold.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from datetime import timedelta + from django.test import TestCase from django.urls import reverse from django_dynamic_fixture import fixture, get @@ -15,7 +17,12 @@ def setUp(self): self.project = get(Project, slug='test', users=[fixture(), self.user]) - self.golduser = get(GoldUser, user=self.user, level=LEVEL_CHOICES[0][0]) + self.golduser = get( + GoldUser, + user=self.user, + level=LEVEL_CHOICES[0][0], + pub_date=GoldUser.SPONSOR_PROJECT_CUTOFF - timedelta(days=1), + ) self.client.login(username='owner', password='test') @@ -25,6 +32,22 @@ def test_adding_projects(self): self.assertEqual(self.golduser.projects.count(), 1) self.assertEqual(resp.status_code, 302) + def test_adding_projects_after_cutoff(self): + user = create_user(username='testuser', password='testtest') + self.client.login(username='testuser', password='testtest') + after_cutoff_golduser = get( + GoldUser, + user=user, + level=LEVEL_CHOICES[0][0], + pub_date=GoldUser.SPONSOR_PROJECT_CUTOFF + timedelta(days=1), + ) + self.assertEqual(after_cutoff_golduser.projects.count(), 0) + + # Ensure no gold project is created + resp = self.client.post(reverse('gold_projects'), data={'project': 'test'}) + self.assertEqual(after_cutoff_golduser.projects.count(), 0) + self.assertEqual(resp.status_code, 302) + def test_too_many_projects(self): self.project2 = get(Project, slug='test2') diff --git a/readthedocs/templates/projects/project_advertising.html b/readthedocs/templates/projects/project_advertising.html index 68e0d981627..d22389f72ef 100644 --- a/readthedocs/templates/projects/project_advertising.html +++ b/readthedocs/templates/projects/project_advertising.html @@ -68,8 +68,8 @@

{% trans "Opting out" %}

  • {% blocktrans trimmed %} If you have an open source project, and can contribute financially, - consider a gold subscription. Gold subscribers can disable ads for - projects they author. + consider a gold subscription. Gold members have an ad-free + experience while using Read the Docs. {% endblocktrans %}