From b838157ad56139784dc5c38a4bc489290955a807 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Mon, 13 Apr 2020 20:50:48 +0200 Subject: [PATCH] User who has lifetime licence or giveaway manual subscriptions can decide to upgrade to a paid plan --- app/dashboard/templates/dashboard/setting.html | 11 ++++++++++- app/dashboard/views/pricing.py | 3 +-- app/models.py | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/dashboard/templates/dashboard/setting.html b/app/dashboard/templates/dashboard/setting.html index 231d080a..ccbf129b 100644 --- a/app/dashboard/templates/dashboard/setting.html +++ b/app/dashboard/templates/dashboard/setting.html @@ -165,9 +165,18 @@ Manage Subscription {% elif manual_sub %} - You are on the Premium plan. The plan ends {{ manual_sub.end_at | dt }}. + You are on the Premium plan. The plan ends {{ manual_sub.end_at | dt }} + ({{ manual_sub.end_at.format("YYYY-MM-DD") }}). + {% if manual_sub.is_giveaway %} +
+ To support SimpleLogin it's possible to change to a paid plan.
+ Upgrade + {% endif %} {% elif current_user.lifetime %} You have the lifetime licence. +
+ To support SimpleLogin it's possible to change to a paid plan.
+ Upgrade {% elif current_user.in_trial() %} You are in the trial period. The trial ends {{ current_user.trial_end | dt }}. {% else %} diff --git a/app/dashboard/views/pricing.py b/app/dashboard/views/pricing.py index fcc28919..aeb39652 100644 --- a/app/dashboard/views/pricing.py +++ b/app/dashboard/views/pricing.py @@ -13,8 +13,7 @@ from app.dashboard.base import dashboard_bp @dashboard_bp.route("/pricing", methods=["GET", "POST"]) @login_required def pricing(): - # sanity check: make sure this page is only for free or trial user - if not current_user.should_upgrade(): + if not current_user.can_upgrade(): flash("You are already a premium user", "warning") return redirect(url_for("dashboard.index")) diff --git a/app/models.py b/app/models.py index b30fccd8..30ab481f 100644 --- a/app/models.py +++ b/app/models.py @@ -243,6 +243,23 @@ class User(db.Model, ModelMixin, UserMixin): return True + def can_upgrade(self): + """User who has lifetime licence or giveaway manual subscriptions can decide to upgrade to a paid plan""" + sub: Subscription = self.get_subscription() + # user who has canceled can also re-subscribe + if sub and not sub.cancelled: + 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.end_at > arrow.now() and not manual_sub.is_giveaway: + return False + + return True + + + + def next_bill_date(self) -> str: sub: Subscription = self.get_subscription() if sub: