From 48384ba8e55c35d80fd20527755b1627be05e746 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Fri, 7 Oct 2022 01:50:20 -0700 Subject: [PATCH] convert a couple of the old constantified permissions to the new system i don't want to break something so i'm keeping one of them for now but it just links --- files/classes/user.py | 2 +- files/helpers/const.py | 7 +++---- files/helpers/offsitementions.py | 9 +++++---- files/routes/notifications.py | 2 +- files/templates/notifications.html | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index a3e1c09f8..717dac50a 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -379,7 +379,7 @@ class User(Base): @property @lazy def can_view_offsitementions(self): - return self.offsitementions or self.admin_level >= REDDIT_NOTIFS_JL_MIN + return self.offsitementions or self.admin_level >= PERMS['NOTIFICATIONS_REDDIT'] @property @lazy diff --git a/files/helpers/const.py b/files/helpers/const.py index ae9d10f20..262876cf5 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -186,6 +186,8 @@ PERMS = { # Minimum admin_level to perform action. 'NOTIFICATIONS_HOLE_CREATION': 2, 'NOTIFICATIONS_FROM_SHADOWBANNED_USERS': 3, 'NOTIFICATIONS_MODMAIL': 3, + 'NOTIFICATIONS_MODERATOR_ACTIONS': 2, + 'NOTIFICATIONS_REDDIT': 1, 'NOTIFICATIONS_SPECIFIC_WPD_COMMENTS': 1, 'MESSAGE_BLOCKED_USERS': 1, 'APPS_MODERATION': 3, @@ -945,11 +947,8 @@ FACTCHECK_REPLIES = ('Factcheck: This claim has been co EIGHTBALL_REPLIES = ('The 8-Ball Says: It is certain.', 'The 8-Ball Says: It is decidedly so.', 'The 8-Ball Says: Without a doubt.', 'The 8-Ball Says: Yes definitely.', 'The 8-Ball Says: You may rely on it.', 'The 8-Ball Says: As I see it, yes.', 'The 8-Ball Says: Most likely.', 'The 8-Ball Says: Outlook good.', 'The 8-Ball Says: Yes.', 'The 8-Ball Says: Signs point to yes.', 'The 8-Ball Says: Reply hazy, try again.', 'The 8-Ball Says: Ask again later.', 'The 8-Ball Says: Better not tell you now.', 'The 8-Ball Says: Cannot predict now.', 'The 8-Ball Says: Concentrate and ask again.', 'The 8-Ball Says: Don\'t count on it.', 'The 8-Ball Says: My reply is no.', 'The 8-Ball Says: My sources say no.', 'The 8-Ball Says: Outlook not so good.', 'The 8-Ball Says: Very doubtful.') +NOTIF_MODACTION_JL_MIN = PERMS['NOTIFICATIONS_MODERATOR_ACTIONS'] - -NOTIF_MODACTION_JL_MIN = 2 - -REDDIT_NOTIFS_JL_MIN = 1 REDDIT_NOTIFS_SITE = set() REDDIT_NOTIFS_USERS = {} diff --git a/files/helpers/offsitementions.py b/files/helpers/offsitementions.py index 85f967981..c59c07c03 100644 --- a/files/helpers/offsitementions.py +++ b/files/helpers/offsitementions.py @@ -8,15 +8,16 @@ from files.classes.comment import Comment from files.classes.notifications import Notification from files.helpers.sanitize import sanitize -# https://api.pushshift.io/meta provides key server_ratelimit_per_minute -# At time of writing, the ratelimit is 120 req/min. We get nowhere near this +# Note: while https://api.pushshift.io/meta provides the key +# server_ratelimit_per_minute, in practice Cloudflare puts stricter, +# unofficially documented limits at around 60/minute. We get nowhere near this # with current keyword quantities. If this ever changes, consider reading the -# value from /meta and doing a random selection of keywords. +# value from /meta (or just guessing) and doing a random selection of keywords. def offsite_mentions_task(): if const.REDDIT_NOTIFS_SITE: row_send_to = g.db.query(User.id) \ - .filter(or_(User.admin_level >= const.REDDIT_NOTIFS_JL_MIN, + .filter(or_(User.admin_level >= const.PERMS['NOTIFICATIONS_REDDIT'], User.offsitementions == True)).all() send_to = [x[0] for x in row_send_to] diff --git a/files/routes/notifications.py b/files/routes/notifications.py index 098ba10d4..f76e31196 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -172,7 +172,7 @@ def notifications_posts(v): @app.get("/notifications/modactions") -@admin_level_required(NOTIF_MODACTION_JL_MIN) +@admin_level_required(PERMS['NOTIFICATIONS_MODERATOR_ACTIONS']) def notifications_modactions(v): try: page = max(int(request.values.get("page", 1)), 1) except: page = 1 diff --git a/files/templates/notifications.html b/files/templates/notifications.html index 5093935ae..2ecaa56c5 100644 --- a/files/templates/notifications.html +++ b/files/templates/notifications.html @@ -30,7 +30,7 @@ Posts {% if v.post_notifications_count %}({{v.post_notifications_count}}){% endif %} - {% if v.admin_level >= NOTIF_MODACTION_JL_MIN %} + {% if v.admin_level >= PERMS['NOTIFICATIONS_MODERATOR_ACTIONS'] %}