take into account AppleSubscription in premium formula

This commit is contained in:
Son NK 2020-04-19 10:58:32 +02:00
parent 2a837f9213
commit 85fd4412ba

View file

@ -217,6 +217,10 @@ class User(db.Model, ModelMixin, UserMixin):
if sub:
return True
apple_sub: AppleSubscription = AppleSubscription.get_by(user_id=self.id)
if apple_sub and apple_sub.is_valid():
return True
manual_sub: ManualSubscription = ManualSubscription.get_by(user_id=self.id)
if manual_sub and manual_sub.end_at > arrow.now():
return True
@ -251,6 +255,10 @@ class User(db.Model, ModelMixin, UserMixin):
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 (
@ -939,6 +947,10 @@ class AppleSubscription(db.Model, ModelMixin):
user = db.relationship(User)
def is_valid(self):
# Todo: take into account grace period?
return self.expires_date > arrow.now()
class DeletedAlias(db.Model, ModelMixin):
"""Store all deleted alias to make sure they are NOT reused"""