diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 62bbb1d92..e68ee4ce5 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -383,6 +383,7 @@ PERMS = { # Minimum admin_level to perform action. 'USER_RESET_PASSWORD': 4, 'CLAIM_REWARDS_ALL_USERS': 4, 'IGNORE_AWARD_IMMUNITY': 4, + 'INSERT_TRANSACTION': 4, } FEATURES = { diff --git a/files/helpers/config/modaction_types.py b/files/helpers/config/modaction_types.py index 56d454050..8045293ac 100644 --- a/files/helpers/config/modaction_types.py +++ b/files/helpers/config/modaction_types.py @@ -181,6 +181,11 @@ MODACTION_TYPES = { "icon": 'fa-tag', "color": 'bg-primary' }, + 'insert_transaction': { + "str": 'Inserted transaction made by {self.target_link}', + "icon": 'fa-dollar-sign', + "color": 'bg-success' + }, 'link_accounts': { "str": 'linked {self.target_link}', "icon": 'fa-link', @@ -436,6 +441,7 @@ MODACTION_PRIVILEGED_TYPES = { 'enable_login_required', 'reset_password', 'schedule_orgy', 'remove_orgy', + 'insert_transaction', } MODACTION_PRIVILEGED__TYPES = {'progstack_post', 'progstack_comment', 'unprogstack_post', 'unprogstack_comment'} diff --git a/files/routes/admin.py b/files/routes/admin.py index 8312f7112..7871bac4e 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -2044,3 +2044,61 @@ def remove_orgy(v, created_utc): requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE}) return {"message": "Orgy stopped successfully!"} + +@app.get("/admin/insert_transaction") +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) +@admin_level_required(PERMS['INSERT_TRANSACTION']) +def insert_transaction(v): + return render_template("admin/insert_transaction.html", v=v) + +@app.post("/admin/insert_transaction") +@limiter.limit('1/second', scope=rpath) +@limiter.limit('1/second', scope=rpath, key_func=get_ID) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) +@admin_level_required(PERMS['INSERT_TRANSACTION']) +def insert_transaction_post(v): + type = request.values.get("type", "").strip() + id = request.values.get("id", "").strip() + amount = request.values.get("amount", "").strip() + username = request.values.get("username", "").strip() + + if type not in {'BTC', 'ETH'}: + abort(400, "Invalid transaction currency!") + + if not id: + abort(400, "A transaction ID is required!") + + if not amount: + abort(400, "A transaction amount is required!") + + if not username: + abort(400, "A username is required!") + + amount = int(amount) + + user = get_user(username) + + if not user.email: + abort(400, f"@{user.username} doesn't have an email tied to their account!") + + transaction = Transaction( + id=id, + created_utc=time.time(), + type=type, + amount=amount, + email=user.email, + ) + g.db.add(transaction) + + ma = ModAction( + kind="insert_transaction", + user_id=v.id, + target_user_id=user.id, + _note=f'Transaction ID: {id}', + ) + g.db.add(ma) + + claim_rewards_all_users() + return {"message": "Transaction inserted successfully!"} diff --git a/files/routes/users.py b/files/routes/users.py index ce6b99d0d..6b2cedf89 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -47,6 +47,7 @@ def _add_profile_view(vid, uid): stdout.flush() def claim_rewards_all_users(): + g.db.flush() emails = [x[0] for x in g.db.query(Transaction.email).filter_by(claimed=None)] users = g.db.query(User).filter(User.email.in_(emails)).order_by(User.truescore.desc()).all() for user in users: @@ -58,8 +59,8 @@ def claim_rewards_all_users(): for transaction in transactions: for t, money in TIER_TO_MONEY.items(): + if transaction.amount < money: break tier = t - if transaction.amount <= money: break marseybux += transaction.amount * 500 if tier > highest_tier: diff --git a/files/templates/admin/admin_home.html b/files/templates/admin/admin_home.html index 9662aab68..1401e09f5 100644 --- a/files/templates/admin/admin_home.html +++ b/files/templates/admin/admin_home.html @@ -4,6 +4,13 @@ {% block content %}