From 408322217d734ac222c9a6a9974985040e647c6b Mon Sep 17 00:00:00 2001 From: Son Nguyen Kim Date: Mon, 27 Sep 2021 09:59:33 +0200 Subject: [PATCH] allow user having apple subscription to switch to web subscription --- app/dashboard/templates/dashboard/setting.html | 16 ++++++++++++---- app/dashboard/views/pricing.py | 5 +++++ app/models.py | 4 ---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/dashboard/templates/dashboard/setting.html b/app/dashboard/templates/dashboard/setting.html index e3696bf0..e3909e62 100644 --- a/app/dashboard/templates/dashboard/setting.html +++ b/app/dashboard/templates/dashboard/setting.html @@ -49,8 +49,15 @@ {% endif %} {% elif apple_sub and apple_sub.is_valid() %} - You are on the Premium plan which expires {{ apple_sub.expires_date | dt }} + You are on the Premium plan (subscribed via Apple) which expires {{ apple_sub.expires_date | dt }} ({{ apple_sub.expires_date.format("YYYY-MM-DD") }}). +
+ If you want to subscribe via the Web instead, please make sure to cancel your subscription + on Apple first. + Upgrade +
+ {% elif coinbase_sub and coinbase_sub.is_active() %} You are on the Premium plan which expires {{ coinbase_sub.end_at | dt }} ({{ coinbase_sub.end_at.format("YYYY-MM-DD") }}). @@ -252,7 +259,7 @@
+ {# todo: remove current_user.include_sender_in_reverse_alias is none condition #} + {% if current_user.include_sender_in_reverse_alias is none or current_user.include_sender_in_reverse_alias %} + checked {% endif %} class="form-check-input">
diff --git a/app/dashboard/views/pricing.py b/app/dashboard/views/pricing.py index 7378d18d..da16424a 100644 --- a/app/dashboard/views/pricing.py +++ b/app/dashboard/views/pricing.py @@ -12,6 +12,7 @@ from app.config import ( ) from app.dashboard.base import dashboard_bp from app.log import LOG +from app.models import AppleSubscription @dashboard_bp.route("/pricing", methods=["GET", "POST"]) @@ -21,6 +22,10 @@ def pricing(): flash("You are already a premium user", "warning") return redirect(url_for("dashboard.index")) + apple_sub: AppleSubscription = AppleSubscription.get_by(user_id=current_user.id) + if apple_sub and apple_sub.is_valid(): + flash("Please make sure to cancel your subscription on Apple first", "warning") + return render_template( "dashboard/pricing.html", PADDLE_VENDOR_ID=PADDLE_VENDOR_ID, diff --git a/app/models.py b/app/models.py index 8983e72d..3e7f1895 100644 --- a/app/models.py +++ b/app/models.py @@ -477,10 +477,6 @@ class User(db.Model, ModelMixin, UserMixin, PasswordOracle): if sub and not sub.cancelled: return False - apple_sub: AppleSubscription = AppleSubscription.get_by(user_id=self.id) - if apple_sub and apple_sub.is_valid(): - return False - manual_sub: ManualSubscription = ManualSubscription.get_by(user_id=self.id) # user who has giveaway premium can decide to upgrade if manual_sub and manual_sub.is_active() and not manual_sub.is_giveaway: