From 925ec1214148cf8ac802ad2bc905d76535c22b3a Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 12 Oct 2022 08:53:32 +0200 Subject: [PATCH] more shadowban refactor --- files/classes/user.py | 6 +++--- files/helpers/get.py | 4 ++-- files/routes/admin.py | 3 +-- files/routes/comments.py | 4 ++-- files/routes/posts.py | 4 ++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 0547c4fe6e..15970039fd 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -461,7 +461,7 @@ class User(Base): @cache.memoize(timeout=86400) def userpagelisting(self, site=None, v=None, page=1, sort="new", t="all"): - if self.shadowbanned and not (v and (v.admin_level >= PERMS['USER_SHADOWBAN'] or v.id == self.id)): return [] + if self.shadowbanned and not (v and v.can_see_shadowbanned): return [] posts = g.db.query(Submission.id).filter_by(author_id=self.id, is_pinned=False) @@ -593,7 +593,7 @@ class User(Base): Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0) - if not self.shadowbanned and self.admin_level < PERMS['USER_SHADOWBAN']: + if not self.can_see_shadowbanned: notifs = notifs.join(Comment.author).filter(User.shadowbanned == None) return notifs.count() + self.post_notifications_count + self.modaction_notifications_count @@ -618,7 +618,7 @@ class User(Base): Comment.parent_submission == None, ) - if not self.shadowbanned and self.admin_level < PERMS['USER_SHADOWBAN']: + if not self.can_see_shadowbanned: notifs = notifs.join(Comment.author).filter(User.shadowbanned == None) return notifs.count() diff --git a/files/helpers/get.py b/files/helpers/get.py index 6e0bee72c4..52aacc21e8 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 >= PERMS['USER_SHADOWBAN'] or v.shadowbanned)))): + if not user or (user.shadowbanned and not (include_shadowbanned or (v and v.can_see_shadowbanned))): if not graceful: abort(404) else: return None @@ -95,7 +95,7 @@ def get_account(id, v=None, graceful=False, include_blocks=False, include_shadow user = g.db.get(User, id) - if not user or (user.shadowbanned and not (include_shadowbanned or (v and (v.admin_level >= PERMS['USER_SHADOWBAN'] or v.shadowbanned)))): + if not user or (user.shadowbanned and not (include_shadowbanned or (v and v.can_see_shadowbanned))): if not graceful: abort(404) else: return None diff --git a/files/routes/admin.py b/files/routes/admin.py index f430f34c7e..bd2a4f82a7 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -350,9 +350,8 @@ def club_ban(v, username): @app.get("/admin/shadowbanned") -@auth_required +@admin_level_required(PERMS['USER_SHADOWBAN']) def shadowbanned(v): - 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/comments.py b/files/routes/comments.py index 8c4f69b66a..3fbb9445c4 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -36,7 +36,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): comment = get_comment(cid, v=v) 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 >= PERMS['USER_SHADOWBAN']): + if comment.author.shadowbanned and not (v and v.can_see_shadowbanned): abort(404) if v and request.values.get("read"): @@ -86,7 +86,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 >= PERMS['USER_SHADOWBAN']): + if not (v and v.can_see_shadowbanned): comments = comments.join(Comment.author).filter(User.shadowbanned == None) comments=comments.filter( diff --git a/files/routes/posts.py b/files/routes/posts.py index 348132d7a2..797d29202c 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -167,7 +167,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 >= PERMS['USER_SHADOWBAN']): + if not (v and v.can_see_shadowbanned): comments = comments.join(Comment.author).filter(User.shadowbanned == None) comments=comments.filter(Comment.parent_submission == post.id, Comment.level < 10).join( @@ -289,7 +289,7 @@ def viewmore(v, pid, sort, offset): blocked.c.target_id, ).filter(Comment.parent_submission == pid, Comment.stickied == None, Comment.id.notin_(ids), Comment.level < 10) - if not (v and v.shadowbanned) and not (v and v.admin_level >= PERMS['USER_SHADOWBAN']): + if not (v and v.can_see_shadowbanned): comments = comments.join(Comment.author).filter(User.shadowbanned == None) comments=comments.join(