delete User.subscription_cancelled
This commit is contained in:
parent
325a1a9524
commit
c29b5100fb
|
@ -6,7 +6,7 @@ from flask_admin.contrib import sqla
|
|||
from flask_login import current_user, login_user
|
||||
|
||||
from app.db import Session
|
||||
from app.models import User, ManualSubscription, Fido
|
||||
from app.models import User, ManualSubscription, Fido, Subscription, AppleSubscription
|
||||
|
||||
|
||||
class SLModelView(sqla.ModelView):
|
||||
|
@ -145,6 +145,26 @@ class UserAdmin(SLModelView):
|
|||
|
||||
def manual_upgrade(way: str, ids: [int], is_giveaway: bool):
|
||||
for user in User.filter(User.id.in_(ids)).all():
|
||||
if user.lifetime:
|
||||
flash(f"user {user} already has a lifetime license", "warning")
|
||||
continue
|
||||
|
||||
sub: Subscription = user.get_subscription()
|
||||
if sub and not sub.cancelled:
|
||||
flash(
|
||||
f"user {user} already has a Paddle license, they have to cancel it first",
|
||||
"warning",
|
||||
)
|
||||
continue
|
||||
|
||||
apple_sub: AppleSubscription = AppleSubscription.get_by(user_id=user.id)
|
||||
if apple_sub and apple_sub.is_valid():
|
||||
flash(
|
||||
f"user {user} already has a Apple subscription, they have to cancel it first",
|
||||
"warning",
|
||||
)
|
||||
continue
|
||||
|
||||
manual_sub: ManualSubscription = ManualSubscription.get_by(user_id=user.id)
|
||||
if manual_sub:
|
||||
# renew existing subscription
|
||||
|
@ -156,15 +176,6 @@ def manual_upgrade(way: str, ids: [int], is_giveaway: bool):
|
|||
flash(f"Subscription extended to {manual_sub.end_at.humanize()}", "success")
|
||||
continue
|
||||
|
||||
# user can have manual subscription applied if their current subscription is canceled
|
||||
if (
|
||||
user.is_premium()
|
||||
and not user.in_trial()
|
||||
and not user.subscription_cancelled
|
||||
):
|
||||
flash(f"User {user} is already premium", "warning")
|
||||
continue
|
||||
|
||||
ManualSubscription.create(
|
||||
user_id=user.id,
|
||||
end_at=arrow.now().shift(years=1, days=1),
|
||||
|
|
|
@ -634,28 +634,6 @@ class User(Base, ModelMixin, UserMixin, PasswordOracle):
|
|||
|
||||
return "N/A"
|
||||
|
||||
@property
|
||||
def subscription_cancelled(self) -> bool:
|
||||
sub: Subscription = self.get_subscription()
|
||||
if sub and sub.cancelled:
|
||||
return True
|
||||
|
||||
apple_sub: AppleSubscription = AppleSubscription.get_by(user_id=self.id)
|
||||
if apple_sub and not apple_sub.is_valid():
|
||||
return True
|
||||
|
||||
manual_sub: ManualSubscription = ManualSubscription.get_by(user_id=self.id)
|
||||
if manual_sub and not manual_sub.is_active():
|
||||
return True
|
||||
|
||||
coinbase_subscription: CoinbaseSubscription = CoinbaseSubscription.get_by(
|
||||
user_id=self.id
|
||||
)
|
||||
if coinbase_subscription and not coinbase_subscription.is_active():
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
# endregion
|
||||
|
||||
def can_create_new_alias(self) -> bool:
|
||||
|
|
Loading…
Reference in New Issue