From d5a48871f88d9615a1706ac4031f2e1ca06f9e9f Mon Sep 17 00:00:00 2001 From: justcool393 Date: Wed, 5 Oct 2022 18:58:43 -0700 Subject: [PATCH] user ban and also fix global hole mod a bit i hope i didn't screw up the templates --- files/classes/user.py | 2 +- files/helpers/const.py | 1 + files/routes/admin.py | 10 +++---- files/routes/awards.py | 4 +-- files/routes/comments.py | 4 +-- files/routes/reporting.py | 2 +- files/routes/subs.py | 4 +-- files/templates/comments.html | 2 +- files/templates/submission_listing.html | 2 +- files/templates/userpage.html | 38 +++++++++++++------------ 10 files changed, 36 insertions(+), 33 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 1102eec37..1ef949466 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -285,7 +285,7 @@ class User(Base): @lazy def mods(self, sub): if self.is_suspended_permanently or self.shadowbanned: return False - return self.admin_level > 2 or bool(g.db.query(Mod.user_id).filter_by(user_id=self.id, sub=sub).one_or_none()) + return self.admin_level >= PERMS['GLOBAL_MODERATION'] or bool(g.db.query(Mod.user_id).filter_by(user_id=self.id, sub=sub).one_or_none()) @lazy def exiled_from(self, sub): diff --git a/files/helpers/const.py b/files/helpers/const.py index 1accfe843..1ba562fad 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -130,6 +130,7 @@ PERMS = { # Minimum admin_level to perform action. 'POST_COMMENT_MODERATION': 2, 'GLOBAL_HOLE_MODERATION': 3, 'POST_EDITING': 3, + 'USER_BAN': 2, } FEATURES = { diff --git a/files/routes/admin.py b/files/routes/admin.py index 53262adbc..c1bc9e96a 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -988,7 +988,7 @@ def admin_title_change(user_id, v): @app.post("/ban_user/") @limiter.limit("1/second;30/minute;200/hour;1000/day") -@admin_level_required(2) +@admin_level_required(PERMS['USER_BAN']) def ban_user(user_id, v): user = get_account(user_id) @@ -1051,7 +1051,7 @@ def ban_user(user_id, v): @app.post("/unban_user/") @limiter.limit("1/second;30/minute;200/hour;1000/day") -@admin_level_required(2) +@admin_level_required(PERMS['USER_BAN']) def unban_user(user_id, v): user = get_account(user_id) if not user.is_banned: @@ -1082,7 +1082,7 @@ def unban_user(user_id, v): @app.post("/mute_user//") @limiter.limit("1/second;30/minute;200/hour;1000/day") -@admin_level_required(2) +@admin_level_required(PERMS['USER_BAN']) def mute_user(v, user_id, mute_status): user = get_account(user_id) @@ -1442,7 +1442,7 @@ def admin_toggle_ban_domain(v): @app.post("/admin/nuke_user") @limiter.limit("1/second;30/minute;200/hour;1000/day") -@admin_level_required(2) +@admin_level_required(PERMS['POST_COMMENT_MODERATION']) def admin_nuke_user(v): user=get_user(request.values.get("user")) @@ -1475,7 +1475,7 @@ def admin_nuke_user(v): @app.post("/admin/unnuke_user") @limiter.limit("1/second;30/minute;200/hour;1000/day") -@admin_level_required(2) +@admin_level_required(PERMS['POST_COMMENT_MODERATION']) def admin_nunuke_user(v): user=get_user(request.values.get("user")) diff --git a/files/routes/awards.py b/files/routes/awards.py index 7f91ceaba..e94e36fd4 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -212,7 +212,7 @@ def award_thing(v, thing_type, id): author.unban_utc += 86400 send_repeatable_notification(author.id, f"Your account has been banned for **yet another day** for {link}. Seriously man?") - if v.admin_level > 2: + if v.admin_level >= PERMS['USER_BAN']: log_link = f'/{thing_type}/{thing.id}' reason = f'{log_link}' @@ -236,7 +236,7 @@ def award_thing(v, thing_type, id): author.ban_reason = None send_repeatable_notification(author.id, "You have been unbanned!") - if v.admin_level > 2: + if v.admin_level >= PERMS['USER_BAN']: ma=ModAction( kind="unban_user", user_id=v.id, diff --git a/files/routes/comments.py b/files/routes/comments.py index 4d05c8d1d..4e1aaebf5 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -127,7 +127,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): if request.headers.get("Authorization"): return top_comment.json else: - if post.is_banned and not (v and (v.admin_level > 1 or post.author_id == v.id)): template = "submission_banned.html" + if post.is_banned and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or post.author_id == v.id)): template = "submission_banned.html" else: template = "submission.html" return render_template(template, v=v, p=post, sort=sort, comment_info=comment_info, render_replies=True, sub=post.subr) @@ -263,7 +263,7 @@ def comment(v): ).first() if existing: return {"error": f"You already made that comment: /comment/{existing.id}"}, 409 - if parent.author.any_block_exists(v) and v.admin_level < 2: + if parent.author.any_block_exists(v) and v.admin_level < PERMS['POST_COMMENT_MODERATION']: return {"error": "You can't reply to users who have blocked you, or users you have blocked."}, 403 is_bot = v.id != 12125 and (bool(request.headers.get("Authorization")) or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID)) diff --git a/files/routes/reporting.py b/files/routes/reporting.py index e72f47a49..962da38f0 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -33,7 +33,7 @@ def flag_post(pid, v): if reason.startswith('!') and (v.admin_level > PERMS['POST_COMMENT_MODERATION'] or post.sub and v.mods(post.sub)): post.flair = reason[1:] g.db.add(post) - if v.admin_level > 1: + if v.admin_level >= PERMS['POST_COMMENT_MODERATION']: ma=ModAction( kind="flair_post", user_id=v.id, diff --git a/files/routes/subs.py b/files/routes/subs.py index c4a328c03..fb0529933 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -366,7 +366,7 @@ def kick(v, pid): old = post.sub post.sub = None - if v.admin_level >= 3 and v.id != post.author_id: + if v.admin_level >= PERMS['GLOBAL_MODERATION'] and v.id != post.author_id: old_str = f'/h/{old}' ma = ModAction( kind='move_hole', @@ -385,7 +385,7 @@ def kick(v, pid): g.db.add(ma) if v.id != post.author_id: - if v.admin_level >= 3: position = 'Admin' + if v.admin_level >= PERMS['GLOBAL_MODERATION']: position = 'Admin' else: position = 'Mod' message = f"@{v.username} ({position}) has moved [{post.title}]({post.shortlink}) from /h/{old} to the main feed!" send_repeatable_notification(post.author_id, message) diff --git a/files/templates/comments.html b/files/templates/comments.html index 7ba1dbf55..7779916c2 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -755,7 +755,7 @@ {% if v %} {% include "gif_modal.html" %} {% include "emoji_modal.html" %} - {% if v.admin_level > 1 %} + {% if v.admin_level >= PERMS['USER_BAN'] %} {% include "ban_modal.html" %} {% endif %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index c0024976b..2ca5fbcbc 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -418,7 +418,7 @@ {% if v %} {% include "delete_post_modal.html" %} {% include "report_post_modal.html" %} - {% if v.admin_level > 1 %} + {% if v.admin_level >= PERMS['USER_BAN'] %} {% include "ban_modal.html" %} {% endif %} {% endif %} diff --git a/files/templates/userpage.html b/files/templates/userpage.html index fea1071df..726e16517 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -296,24 +296,26 @@

 						

-						{% if u.is_suspended %}
-							
- - - -
- {% else %} -
- - - - -
- - -
- -
+ {% if v.admin_level >= PERMS['USER_BAN'] %} + {% if u.is_suspended %} +
+ + + +
+ {% else %} +
+ + + + +
+ + +
+ +
+ {% endif %} {% endif %}