From 6c6deedf471a651cd9cf513bbb6d4eacc101434f Mon Sep 17 00:00:00 2001 From: Son Nguyen Kim Date: Thu, 4 Aug 2022 09:20:07 +0200 Subject: [PATCH] Stop paddle sub (#1216) * admin can stop a paddle sub * show admin menu if user is admin --- app/admin_model.py | 20 ++++++++++++++++++++ templates/menu.html | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/app/admin_model.py b/app/admin_model.py index f3af2813..a49efc23 100644 --- a/app/admin_model.py +++ b/app/admin_model.py @@ -26,6 +26,7 @@ from app.models import ( ProviderComplaint, Alias, Newsletter, + PADDLE_SUBSCRIPTION_GRACE_DAYS, ) from app.newsletter_utils import send_newsletter_to_user, send_newsletter_to_address @@ -199,6 +200,25 @@ class UserAdmin(SLModelView): Session.commit() + @action( + "stop_paddle_sub", + "Stop user Paddle subscription", + "This will stop the current user Paddle subscription so if user doesn't have Proton sub, they will lose all SL benefits immediately", + ) + def stop_paddle_sub(self, ids): + for user in User.filter(User.id.in_(ids)): + sub: Subscription = user.get_paddle_subscription() + if not sub: + flash(f"No Paddle sub for {user}", "warning") + continue + + flash(f"{user} sub will end now, instead of {sub.next_bill_date}", "info") + sub.next_bill_date = ( + arrow.now().shift(days=-PADDLE_SUBSCRIPTION_GRACE_DAYS).date() + ) + + Session.commit() + # @action( # "login_as", # "Login as this user", diff --git a/templates/menu.html b/templates/menu.html index 8920b976..47f3c345 100644 --- a/templates/menu.html +++ b/templates/menu.html @@ -83,6 +83,14 @@ {% endif %} + {% if current_user.is_admin %} + + + {% endif %} {% if ZENDESK_ENABLED %}