From 4b78ed176a7b45abf6c15174a6d0008d55c360ea Mon Sep 17 00:00:00 2001 From: justcool393 Date: Wed, 5 Oct 2022 18:16:52 -0700 Subject: [PATCH] global moderation perm and add some more checks for const perm --- files/classes/user.py | 2 +- files/helpers/const.py | 1 + files/routes/reporting.py | 4 ++-- files/routes/users.py | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 12aed3b0f..1102eec37 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -319,7 +319,7 @@ class User(Base): @lazy def mod_date(self, sub): - if self.admin_level >= 3: return 1 + if self.admin_level >= PERMS['GLOBAL_HOLE_MODERATION']: return 1 mod = g.db.query(Mod).filter_by(user_id=self.id, sub=sub).one_or_none() if not mod: return None return mod.created_utc diff --git a/files/helpers/const.py b/files/helpers/const.py index be6891b77..fa09dc1b0 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -128,6 +128,7 @@ PERMS = { # Minimum admin_level to perform action. 'USER_FOLLOWS_VISIBLE': 0, 'USER_VOTERS_VISIBLE': 0, 'POST_COMMENT_MODERATION': 2, + 'GLOBAL_HOLE_MODERATION': 3, } FEATURES = { diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 4b965faf0..e72f47a49 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -30,7 +30,7 @@ def flag_post(pid, v): if len(reason) > 350: return {"error": "Too long."}, 400 - if reason.startswith('!') and (v.admin_level > 1 or post.sub and v.mods(post.sub)): + 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: @@ -51,7 +51,7 @@ def flag_post(pid, v): ) g.db.add(ma) - elif reason.startswith('/h/') and (v.admin_level >= 2 or v.id == post.author_id or (reason == '/h/chudrama' and v.mods(post.sub))): + elif reason.startswith('/h/') and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == post.author_id or (reason == '/h/chudrama' and v.mods(post.sub))): sub_from = post.sub sub_to = reason[3:].strip().lower() diff --git a/files/routes/users.py b/files/routes/users.py index 54aa674ab..cb87b5026 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1141,14 +1141,14 @@ def u_username_comments(username, v=None): Comment.parent_submission != None ) - if not v or (v.id != u.id and v.admin_level < 2): + if not v or (v.id != u.id and v.admin_level < PERMS['POST_COMMENT_MODERATION']): comments = comments.filter( Comment.is_banned == False, Comment.ghost == False, comment_post_author.shadowbanned == None ) - if not (v and v.admin_level > 1): + if not (v and v.admin_level > PERMS['POST_COMMENT_MODERATION']): comments = comments.filter(Comment.deleted_utc == 0) comments = apply_time_filter(t, comments, Comment)