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

Gold project sponsorship changes #5628

Merged
merged 2 commits into from
May 10, 2019
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
11 changes: 11 additions & 0 deletions readthedocs/gold/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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):
davidfischer marked this conversation as resolved.
Show resolved Hide resolved
if self.pub_date < self.SPONSOR_PROJECT_CUTOFF or self.projects.exists():
return True

return False
28 changes: 17 additions & 11 deletions readthedocs/gold/templates/gold/projects.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

{% block edit_content %}

<p class="empty">
{% blocktrans trimmed %}
<strong>Note:</strong> this is a legacy feature.
New gold members cannot sponsor projects to be ad-free.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't feel good to me to expose this to new gold users.

I'm not sure what's best here, but maybe removing this page completely for new gold users is better, instead of showing them that they could have sponsored their projects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on the fence about whether to include it, but I do think we should probably prompt them to email us here about removing ads if they want as well. Or perhaps some other messaging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't feel good to me to expose this to new gold users.

The page is removed for new gold users. New users will be redirected. This message is shown only to older gold users to let them know that we no longer do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! 💯

{% endblocktrans %}
</p>

<p class="help_text">
{% 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." %}
</p>
Expand All @@ -24,17 +31,16 @@ <h3> {% trans "Existing Projects" %} </h3>
{% endblocktrans %}
</p>

<ul>
{% for project in projects %}
<li>
<a href="{{ project.get_absolute_url }}">
{{ project }}
</a>
(<a href="{% url "gold_projects_remove" project.slug %}">{% trans "Remove" %}</a>)
</li>
{% endfor %}
</ul>
</p>
<ul>
{% for project in projects %}
<li>
<a href="{{ project.get_absolute_url }}">
{{ project }}
</a>
(<a href="{% url "gold_projects_remove" project.slug %}">{% trans "Remove" %}</a>)
</li>
{% endfor %}
</ul>

<h3>{% trans "Add a project" %}</h3>
<p>
Expand Down
24 changes: 13 additions & 11 deletions readthedocs/gold/templates/gold/subscription_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,19 @@ <h2>{% trans "Gold Subscription" %}</h2>
<button>{% trans "Cancel Subscription" %}</button>
</form>

<h3>{% trans "Projects" %}</h3>
<p class="subscription-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 %}
</p>
{% if golduser.can_sponsor_projects %}
<h3>{% trans "Projects" %}</h3>
<p class="subscription-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 %}
</p>

<form method="get" action="{% url "gold_projects" %}" class="subscription-projects">
<button>{% trans "Select Projects" %}</button>
</form>
<form method="get" action="{% url "gold_projects" %}" class="subscription-projects">
<button>{% trans "Select Projects" %}</button>
</form>
{% endif %}
</div>
{% endblock %}
4 changes: 4 additions & 0 deletions readthedocs/gold/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 24 additions & 1 deletion readthedocs/rtd_tests/tests/test_gold.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')

Expand All @@ -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')

Expand Down
4 changes: 2 additions & 2 deletions readthedocs/templates/projects/project_advertising.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ <h4>{% trans "Opting out" %}</h4>
<li class="module-item">
{% 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 %}

<form method="get" action="{% url "gold_subscription" %}">
Expand Down