From 68851ed986604f72cf656349121de789f0792eb3 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Wed, 5 Oct 2022 22:07:38 -0700 Subject: [PATCH] profile views and modmail/hole creation notifications --- files/classes/user.py | 2 +- files/helpers/const.py | 3 +++ files/routes/static.py | 2 +- files/routes/subs.py | 2 +- files/routes/users.py | 22 +++++++++++----------- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 68e917aab..96e3350ad 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -903,7 +903,7 @@ class User(Base): def viewers_recorded(self): if SITE_NAME == 'WPD': # WPD gets profile views return True - elif self.admin_level >= 2: # Admins get profile views + elif self.admin_level >= PERMS['VIEW_PROFILE_VIEWS']: # Admins get profile views return True elif self.patron: # Patrons get profile views as a perk return True diff --git a/files/helpers/const.py b/files/helpers/const.py index b29ab6e86..4e8733ac7 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -154,6 +154,7 @@ PERMS = { # Minimum admin_level to perform action. 'VIEW_CHUDRAMA': 1, 'VIEW_PRIVATE_PROFILES': 2, 'VIEW_ALTS': 2, + 'VIEW_PROFILE_VIEWS': 2, 'PRINT_MARSEYBUX_FOR_KIPPY_ON_PCMEMES': 3, 'VIEW_ACTIVE_USERS': 2, 'MERGE_USERS': 3, # note: extra check for Aevann @@ -169,7 +170,9 @@ PERMS = { # Minimum admin_level to perform action. 'CACHE_DUMP_INTERNAL': 2, 'DOMAINS_BAN': 3, 'NOTIFICATIONS_HOLE_INACTIVITY_DELETION': 2, + 'NOTIFICATIONS_HOLE_CREATION': 2, 'NOTIFICATIONS_FROM_SHADOWBANNED_USERS': 3, + 'NOTIFICATIONS_MODMAIL': 3, } FEATURES = { diff --git a/files/routes/static.py b/files/routes/static.py index 3acad856c..5e619cf48 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -235,7 +235,7 @@ def submit_contact(v): g.db.flush() new_comment.top_comment_id = new_comment.id - admins = g.db.query(User).filter(User.admin_level > 2) + admins = g.db.query(User).filter(User.admin_level >= PERMS['NOTIFICATIONS_MODMAIL']) if SITE == 'watchpeopledie.co': admins = admins.filter(User.id != AEVANN_ID) diff --git a/files/routes/subs.py b/files/routes/subs.py index fb0529933..486214e7d 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -345,7 +345,7 @@ def create_sub2(v): mod = Mod(user_id=v.id, sub=sub.name) g.db.add(mod) - admins = [x[0] for x in g.db.query(User.id).filter(User.admin_level > 1, User.id != v.id).all()] + admins = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_HOLE_CREATION'], User.id != v.id).all()] for admin in admins: send_repeatable_notification(admin, f":!marseyparty: /h/{sub} has been created by @{v.username} :marseyparty:") diff --git a/files/routes/users.py b/files/routes/users.py index 9f791204b..13f712b5a 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -62,7 +62,7 @@ gevent.spawn(leaderboard_thread) @auth_required def upvoters_posts(v, username, uid): u = get_user(username, v=v, include_shadowbanned=False) - if u.is_private and (not v or (v.id != u.id and v.admin_level < 2 and not v.eye)): abort(403) + if u.is_private and (not v or (v.id != u.id and v.admin_level < PERMS['VIEW_PRIVATE_PROFILES'] and not v.eye)): abort(403) if not (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']): abort(403) id = u.id uid = int(uid) @@ -84,7 +84,7 @@ def upvoters_posts(v, username, uid): @auth_required def upvoters_comments(v, username, uid): u = get_user(username, v=v, include_shadowbanned=False) - if u.is_private and (not v or (v.id != u.id and v.admin_level < 2 and not v.eye)): abort(403) + if u.is_private and (not v or (v.id != u.id and v.admin_level < PERMS['VIEW_PRIVATE_PROFILES'] and not v.eye)): abort(403) if not (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']): abort(403) id = u.id uid = int(uid) @@ -106,7 +106,7 @@ def upvoters_comments(v, username, uid): @auth_required def downvoters_posts(v, username, uid): u = get_user(username, v=v, include_shadowbanned=False) - if u.is_private and (not v or (v.id != u.id and v.admin_level < 2 and not v.eye)): abort(403) + if u.is_private and (not v or (v.id != u.id and v.admin_level < PERMS['VIEW_PRIVATE_PROFILES'] and not v.eye)): abort(403) if not (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']): abort(403) id = u.id uid = int(uid) @@ -128,7 +128,7 @@ def downvoters_posts(v, username, uid): @auth_required def downvoters_comments(v, username, uid): u = get_user(username, v=v, include_shadowbanned=False) - if u.is_private and (not v or (v.id != u.id and v.admin_level < 2 and not v.eye)): abort(403) + if u.is_private and (not v or (v.id != u.id and v.admin_level < PERMS['VIEW_PRIVATE_PROFILES'] and not v.eye)): abort(403) if not (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']): abort(403) id = u.id uid = int(uid) @@ -153,7 +153,7 @@ def downvoters_comments(v, username, uid): @auth_required def upvoting_posts(v, username, uid): u = get_user(username, v=v, include_shadowbanned=False) - if u.is_private and (not v or (v.id != u.id and v.admin_level < 2 and not v.eye)): abort(403) + if u.is_private and (not v or (v.id != u.id and v.admin_level < PERMS['VIEW_PRIVATE_PROFILES'] and not v.eye)): abort(403) if not (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']): abort(403) id = u.id uid = int(uid) @@ -175,7 +175,7 @@ def upvoting_posts(v, username, uid): @auth_required def upvoting_comments(v, username, uid): u = get_user(username, v=v, include_shadowbanned=False) - if u.is_private and (not v or (v.id != u.id and v.admin_level < 2 and not v.eye)): abort(403) + if u.is_private and (not v or (v.id != u.id and v.admin_level < PERMS['VIEW_PRIVATE_PROFILES'] and not v.eye)): abort(403) if not (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']): abort(403) id = u.id uid = int(uid) @@ -197,7 +197,7 @@ def upvoting_comments(v, username, uid): @auth_required def downvoting_posts(v, username, uid): u = get_user(username, v=v, include_shadowbanned=False) - if u.is_private and (not v or (v.id != u.id and v.admin_level < 2 and not v.eye)): abort(403) + if u.is_private and (not v or (v.id != u.id and v.admin_level < PERMS['VIEW_PRIVATE_PROFILES'] and not v.eye)): abort(403) if not (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']): abort(403) id = u.id uid = int(uid) @@ -219,7 +219,7 @@ def downvoting_posts(v, username, uid): @auth_required def downvoting_comments(v, username, uid): u = get_user(username, v=v, include_shadowbanned=False) - if u.is_private and (not v or (v.id != u.id and v.admin_level < 2 and not v.eye)): abort(403) + if u.is_private and (not v or (v.id != u.id and v.admin_level < PERMS['VIEW_PRIVATE_PROFILES'] and not v.eye)): abort(403) if not (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']): abort(403) id = u.id uid = int(uid) @@ -241,7 +241,7 @@ def downvoting_comments(v, username, uid): @auth_required def user_upvoted_posts(v, username): u = get_user(username, v=v, include_shadowbanned=False) - if u.is_private and (not v or (v.id != u.id and v.admin_level < 2 and not v.eye)): abort(403) + if u.is_private and (not v or (v.id != u.id and v.admin_level < PERMS['VIEW_PRIVATE_PROFILES'] and not v.eye)): abort(403) if not (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']): abort(403) page = max(1, int(request.values.get("page", 1))) @@ -267,7 +267,7 @@ def user_upvoted_posts(v, username): @auth_required def user_upvoted_comments(v, username): u = get_user(username, v=v, include_shadowbanned=False) - if u.is_private and (not v or (v.id != u.id and v.admin_level < 2 and not v.eye)): abort(403) + if u.is_private and (not v or (v.id != u.id and v.admin_level < PERMS['VIEW_PRIVATE_PROFILES'] and not v.eye)): abort(403) if not (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']): abort(403) page = max(1, int(request.values.get("page", 1))) @@ -877,7 +877,7 @@ def messagereply(v): if c.top_comment.sentto == 2: - admins = g.db.query(User.id).filter(User.admin_level > 2, User.id != v.id) + admins = g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_MODMAIL'], User.id != v.id) if SITE == 'watchpeopledie.co': admins = admins.filter(User.id != AEVANN_ID)