From bdaced6c1036a9bf162ef263727d5e2a6f5d70f9 Mon Sep 17 00:00:00 2001 From: Aevann Date: Mon, 23 Jan 2023 14:40:44 +0200 Subject: [PATCH] allow admins to apply progstack --- files/helpers/config/const.py | 9 ++++-- files/routes/admin.py | 12 ++++++++ files/routes/jinja2.py | 2 +- files/routes/votes.py | 29 +++++++++++-------- files/templates/post_actions.html | 3 ++ .../templates/post_admin_actions_mobile.html | 4 ++- 6 files changed, 43 insertions(+), 16 deletions(-) diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index ac1dd4ae8..739fc0640 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -53,6 +53,7 @@ blackjack2 = environ.get("BLACKJACK2", "").strip() FP = environ.get("FP", "").strip() KOFI_TOKEN = environ.get("KOFI_TOKEN", "").strip() KOFI_LINK = environ.get("KOFI_LINK", "").strip() +PROGSTACK_MUL = float(environ.get("PROGSTACK_MUL", 2.0)) class Service(Enum): RDRAMA = auto() @@ -472,9 +473,10 @@ PERMS = { # Minimum admin_level to perform action. 'UPDATE_ASSETS': 4, 'VIEW_PATRONS': 4, 'BLACKJACK_NOTIFICATIONS': 4, - 'IGNORE_BADGE_BLACKLIST': 4, + 'IGNORE_BADGE_BLACKLIST': 4, + 'PROGSTACK': 4, 'SEE_GHOST_VOTES': 5, - 'MODS_EVERY_HOLE': 5 + 'MODS_EVERY_HOLE': 5, } FEATURES = { @@ -614,6 +616,8 @@ LONGPOSTBOT_ID = 3 ZOZBOT_ID = 4 PIZZASHILL_ID = 0 IMPASSIONATA_ID = 0 +PROGSTACK_ID = 4 + CARP_ID = 0 AEVANN_ID = 0 SNAKES_ID = 0 @@ -709,6 +713,7 @@ if SITE == 'rdrama.net': ZOZBOT_ID = 1833 PIZZASHILL_ID = 2424 IMPASSIONATA_ID = 5800 + PROGSTACK_ID = 15531 CARP_ID = 995 AEVANN_ID = 1 SNAKES_ID = 10288 diff --git a/files/routes/admin.py b/files/routes/admin.py index d86ef882f..10d708c74 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1,5 +1,6 @@ import time from urllib.parse import quote, urlencode +from math import floor from sqlalchemy import nullslast from sqlalchemy.exc import IntegrityError @@ -1269,6 +1270,17 @@ def unmute_user(v:User, user_id): return {"message": f"@{user.username} has been unmuted!"} +@app.post("/admin/progstack/") +@limiter.limit(DEFAULT_RATELIMIT_SLOWER) +@limiter.limit(DEFAULT_RATELIMIT_SLOWER, key_func=get_ID) +@admin_level_required(PERMS['PROGSTACK']) +def progstack(post_id, v): + post = get_post(post_id) + post.is_approved = PROGSTACK_ID + post.realupvotes = floor(target.realupvotes * PROGSTACK_MUL) + g.db.add(post) + cache.delete_memoized(frontlist) + return {"message": "Progressive stack applied!"} @app.post("/remove_post/") @limiter.limit(DEFAULT_RATELIMIT_SLOWER) diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index 7ccb01139..e2e5acc77 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -114,7 +114,7 @@ def inject_constants(): "approved_embed_hosts":approved_embed_hosts, "site_settings":get_settings(), "EMAIL":EMAIL, "max": max, "min": min, "user_can_see":User.can_see, "TELEGRAM_ID":TELEGRAM_ID, "EMAIL_REGEX_PATTERN":EMAIL_REGEX_PATTERN, - "TRUESCORE_DONATE_MINIMUM":TRUESCORE_DONATE_MINIMUM, + "TRUESCORE_DONATE_MINIMUM":TRUESCORE_DONATE_MINIMUM, "PROGSTACK_ID":PROGSTACK_ID, "DONATE_LINK":DONATE_LINK, "DONATE_SERVICE":DONATE_SERVICE, "BAN_EVASION_DOMAIN":BAN_EVASION_DOMAIN, "HOUSE_JOIN_COST":HOUSE_JOIN_COST, "HOUSE_SWITCH_COST":HOUSE_SWITCH_COST, "IMAGE_FORMATS":','.join(IMAGE_FORMATS), "PAGE_SIZES":PAGE_SIZES, "THEMES":THEMES, "COMMENT_SORTS":COMMENT_SORTS, "SORTS":SORTS, diff --git a/files/routes/votes.py b/files/routes/votes.py index f56b8d8ca..2e3007fb0 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -5,6 +5,8 @@ from files.routes.wrappers import * from files.__main__ import app, limiter from files.routes.routehelpers import get_alt_graph +from math import floor + @app.get("/votes/") @limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) @auth_required @@ -161,21 +163,24 @@ def vote_post_comment(target_id, new, v, cls, vote_cls): target.realupvotes = get_vote_count(0, True) # first arg is ignored here mul = 1 - if target.author.progressivestack or (target.author.admin_level and target.author.id not in {AEVANN_ID, CARP_ID}): - mul = 2 - if cls == Submission and target.author.id not in {8768,3402,5214,12719}: - if (target.domain.endswith('.win') or 'forum' in target.domain - or (target.domain in BOOSTED_SITES and not target.url.startswith('/')) - or target.sub in BOOSTED_HOLES): + if target.is_approved == PROGSTACK_ID: + mul = PROGSTACK_MUL + else: + if target.author.progressivestack or (target.author.admin_level and target.author.id not in {AEVANN_ID, CARP_ID}): mul = 2 - elif not target.sub and target.body_html: - x = target.body_html.count('" target="_blank" rel="nofollow noopener">') - x += target.body_html.count('') + x += target.body_html.count('Mark +18 {% endif %} + {% if v.admin_level >= PERMS['PROGSTACK'] %} + + {% endif %} {% if v.admin_level >= PERMS['USER_BAN'] and v.id != p.author_id %} diff --git a/files/templates/post_admin_actions_mobile.html b/files/templates/post_admin_actions_mobile.html index 95167a7f6..e85742508 100644 --- a/files/templates/post_admin_actions_mobile.html +++ b/files/templates/post_admin_actions_mobile.html @@ -36,11 +36,13 @@ {% endif %} + {% if v.admin_level >= PERMS['PROGSTACK'] %} + + {% endif %} {% if v.id != p.author_id and v.admin_level >= PERMS['USER_BAN'] %} {% endif %} - {% if v.id != p.author_id and v.admin_level >= PERMS['USER_AGENDAPOSTER'] %}