start unlimited aliases for premium subscribers
This commit is contained in:
Родитель
dcd3603b6f
Коммит
009bbcee40
10
.env-dist
10
.env-dist
|
@ -1,7 +1,7 @@
|
|||
ON_HEROKU=False
|
||||
FXA_OAUTH_ENDPOINT=https://oauth-stable.dev.lcip.org/v1
|
||||
FXA_PROFILE_ENDPOINT=https://stable.dev.lcip.org/profile/v1
|
||||
FXA_SETTINGS_URL=https://stable.dev.lcip.org/settings
|
||||
FXA_OAUTH_ENDPOINT=https://oauth.stage.mozaws.net/v1
|
||||
FXA_PROFILE_ENDPOINT=https://profile.stage.mozaws.net/v1
|
||||
FXA_SETTINGS_URL=https://accounts.stage.mozaws.net/settings
|
||||
GOOGLE_ANALYTICS_ID="UA-77033033-33"
|
||||
SECRET_KEY=unsafe-secret-key-for-dev-envs
|
||||
ADMIN_ENABLED=
|
||||
|
@ -24,3 +24,7 @@ MAX_NUM_FREE_ALIASES=5
|
|||
TWILIO_ACCOUNT_SID=
|
||||
TWILIO_AUTH_TOKEN=
|
||||
TWILIO_SERVICE_ID=
|
||||
PREMIUM_ENABLED=True
|
||||
PREMIUM_PROD_ID=prod_IyCWnXUbkYjDgL
|
||||
PREMIUM_PRICE_ID=price_1IMG7KKb9q6OnNsL15Hsn1HE
|
||||
SUBSCRIPTIONS_WITH_UNLIMITED="monitor-unlimited,mozilla-one,guardian_vpn"
|
||||
|
|
|
@ -83,6 +83,27 @@ class Profile(models.Model):
|
|||
return self.last_soft_bounce
|
||||
return None
|
||||
|
||||
@property
|
||||
def at_max_free_aliases(self):
|
||||
relay_addresses_count = RelayAddress.objects.filter(
|
||||
user=self.user
|
||||
).count()
|
||||
return relay_addresses_count >= settings.MAX_NUM_FREE_ALIASES
|
||||
|
||||
@property
|
||||
def has_unlimited(self):
|
||||
social_account = self.user.socialaccount_set.filter(
|
||||
provider='fxa'
|
||||
).first()
|
||||
if not social_account:
|
||||
return False
|
||||
fxa_profile_data = social_account.extra_data
|
||||
for sub in settings.SUBSCRIPTIONS_WITH_UNLIMITED.split(','):
|
||||
if sub in fxa_profile_data.get('subscriptions', []):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def address_default():
|
||||
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=9))
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
from datetime import datetime, timedelta, timezone
|
||||
from hashlib import sha256
|
||||
import random
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
|
||||
from allauth.socialaccount.models import SocialAccount
|
||||
|
||||
from model_bakery import baker
|
||||
|
||||
from ..models import (
|
||||
|
@ -224,3 +227,20 @@ class ProfileTest(TestCase):
|
|||
self.profile.save()
|
||||
|
||||
assert self.profile.last_bounce_date == self.profile.last_hard_bounce
|
||||
|
||||
def test_has_unlimited_default_False(self):
|
||||
assert self.profile.has_unlimited == False
|
||||
|
||||
def test_has_unlimited_with_unlimited_subsription_returns_True(self):
|
||||
premium_user = baker.make(User)
|
||||
random_sub = random.choice(
|
||||
settings.SUBSCRIPTIONS_WITH_UNLIMITED.split(',')
|
||||
)
|
||||
socialaccount = baker.make(
|
||||
SocialAccount,
|
||||
user=premium_user,
|
||||
provider='fxa',
|
||||
extra_data={'subscriptions': [random_sub]}
|
||||
)
|
||||
premium_profile = baker.make(Profile, user=premium_user)
|
||||
assert premium_profile.has_unlimited == True
|
||||
|
|
|
@ -85,11 +85,13 @@ def _index_POST(request):
|
|||
locked_profile = Profile.objects.select_for_update().get(
|
||||
user=user_profile.user
|
||||
)
|
||||
if locked_profile.num_active_address >= settings.MAX_NUM_FREE_ALIASES:
|
||||
if locked_profile.at_max_free_aliases and not locked_profile.has_unlimited:
|
||||
if not settings.SITE_ORIGIN in request.headers.get('Origin', ''):
|
||||
return HttpResponse('Payment Required', status=402)
|
||||
messages.error(
|
||||
request, "You already have 5 email addresses. Please upgrade."
|
||||
request,
|
||||
"You already have %s email addresses. Please upgrade." %
|
||||
settings.MAX_NUM_FREE_ALIASES
|
||||
)
|
||||
return redirect('profile')
|
||||
relay_address = RelayAddress.make_relay_address(locked_profile.user)
|
||||
|
|
|
@ -218,6 +218,12 @@ TEMPLATES = [
|
|||
]
|
||||
|
||||
MAX_NUM_FREE_ALIASES = config('MAX_NUM_FREE_ALIASES', 5, cast=int)
|
||||
PREMIUM_ENABLED = config('PREMIUM_ENABLED', default=False, cast=bool)
|
||||
PREMIUM_PROD_ID = config('PREMIUM_PROD_ID', '', cast=str)
|
||||
PREMIUM_PRICE_ID = config('PREMIUM_PRICE_ID', '', cast=str)
|
||||
SUBSCRIPTIONS_WITH_UNLIMITED = config(
|
||||
'SUBSCRIPTIONS_WITH_UNLIMITED', default=[]
|
||||
)
|
||||
|
||||
SOFT_BOUNCE_ALLOWED_DAYS = config('SOFT_BOUNCE_ALLOWED_DAYS', 1, cast=int)
|
||||
HARD_BOUNCE_ALLOWED_DAYS = config('HARD_BOUNCE_ALLOWED_DAYS', 30, cast=int)
|
||||
|
|
|
@ -4,5 +4,14 @@
|
|||
|
||||
<span class="remaining-aliases flx">
|
||||
<span class="num-remaining-aliases bold">
|
||||
{% remaining_free_aliases relay_addresses %}</span> remaining {% if relay_addresses|length == 4 %}alias{% else %} aliases {% endif %}
|
||||
{% with request.user.profile_set.first as user_profile %}
|
||||
{% if user_profile.has_unlimited %}
|
||||
{{ relay_addresses|length }} aliases. You can make unlimited!
|
||||
{% else %}
|
||||
<p>{% remaining_free_aliases relay_addresses %}</span> remaining {% if relay_addresses|length == 4 %}alias{% else %} aliases {% endif %}</p>
|
||||
{% if settings.PREMIUM_ENABLED %}
|
||||
<a href="https://accounts.stage.mozaws.net/subscriptions/products/{{ settings.PREMIUM_PROD_ID }}?plan={{ settings.PREMIUM_PRICE_ID }}" target="_blank">Buy unlimited aliases</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</span>
|
||||
|
|
|
@ -39,19 +39,28 @@
|
|||
</div>
|
||||
<form action="/emails/" class="dash-create" method="POST">
|
||||
<input type="hidden" name="api_token" value="{{ user.profile_set.first.api_token }}">
|
||||
{% with request.user.profile_set.first as user_profile %}
|
||||
{% if user_profile.at_max_free_aliases and not user_profile.has_unlimited %}
|
||||
<button
|
||||
class="blue-btn-states dash-create-new-relay flx al-cntr jst-cntr {%if relay_addresses|length == settings.MAX_NUM_FREE_ALIASES %} btn-disabled {% endif %}"
|
||||
type="submit" value="Generate new alias" data-event-label="Create New Relay Alias"
|
||||
|
||||
{% if relay_addresses|length == settings.MAX_NUM_FREE_ALIASES %}
|
||||
title="You have reached the alias limit."
|
||||
{% else %}
|
||||
title="Generate new alias"
|
||||
{% endif %}
|
||||
class="blue-btn-states dash-create-new-relay flx al-cntr jst-cntr btn-disabled"
|
||||
title="You have reached the alias limit."
|
||||
type="submit"
|
||||
value="Generate new alias"
|
||||
data-event-label="Create New Relay Alias"
|
||||
>
|
||||
{% else %}
|
||||
<button
|
||||
class="blue-btn-states dash-create-new-relay flx al-cntr jst-cntr"
|
||||
title="Generate new alias"
|
||||
type="submit"
|
||||
value="Generate new alias"
|
||||
data-event-label="Create New Relay Alias"
|
||||
>
|
||||
{% endif %}
|
||||
<span class="generate-new-relay-icon"></span>
|
||||
<span class="generate-new-alias-text">Generate New Alias</span>
|
||||
</button>
|
||||
{% endwith %}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче