From 558ee805ecf3916c80dcf266bd1b8621483f35c8 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Fri, 7 Oct 2022 21:07:44 -0700 Subject: [PATCH] re-add revert admin actions function and also fix a bug with it --- files/helpers/const.py | 1 + files/routes/admin.py | 50 +++++++++++++++++++++++++++++++++++ files/templates/userpage.html | 8 ++++-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index e0e5217d4..24735dc68 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -165,6 +165,7 @@ PERMS = { # Minimum admin_level to perform action. 'ADMIN_ADD': 3, # note: explicitly disabled on rDrama 'ADMIN_REMOVE': 3, 'ADMIN_ADD_PERM_LEVEL': 2, # permission level given when user added via site + 'ADMIN_ACTIONS_REVERT': 3, 'ADMIN_MOP_VISIBLE': 2, 'ADMIN_HOME_VISIBLE': 2, 'DOMAINS_BAN': 3, diff --git a/files/routes/admin.py b/files/routes/admin.py index fe0dac4de..0ea454b16 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -247,6 +247,56 @@ def distribute(v, option_id): return {"message": f"Each winner has received {coinsperperson} coins!"} +@app.post("/@/revert_actions") +@limiter.limit("1/second;30/minute;200/hour;1000/day") +@admin_level_required(PERMS['ADMIN_ACTIONS_REVERT']) +def revert_actions(v, username): + user = get_user(username) + + ma = ModAction( + kind="revert", + user_id=v.id, + target_user_id=user.id + ) + g.db.add(ma) + + cutoff = int(time.time()) - 86400 + + posts = [x[0] for x in g.db.query(ModAction.target_submission_id).filter(ModAction.user_id == user.id, ModAction.created_utc > cutoff, ModAction.kind == 'ban_post').all()] + posts = g.db.query(Submission).filter(Submission.id.in_(posts)).all() + + comments = [x[0] for x in g.db.query(ModAction.target_comment_id).filter(ModAction.user_id == user.id, ModAction.created_utc > cutoff, ModAction.kind == 'ban_comment').all()] + comments = g.db.query(Comment).filter(Comment.id.in_(comments)).all() + + for item in posts + comments: + item.is_banned = False + item.ban_reason = None + item.is_approved = v.id + g.db.add(item) + + users = (x[0] for x in g.db.query(ModAction.target_user_id).filter(ModAction.user_id == user.id, ModAction.created_utc > cutoff, ModAction.kind.in_(('shadowban', 'ban_user'))).all()) + users = g.db.query(User).filter(User.id.in_(users)).all() + + for user in users: + user.shadowbanned = None + user.unban_utc = 0 + user.ban_reason = None + if user.is_banned: + user.is_banned = 0 + send_repeatable_notification(user.id, f"@{v.username} has unbanned you!") + g.db.add(user) + + for u in user.alts: + u.shadowbanned = None + u.unban_utc = 0 + u.ban_reason = None + if u.is_banned: + u.is_banned = 0 + send_repeatable_notification(u.id, f"@{v.username} has unbanned you!") + g.db.add(u) + + return {"message": f"@{user.username}'s admin actions has been reverted!"} + @app.post("/@/club_allow") @limiter.limit("1/second;30/minute;200/hour;1000/day") @admin_level_required(PERMS['USER_CLUB_ALLOW_BAN']) diff --git a/files/templates/userpage.html b/files/templates/userpage.html index e81b27639..4849f8ed4 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -227,7 +227,9 @@ Remove admin {% endif %} - + {% if v.admin_level >= PERMS['ADMIN_ACTIONS_REVERT'] and u.admin_level %} + Revert admin actions + {% endif %}

@@ -493,7 +495,9 @@
 					{% if v.admin_level >= PERMS['ADMIN_REMOVE'] %}
 						Remove admin
 					{% endif %}
-					
+					{% if v.admin_level >= PERMS['ADMIN_ACTIONS_REVERT'] and u.admin_level %}
+						Revert admin actions
+					{% endif %}