From 2fc3044d5b8e0455cd82f6035b92c2f2a35ca844 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Wed, 5 Oct 2022 19:24:37 -0700 Subject: [PATCH] shadowban perms and stuff --- files/helpers/const.py | 1 + files/helpers/get.py | 4 +- files/routes/admin.py | 2 +- files/routes/awards.py | 2 +- files/routes/comments.py | 6 +- files/routes/front.py | 2 +- files/routes/notifications.py | 2 +- files/routes/posts.py | 2 +- files/routes/reporting.py | 2 +- files/routes/search.py | 2 +- files/routes/static.py | 2 +- files/templates/comments.html | 6 +- .../templates/post_admin_actions_mobile.html | 2 +- files/templates/submission.html | 2 +- files/templates/submission_listing.html | 2 +- files/templates/userpage.html | 105 +++++++++--------- 16 files changed, 75 insertions(+), 69 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index 1ba562fad..12375f46b 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -131,6 +131,7 @@ PERMS = { # Minimum admin_level to perform action. 'GLOBAL_HOLE_MODERATION': 3, 'POST_EDITING': 3, 'USER_BAN': 2, + 'USER_SHADOWBAN': 2, } FEATURES = { diff --git a/files/helpers/get.py b/files/helpers/get.py index 8ebd3a4dc..084275ad1 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -39,7 +39,7 @@ def get_user(username, v=None, graceful=False, rendered=False, include_blocks=Fa user = user.one_or_none() - if not user or (user.shadowbanned and not (include_shadowbanned or (v and (v.admin_level >= 2 or v.shadowbanned)))): + if not user or (user.shadowbanned and not (include_shadowbanned or (v and (v.admin_level >= PERMS['USER_SHADOWBAN'] or v.shadowbanned)))): if not graceful: abort(404) else: return None @@ -264,7 +264,7 @@ def get_comments(cids, v=None, load_parent=False): blocked.c.target_id, ).filter(Comment.id.in_(cids)) - if not (v and (v.shadowbanned or v.admin_level >= 2)): + if not (v and (v.shadowbanned or v.admin_level >= PERMS['USER_SHADOWBAN'])): comments = comments.join(Comment.author).filter(User.shadowbanned == None) comments = comments.join( diff --git a/files/routes/admin.py b/files/routes/admin.py index c1bc9e96a..679d87a48 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -347,7 +347,7 @@ def club_ban(v, username): @app.get("/admin/shadowbanned") @auth_required def shadowbanned(v): - if not (v and v.admin_level > 1): abort(404) + if not (v and v.admin_level >= PERMS['USER_SHADOWBAN']): abort(404) users = g.db.query(User).filter(User.shadowbanned != None).order_by(User.shadowbanned).all() return render_template("shadowbanned.html", v=v, users=users) diff --git a/files/routes/awards.py b/files/routes/awards.py index e94e36fd4..2271bd969 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -249,7 +249,7 @@ def award_thing(v, thing_type, id): author.unban_utc = int(time.time()) + 30 * 86400 send_repeatable_notification(author.id, f"Your account has been banned permanently for {link}. You must [provide the admins](/contact) a timestamped picture of you touching grass/snow/sand/ass to get unbanned!") - if v.admin_level > 2: + if v.admin_level >= PERMS['USER_BAN']: log_link = f'/{thing_type}/{thing.id}' reason = f'{log_link}' diff --git a/files/routes/comments.py b/files/routes/comments.py index 4e1aaebf5..ce52a74f4 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -41,7 +41,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): if not comment.can_see(v): abort(403) - if comment.author.shadowbanned and not (v and v.shadowbanned) and not (v and v.admin_level >= 2): + if comment.author.shadowbanned and not (v and v.shadowbanned) and not (v and v.admin_level >= PERMS['USER_SHADOWBAN']): abort(404) if v and request.values.get("read"): @@ -52,7 +52,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): if comment.post and comment.post.club and not (v and (v.paid_dues or v.id in [comment.author_id, comment.post.author_id])): abort(403) - if not comment.parent_submission and not (v and (comment.author.id == v.id or comment.sentto == v.id)) and not (v and v.admin_level > 1) : abort(403) + if not comment.parent_submission and not (v and (comment.author.id == v.id or comment.sentto == v.id)) and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) : abort(403) if not pid: if comment.parent_submission: pid = comment.parent_submission @@ -96,7 +96,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): blocked.c.target_id, ) - if not (v and v.shadowbanned) and not (v and v.admin_level >= 2): + if not (v and v.shadowbanned) and not (v and v.admin_level >= PERMS['USER_SHADOWBAN']): comments = comments.join(Comment.author).filter(User.shadowbanned == None) comments=comments.filter( diff --git a/files/routes/front.py b/files/routes/front.py index 6e5900b9e..ee9de5134 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -239,7 +239,7 @@ def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all", gt=0, lt=0, comments = g.db.query(Comment.id).filter(Comment.parent_submission != None, Comment.author_id.notin_(v.userblocks)) - if v.admin_level < 2: + if v.admin_level < PERMS['POST_COMMENT_MODERATION']: private = [x[0] for x in g.db.query(Submission.id).filter(Submission.private == True).all()] comments = comments.filter(Comment.is_banned==False, Comment.deleted_utc == 0, Comment.parent_submission.notin_(private)) diff --git a/files/routes/notifications.py b/files/routes/notifications.py index e483508ac..2ac12f904 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -258,7 +258,7 @@ def notifications(v): or_(Comment.sentto == None, Comment.sentto == 2), ).order_by(Notification.created_utc.desc()) - if not (v and (v.shadowbanned or v.admin_level > 2)): + if not (v and (v.shadowbanned or v.admin_level >= 3)): comments = comments.join(Comment.author).filter(User.shadowbanned == None) comments = comments.offset(25 * (page - 1)).limit(26).all() diff --git a/files/routes/posts.py b/files/routes/posts.py index b58a03214..14962181a 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -132,7 +132,7 @@ def post_id(pid, anything=None, v=None, sub=None): blocked.c.target_id, ) - if not (v and v.shadowbanned) and not (v and v.admin_level >= 2): + if not (v and v.shadowbanned) and not (v and v.admin_level >= PERMS['USER_SHADOWBAN']): comments = comments.join(Comment.author).filter(User.shadowbanned == None) comments=comments.filter(Comment.parent_submission == post.id, Comment.level < 10).join( diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 962da38f0..ec0546105 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -95,7 +95,7 @@ def flag_post(pid, v): g.db.add(ma) if v.id != post.author_id: - if v.admin_level >= 3: position = 'Admin' + if v.admin_level >= PERMS['POST_COMMENT_MODERATION']: position = 'Admin' else: position = 'Mod' message = f"@{v.username} ({position}) has moved [{post.title}]({post.shortlink}) to /h/{post.sub}" send_repeatable_notification(post.author_id, message) diff --git a/files/routes/search.py b/files/routes/search.py index 5c325d1ef..616bbcb34 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -282,7 +282,7 @@ def searchusers(v): ) ) - if v.admin_level < 2: + if v.admin_level < PERMS['USER_SHADOWBAN']: users = users.filter(User.shadowbanned == None) users=users.order_by(User.username.ilike(term).desc(), User.stored_subscriber_count.desc()) diff --git a/files/routes/static.py b/files/routes/static.py index ee5435919..3acad856c 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -148,7 +148,7 @@ def log(v): actions = [] else: actions = g.db.query(ModAction) - if not (v and v.admin_level >= 2): + if not (v and v.admin_level >= PERMS['USER_SHADOWBAN']): actions = actions.filter(ModAction.kind.notin_(["shadowban","unshadowban"])) if admin_id: diff --git a/files/templates/comments.html b/files/templates/comments.html index 7779916c2..18618c3a4 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -21,7 +21,7 @@ {% set score=ups-downs %} {% if render_replies %} - {% if v and (v.shadowbanned or v.admin_level >= 2) %} + {% if v and (v.shadowbanned or v.admin_level >= PERMS['USER_SHADOWBAN']) %} {% set replies=c.replies3(sort) %} {% else %} {% set replies=c.replies(sort) %} @@ -140,7 +140,7 @@ {% endif %} {% if c.active_flags(v) %}{{c.active_flags(v)}} Report{{ help.plural(c.active_flags(v)) }}{% endif %} {% if c.over_18 %}+18{% endif %} - {% if v and v.admin_level > 1 and c.author.shadowbanned %}{% endif %} + {% if v and v.admin_level >= PERMS['USER_SHADOWBAN'] and c.author.shadowbanned %}{% endif %} {% if c.stickied %} {% endif %} @@ -485,7 +485,7 @@ {% endif %} -{% if v.admin_level > 1 and v.id != c.author_id %} +{% if v.admin_level >= PERMS['USER_BAN'] and v.id != c.author_id %} {% endif %} diff --git a/files/templates/post_admin_actions_mobile.html b/files/templates/post_admin_actions_mobile.html index bb794e2ef..ee568c0b9 100644 --- a/files/templates/post_admin_actions_mobile.html +++ b/files/templates/post_admin_actions_mobile.html @@ -9,7 +9,7 @@

 						

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

 						

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