Stop paddle sub (#1216)

* admin can stop a paddle sub

* show admin menu if user is admin
This commit is contained in:
Son Nguyen Kim 2022-08-04 09:20:07 +02:00 committed by GitHub
parent f340c9c9ea
commit 6c6deedf47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View file

@ -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",

View file

@ -83,6 +83,14 @@
</a>
</li>
{% endif %}
{% if current_user.is_admin %}
<li class="nav-item">
<a href="/admin">
<i class="fe fe-server"></i> Admin ☢️
</a>
</li>
{% endif %}
{% if ZENDESK_ENABLED %}
<li class="nav-item">