From bf391394a8e74e2b90cfdcfffd78c31a354d4169 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 5 Mar 2022 22:53:39 +0200 Subject: [PATCH] bad PR --- files/classes/user.py | 33 ++++++---------------- files/helpers/wrappers.py | 2 +- files/routes/discord.py | 2 +- files/routes/front.py | 52 ++++++++++------------------------- files/routes/posts.py | 2 +- files/routes/search.py | 33 ++++++++++------------ files/routes/users.py | 10 ++----- files/templates/comments.html | 4 +-- schema.sql | 1 - seed-db.sql | 18 ++++++------ 10 files changed, 53 insertions(+), 104 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 4749164f6..2a9a07f1b 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -67,7 +67,6 @@ class User(Base): comment_count = Column(Integer, default=0) received_award_count = Column(Integer, default=0) created_utc = Column(Integer) - suicide_utc = Column(Integer, default=0) rent_utc = Column(Integer, default=0) steal_utc = Column(Integer, default=0) fail_utc = Column(Integer, default=0) @@ -584,24 +583,18 @@ class User(Base): posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id).all() return [x[0] for x in posts] + @lazy + def userblocks(self): + return [x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=v.id).all()] + [x[0] for x in g.db.query(UserBlock.user_id).filter_by(target_id=v.id).all()] + @lazy def saved_idlist(self, page=1): saved = [x[0] for x in g.db.query(SaveRelationship.submission_id).filter_by(user_id=self.id).all()] posts = g.db.query(Submission.id).filter(Submission.id.in_(saved), Submission.is_banned == False, Submission.deleted_utc == 0) - if self.admin_level == 0: - blocking = [x[0] for x in g.db.query( - UserBlock.target_id).filter_by( - user_id=self.id).all()] - blocked = [x[0] for x in g.db.query( - UserBlock.user_id).filter_by( - target_id=self.id).all()] - - posts = posts.filter( - Submission.author_id.notin_(blocking), - Submission.author_id.notin_(blocked) - ) + if self.admin_level < 2: + posts = posts.filter(Submission.author_id.notin_(self.blocks)) return [x[0] for x in posts.order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).all()] @@ -611,18 +604,8 @@ class User(Base): saved = [x[0] for x in g.db.query(CommentSaveRelationship.comment_id).filter_by(user_id=self.id).all()] comments = g.db.query(Comment.id).filter(Comment.id.in_(saved), Comment.is_banned == False, Comment.deleted_utc == 0) - if self.admin_level == 0: - blocking = [x[0] for x in g.db.query( - UserBlock.target_id).filter_by( - user_id=self.id).all()] - blocked = [x[0] for x in g.db.query( - UserBlock.user_id).filter_by( - target_id=self.id).all()] - - comments = comments.filter( - Comment.author_id.notin_(blocking), - Comment.author_id.notin_(blocked) - ) + if self.admin_level < 2: + comments = comments.filter(Comment.author_id.notin_(self.blocks)) return [x[0] for x in comments.order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).all()] diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 204ebc498..c5f7fbfaf 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -35,7 +35,7 @@ def get_logged_in_user(): return v def check_ban_evade(v): - if v and not v.patron and v.admin_level == 0 and v.ban_evade and not v.unban_utc: + if v and not v.patron and v.admin_level < 2 and v.ban_evade and not v.unban_utc: if randint(0,30) < v.ban_evade: v.shadowbanned = "AutoJanny" else: v.ban_evade +=1 g.db.add(v) diff --git a/files/routes/discord.py b/files/routes/discord.py index 19790f806..81ec4028d 100644 --- a/files/routes/discord.py +++ b/files/routes/discord.py @@ -17,7 +17,7 @@ def join_discord(v): if v.shadowbanned: return {"error": "Internal server error"} - if SITE_NAME == 'Drama' and v.admin_level == 0 and v.patron == 0 and v.truecoins < 150: + if SITE_NAME == 'Drama' and v.admin_level < 2 and v.patron == 0 and v.truecoins < 150: return "You must receive 150 upvotes/downvotes from other users before being able to join the Discord server." now=int(time.time()) diff --git a/files/routes/front.py b/files/routes/front.py index f9c0605de..2e055e922 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -307,17 +307,8 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false" if (sort == "hot" or (v and v.id == Q_ID)) and ccmode == "false" and not gt and not lt: posts = posts.filter_by(stickied=None) - if v and v.admin_level == 0: - blocking = [x[0] for x in g.db.query( - UserBlock.target_id).filter_by( - user_id=v.id).all()] - blocked = [x[0] for x in g.db.query( - UserBlock.user_id).filter_by( - target_id=v.id).all()] - posts = posts.filter( - Submission.author_id.notin_(blocking), - Submission.author_id.notin_(blocked) - ) + if v and v.admin_level < 2: + posts = posts.filter(Submission.author_id.notin_(v.userblocks)) if not (v and v.changelogsub): posts=posts.filter(not_(Submission.title.ilike('[changelog]%'))) @@ -365,10 +356,8 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false" if v and v.all_blocks: pins = pins.filter(or_(Submission.sub == None, Submission.sub.notin_(v.all_blocks))) else: pins = pins.filter(Submission.sub == None) - if v and v.admin_level == 0: - blocking = [x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=v.id).all()] - blocked = [x[0] for x in g.db.query(UserBlock.user_id).filter_by(target_id=v.id).all()] - pins = pins.filter(Submission.author_id.notin_(blocking), Submission.author_id.notin_(blocked)) + if v and v.admin_level < 2: + pins = pins.filter(Submission.author_id.notin_(v.userblocks)) pins = pins.all() @@ -419,17 +408,8 @@ def changeloglist(v=None, sort="new", page=1 ,t="all"): posts = g.db.query(Submission.id).filter_by(is_banned=False, private=False,).filter(Submission.deleted_utc == 0) - if v and v.admin_level == 0: - blocking = [x[0] for x in g.db.query( - UserBlock.target_id).filter_by( - user_id=v.id).all()] - blocked = [x[0] for x in g.db.query( - UserBlock.user_id).filter_by( - target_id=v.id).all()] - posts = posts.filter( - Submission.author_id.notin_(blocking), - Submission.author_id.notin_(blocked) - ) + if v.admin_level < 2: + posts = posts.filter(Submission.author_id.notin_(v.userblocks)) admins = [x[0] for x in g.db.query(User.id).filter(User.admin_level > 0).all()] posts = posts.filter(Submission.title.ilike('_changelog%'), Submission.author_id.in_(admins)) @@ -481,22 +461,18 @@ def random_post(v): @cache.memoize(timeout=86400) def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all"): - cc_or_private = [x[0] for x in g.db.query(Submission.id).filter(or_(Submission.club == True, Submission.private == True)).all()] + comments = g.db.query(Comment.id).filter(Comment.parent_submission != None) - comments = g.db.query(Comment.id).filter(Comment.parent_submission != None, Comment.parent_submission.notin_(cc_or_private)) + if v.admin_level < 2: + private = [x[0] for x in g.db.query(Submission.id).filter(Submission.private == True).all()] - if v and v.admin_level <= 3: - blocking = [x[0] for x in g.db.query( - UserBlock.target_id).filter_by( - user_id=v.id).all()] - blocked = [x[0] for x in g.db.query( - UserBlock.user_id).filter_by( - target_id=v.id).all()] + comments = comments.filter(Comment.author_id.notin_(v.userblocks), Comment.is_banned==False, Comment.deleted_utc == 0, Comment.parent_submission.notin_(private)) - comments = comments.filter(Comment.author_id.notin_(blocking), Comment.author_id.notin_(blocked)) - if not v or not v.admin_level > 1: - comments = comments.filter(Comment.is_banned==False, Comment.deleted_utc == 0) + if not v.paid_dues: + club = [x[0] for x in g.db.query(Submission.id).filter(Submission.club == True).all()] + comments = comments.filter(Comment.parent_submission.notin_(club)) + now = int(time.time()) if t == 'hour': diff --git a/files/routes/posts.py b/files/routes/posts.py index aa17d8a13..3ff56bcd9 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -73,7 +73,7 @@ def toggle_club(pid, v): if v.club_allowed == False: abort(403) post = get_post(pid) - if post.author_id != v.id and v.admin_level == 0: abort(403) + if post.author_id != v.id and v.admin_level < 2: abort(403) post.club = not post.club g.db.add(post) diff --git a/files/routes/search.py b/files/routes/search.py index 47be37ec8..d730ee558 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -57,9 +57,11 @@ def searchposts(v): posts = g.db.query(Submission.id) - if not (v and v.paid_dues): posts = posts.filter(Submission.club == False) + if not v.paid_dues: posts = posts.filter_by(club=False) - if not (v and v.admin_level > 1): posts = posts.filter(Submission.private == False) + if v.admin_level < 2: + posts = posts.filter(Submission.deleted_utc == 0, Submission.is_banned == False, Submission.private == False, Submission.author_id.notin_(v.userblocks)) + if 'author' in criteria: @@ -114,21 +116,6 @@ def searchposts(v): ) ) - if not (v and v.admin_level > 1): posts = posts.filter(Submission.deleted_utc == 0, Submission.is_banned == False) - - if v and v.admin_level > 1: pass - elif v: - blocking = [x[0] for x in g.db.query( - UserBlock.target_id).filter_by( - user_id=v.id).all()] - blocked = [x[0] for x in g.db.query( - UserBlock.user_id).filter_by( - target_id=v.id).all()] - - posts = posts.filter( - Submission.author_id.notin_(blocking), - Submission.author_id.notin_(blocked), - ) if t: now = int(time.time()) @@ -232,8 +219,6 @@ def searchcomments(v): if 'over18' in criteria: comments = comments.filter(Comment.over_18 == True) - if not (v and v.admin_level > 1): comments = comments.filter(Comment.deleted_utc == 0, Comment.is_banned == False) - if t: now = int(time.time()) if t == 'hour': @@ -251,6 +236,16 @@ def searchcomments(v): comments = comments.filter(Comment.created_utc >= cutoff) + if v.admin_level < 2: + private = [x[0] for x in g.db.query(Submission.id).filter(Submission.private == True).all()] + + comments = comments.filter(Comment.author_id.notin_(v.userblocks), Comment.is_banned==False, Comment.deleted_utc == 0, Comment.parent_submission.notin_(private)) + + + if not v.paid_dues: + club = [x[0] for x in g.db.query(Submission.id).filter(Submission.club == True).all()] + comments = comments.filter(Comment.parent_submission.notin_(club)) + if sort == "new": comments = comments.order_by(Comment.created_utc.desc()) diff --git a/files/routes/users.py b/files/routes/users.py index 4d00c1ac5..c9126ec9a 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -251,16 +251,12 @@ def thiefs(v): @app.post("/@/suicide") -@limiter.limit("1/second;30/minute;200/hour;1000/day") +@limiter.limit("5/day") @auth_required def suicide(v, username): - t = int(time.time()) - if v.admin_level == 0 and t - v.suicide_utc < 86400: return {"message": "You're on 1-day cooldown!"} user = get_user(username) suicide = f"Hi there,\n\nA [concerned user](/id/{v.id}) reached out to us about you.\n\nWhen you're in the middle of something painful, it may feel like you don't have a lot of options. But whatever you're going through, you deserve help and there are people who are here for you.\n\nThere are resources available in your area that are free, confidential, and available 24/7:\n\n- Call, Text, or Chat with Canada's [Crisis Services Canada](https://www.crisisservicescanada.ca/en/)\n- Call, Email, or Visit the UK's [Samaritans](https://www.samaritans.org/)\n- Text CHAT to America's [Crisis Text Line](https://www.crisistextline.org/) at 741741.\nIf you don't see a resource in your area above, the moderators keep a comprehensive list of resources and hotlines for people organized by location. Find Someone Now\n\nIf you think you may be depressed or struggling in another way, don't ignore it or brush it aside. Take yourself and your feelings seriously, and reach out to someone.\n\nIt may not feel like it, but you have options. There are people available to listen to you, and ways to move forward.\n\nYour fellow users care about you and there are people who want to help." - send_repeatable_notification(user.id, suicide) - v.suicide_utc = t - g.db.add(v) + send_notification(user.id, suicide) g.db.commit() return {"message": "Help message sent!"} @@ -826,7 +822,7 @@ def u_username_comments(username, v=None): comments = g.db.query(Comment.id).filter(Comment.author_id == u.id, Comment.parent_submission != None) - if not v or (v.id != u.id and v.admin_level == 0): + if not v or (v.id != u.id and v.admin_level < 2): comments = comments.filter(Comment.deleted_utc == 0, Comment.is_banned == False, Comment.ghost == False) now = int(time.time()) diff --git a/files/templates/comments.html b/files/templates/comments.html index 6b7121f0c..1833b0b08 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -432,7 +432,7 @@