do not send double subscription email (#1118)
* do not send double subscription email * remove unused import * remove unused test
This commit is contained in:
parent
90b767169b
commit
f6a7ee981a
|
@ -1,15 +1,13 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from arrow import Arrow
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
||||
from flask import url_for
|
||||
from newrelic import agent
|
||||
from typing import Optional
|
||||
|
||||
from app import config
|
||||
from arrow import Arrow
|
||||
from newrelic import agent
|
||||
|
||||
from app.db import Session
|
||||
from app.email_utils import send_email_at_most_times, send_welcome_email, render
|
||||
from app.email_utils import send_welcome_email
|
||||
from app.errors import AccountAlreadyLinkedToAnotherPartnerException
|
||||
from app.log import LOG
|
||||
from app.models import (
|
||||
|
@ -17,10 +15,7 @@ from app.models import (
|
|||
Partner,
|
||||
PartnerUser,
|
||||
User,
|
||||
AppleSubscription,
|
||||
Subscription,
|
||||
)
|
||||
from app.proton.utils import is_proton_partner
|
||||
from app.utils import random_string
|
||||
|
||||
|
||||
|
@ -50,36 +45,6 @@ class LinkResult:
|
|||
strategy: str
|
||||
|
||||
|
||||
def send_double_subscription_if_needed(partner_user: PartnerUser):
|
||||
sub = partner_user.user.get_active_subscription()
|
||||
if isinstance(sub, AppleSubscription):
|
||||
channel = "Apple"
|
||||
elif isinstance(sub, Subscription):
|
||||
channel = "Paddle"
|
||||
else:
|
||||
return
|
||||
send_email_at_most_times(
|
||||
partner_user.user,
|
||||
config.ALERT_DUAL_SUBSCRIPTION_WITH_PARTNER,
|
||||
partner_user.user.email,
|
||||
f"You have two subscriptions in SimpleLogin",
|
||||
render(
|
||||
"transactional/double-subscription-partner.txt.jinja2",
|
||||
is_proton=is_proton_partner(partner_user.partner),
|
||||
partner=partner_user.partner,
|
||||
subscription_channel=channel,
|
||||
cancel_link=url_for("dashboard.billing"),
|
||||
),
|
||||
render(
|
||||
"transactional/double-subscription-partner.html",
|
||||
is_proton=is_proton_partner(partner_user.partner),
|
||||
partner=partner_user.partner,
|
||||
subscription_channel=channel,
|
||||
cancel_link=url_for("dashboard.billing"),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def set_plan_for_partner_user(partner_user: PartnerUser, plan: SLPlan):
|
||||
sub = PartnerSubscription.get_by(partner_user_id=partner_user.id)
|
||||
if plan.type == SLPlanType.Free:
|
||||
|
@ -108,7 +73,6 @@ def set_plan_for_partner_user(partner_user: PartnerUser, plan: SLPlan):
|
|||
"PlanChange", {"plan": "premium", "type": "extension"}
|
||||
)
|
||||
sub.end_at = plan.expiration
|
||||
send_double_subscription_if_needed(partner_user)
|
||||
Session.commit()
|
||||
|
||||
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% call text() %}
|
||||
Hi,
|
||||
{% endcall %}
|
||||
|
||||
{% call text() %}
|
||||
{% if is_proton %}
|
||||
As a Proton user with a paid mail subscription you can have SimpleLogin premium for free, thanks to the SimpleLogin Proton integration.<br>
|
||||
{% else %}
|
||||
{{ partner.name }} has upgraded your account to premium.<br>
|
||||
{% endif %}
|
||||
You currently have a paid SimpleLogin subscription via {{ subscription_channel }}.<br>
|
||||
{% if subscription_channel == 'apple' %}
|
||||
You can cancel it to avoid automatic renewal on your Apple iCloud account page.
|
||||
You can find more info <a href="https://support.apple.com/en-us/HT202039">here</a>.<br>
|
||||
{% elif subscription_channel == 'paddle' %}
|
||||
You can cancel it to avoid automatic renewal on <a href="{{ cancel_link }}">{{ cancel_link }}</a>.<br>
|
||||
{% endif %}
|
||||
You can also keep both subscriptions. In this case there’s nothing to do.
|
||||
{% endcall %}
|
||||
|
||||
{% call text() %}
|
||||
Best, <br>
|
||||
SimpleLogin team.
|
||||
{% endcall %}
|
||||
{% endblock %}
|
|
@ -1,22 +0,0 @@
|
|||
{% extends "base.txt.jinja2" %}
|
||||
|
||||
{% block content %}
|
||||
Hi,
|
||||
|
||||
{% if is_proton -%}
|
||||
As a Proton user with a paid mail subscription you can have SimpleLogin premium for free, thanks to the SimpleLogin Proton integration.
|
||||
{% else -%}}
|
||||
{{ partner.name }} has upgraded your account to premium.
|
||||
{% endif -%}
|
||||
You currently have a paid SimpleLogin subscription via {subscription_channel}.
|
||||
{% if subscription_channel == 'Apple' %}
|
||||
You can cancel it to avoid automatic renewal on your Apple iCloud account page.
|
||||
Please find more info at https://support.apple.com/en-us/HT202039
|
||||
{% elif subscription_channel == 'Paddle' %}
|
||||
You can cancel it to avoid automatic renewal on {{ cancel_link }}.
|
||||
{% endif %}
|
||||
You can also keep both subscriptions. In this case there’s nothing to do.
|
||||
|
||||
Best,
|
||||
SimpleLogin team.
|
||||
{% endblock %}
|
|
@ -1,10 +1,6 @@
|
|||
import random
|
||||
|
||||
import arrow
|
||||
import pytest
|
||||
from arrow import Arrow
|
||||
|
||||
from app import config
|
||||
from app.account_linking import (
|
||||
process_link_case,
|
||||
process_login_case,
|
||||
|
@ -17,15 +13,12 @@ from app.account_linking import (
|
|||
SLPlanType,
|
||||
PartnerLinkRequest,
|
||||
ClientMergeStrategy,
|
||||
set_plan_for_partner_user,
|
||||
)
|
||||
from app.mail_sender import mail_sender
|
||||
from app.db import Session
|
||||
from app.errors import AccountAlreadyLinkedToAnotherPartnerException
|
||||
from app.models import Partner, PartnerUser, User, Subscription, PlanEnum, SentAlert
|
||||
from app.models import Partner, PartnerUser, User
|
||||
from app.proton.utils import get_proton_partner
|
||||
from app.utils import random_string
|
||||
|
||||
from tests.utils import random_email
|
||||
|
||||
|
||||
|
@ -326,39 +319,3 @@ def test_ensure_partner_user_exists_for_user_raises_exception_when_linked_to_ano
|
|||
user,
|
||||
partner_2,
|
||||
)
|
||||
|
||||
|
||||
@mail_sender.store_emails_test_decorator
|
||||
def test_send_double_sub_email_is_sent(flask_client):
|
||||
user = create_user(random_email())
|
||||
Subscription.create(
|
||||
user_id=user.id,
|
||||
cancel_url="https://checkout.paddle.com/subscription/cancel?user=1234",
|
||||
update_url="https://checkout.paddle.com/subscription/update?user=1234",
|
||||
subscription_id=int(random.randint(10000, 999999999)),
|
||||
event_time=arrow.now(),
|
||||
next_bill_date=arrow.now().shift(days=10).date(),
|
||||
plan=PlanEnum.monthly,
|
||||
commit=True,
|
||||
)
|
||||
partner = Partner.create(
|
||||
name=random_string(),
|
||||
contact_email=random_email(),
|
||||
flush=True,
|
||||
)
|
||||
partner_user = PartnerUser.create(
|
||||
user_id=user.id,
|
||||
partner_id=partner.id,
|
||||
partner_email=user.email,
|
||||
external_user_id=random_string(),
|
||||
commit=True,
|
||||
)
|
||||
set_plan_for_partner_user(
|
||||
partner_user,
|
||||
SLPlan(type=SLPlanType.Premium, expiration=arrow.now().shift(months=10)),
|
||||
)
|
||||
emails_sent = mail_sender.get_stored_emails()
|
||||
assert len(emails_sent) == 1
|
||||
alerts = SentAlert.filter_by(user_id=user.id).all()
|
||||
assert len(alerts) == 1
|
||||
assert alerts[0].alert_type == config.ALERT_DUAL_SUBSCRIPTION_WITH_PARTNER
|
||||
|
|
Loading…
Reference in a new issue