From f6a7ee981a95ff7aa91890a484e08dcb37e7429f Mon Sep 17 00:00:00 2001 From: Son Nguyen Kim Date: Tue, 28 Jun 2022 17:51:44 +0200 Subject: [PATCH] do not send double subscription email (#1118) * do not send double subscription email * remove unused import * remove unused test --- app/account_linking.py | 44 ++---------------- .../double-subscription-partner.html | 28 ------------ .../double-subscription-partner.txt.jinja2 | 22 --------- tests/test_account_linking.py | 45 +------------------ 4 files changed, 5 insertions(+), 134 deletions(-) delete mode 100644 templates/emails/transactional/double-subscription-partner.html delete mode 100644 templates/emails/transactional/double-subscription-partner.txt.jinja2 diff --git a/app/account_linking.py b/app/account_linking.py index 754dd12f..19762cd2 100644 --- a/app/account_linking.py +++ b/app/account_linking.py @@ -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() diff --git a/templates/emails/transactional/double-subscription-partner.html b/templates/emails/transactional/double-subscription-partner.html deleted file mode 100644 index e8a379d6..00000000 --- a/templates/emails/transactional/double-subscription-partner.html +++ /dev/null @@ -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.
- {% 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. - You can find more info here.
- {% 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. - {% endcall %} - - {% call text() %} - Best,
- SimpleLogin team. - {% endcall %} -{% endblock %} diff --git a/templates/emails/transactional/double-subscription-partner.txt.jinja2 b/templates/emails/transactional/double-subscription-partner.txt.jinja2 deleted file mode 100644 index 9ad89171..00000000 --- a/templates/emails/transactional/double-subscription-partner.txt.jinja2 +++ /dev/null @@ -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 %} diff --git a/tests/test_account_linking.py b/tests/test_account_linking.py index c71804dc..2411c3f3 100644 --- a/tests/test_account_linking.py +++ b/tests/test_account_linking.py @@ -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