add admin page for manual subscription

This commit is contained in:
Son NK 2021-02-24 09:48:06 +01:00
parent b00524e74f
commit 0f9cb13920
2 changed files with 25 additions and 1 deletions

View file

@ -5,6 +5,7 @@ from flask_admin.actions import action
from flask_admin.contrib import sqla from flask_admin.contrib import sqla
from flask_login import current_user from flask_login import current_user
from app.extensions import db
from app.models import User, ManualSubscription from app.models import User, ManualSubscription
@ -120,3 +121,19 @@ class MailboxAdmin(SLModelView):
class LifetimeCouponAdmin(SLModelView): class LifetimeCouponAdmin(SLModelView):
can_edit = True can_edit = True
can_create = True can_create = True
class ManualSubscriptionAdmin(SLModelView):
can_edit = True
@action(
"extend_1y",
"Extend for 1 year",
"Extend 1 year more?",
)
def extend_1y(self, ids):
for ms in ManualSubscription.query.filter(ManualSubscription.id.in_(ids)):
ms.end_at = ms.end_at.shift(years=1)
flash(f"Extend subscription for {ms.user}", "success")
db.session.commit()

View file

@ -34,6 +34,7 @@ from app.admin_model import (
AliasAdmin, AliasAdmin,
MailboxAdmin, MailboxAdmin,
LifetimeCouponAdmin, LifetimeCouponAdmin,
ManualSubscriptionAdmin,
) )
from app.api.base import api_bp from app.api.base import api_bp
from app.auth.base import auth_bp from app.auth.base import auth_bp
@ -93,6 +94,7 @@ from app.models import (
File, File,
Contact, Contact,
RefusedEmail, RefusedEmail,
ManualSubscription,
) )
from app.monitor.base import monitor_bp from app.monitor.base import monitor_bp
from app.oauth.base import oauth_bp from app.oauth.base import oauth_bp
@ -205,7 +207,7 @@ def fake_data():
password="password", password="password",
activated=True, activated=True,
is_admin=True, is_admin=True,
enable_otp=False, # enable_otp=True,
otp_secret="base32secret3232", otp_secret="base32secret3232",
intro_shown=True, intro_shown=True,
fido_uuid=None, fido_uuid=None,
@ -372,6 +374,10 @@ def fake_data():
Mailbox.create(user_id=user2.id, email="winston2@high.table", verified=True) Mailbox.create(user_id=user2.id, email="winston2@high.table", verified=True)
db.session.commit() db.session.commit()
ManualSubscription.create(
user_id=user2.id, end_at=arrow.now().shift(years=1, days=1), commit=True
)
@login_manager.user_loader @login_manager.user_loader
def load_user(user_id): def load_user(user_id):
@ -795,6 +801,7 @@ def init_admin(app):
admin.add_view(MailboxAdmin(Mailbox, db.session)) admin.add_view(MailboxAdmin(Mailbox, db.session))
admin.add_view(EmailLogAdmin(EmailLog, db.session)) admin.add_view(EmailLogAdmin(EmailLog, db.session))
admin.add_view(LifetimeCouponAdmin(LifetimeCoupon, db.session)) admin.add_view(LifetimeCouponAdmin(LifetimeCoupon, db.session))
admin.add_view(ManualSubscriptionAdmin(ManualSubscription, db.session))
def setup_do_not_track(app): def setup_do_not_track(app):