diff --git a/app/models.py b/app/models.py index 2018bd93..f821dbd4 100644 --- a/app/models.py +++ b/app/models.py @@ -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"""