diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index c1d6edb23..ad82c84b4 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -86,21 +86,4 @@ def NOTIFY_USERS2(text, v): user = get_user(i.group(2), graceful=True) if user and not v.any_block_exists(user): notify_users.add(user.id) - return notify_users - -def send_admin(id, body_html, vid=None): - - new_comment = Comment(author_id=id, - parent_submission=None, - level=1, - sentto=2, - body_html=body_html, - ) - g.db.add(new_comment) - g.db.flush() - - if vid: admins = g.db.query(User).filter(User.admin_level > 2, User.id != vid).all() - else: admins = g.db.query(User).filter(User.admin_level > 2).all() - for admin in admins: - notif = Notification(comment_id=new_comment.id, user_id=admin.id) - g.db.add(notif) \ No newline at end of file + return notify_users \ No newline at end of file diff --git a/files/routes/admin.py b/files/routes/admin.py index 75ebf6284..df826c72e 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -883,7 +883,19 @@ def shadowban(user_id, v): body_html = sanitize(body) - send_admin(NOTIFICATIONS_ID, body_html, v.id) + + new_comment = Comment(author_id=NOTIFICATIONS_ID, + parent_submission=None, + level=1, + body_html=body_html, + ) + g.db.add(new_comment) + g.db.flush() + for admin in g.db.query(User).filter(User.admin_level > 2, User.id != v.id).all(): + notif = Notification(comment_id=new_comment.id, user_id=admin.id) + g.db.add(notif) + + g.db.commit() return {"message": "User shadowbanned!"} @@ -1052,7 +1064,18 @@ def ban_user(user_id, v): body_html = sanitize(body) - send_admin(NOTIFICATIONS_ID, body_html, v.id) + + new_comment = Comment(author_id=NOTIFICATIONS_ID, + parent_submission=None, + level=1, + body_html=body_html, + ) + g.db.add(new_comment) + g.db.flush() + for admin in g.db.query(User).filter(User.admin_level > 2, User.id != v.id).all(): + notif = Notification(comment_id=new_comment.id, user_id=admin.id) + g.db.add(notif) + g.db.commit() diff --git a/files/routes/front.py b/files/routes/front.py index b805f2af4..bc295e184 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -42,9 +42,8 @@ def notifications(v): modmail = request.values.get('modmail') posts = request.values.get('posts') if modmail and v.admin_level > 1: - comments = g.db.query(Comment).filter(Comment.sentto==2).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all() - next_exists = (len(comments) > 25) - comments = comments[:25] + comments = g.db.query(Comment).filter(Comment.sentto==2).order_by(Comment.id.desc()).all() + next_exists = False elif messages: comments = g.db.query(Comment).filter(or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None, not_(Comment.child_comments.any())).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all() next_exists = (len(comments) > 25) diff --git a/files/routes/login.py b/files/routes/login.py index c49f7edf0..e551eb98f 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -225,7 +225,7 @@ def sign_up_get(v): @app.post("/signup") -@limiter.limit("5/day") +@limiter.limit("10/day") @auth_desired def sign_up_post(v): with open('disable_signups', 'r') as f: diff --git a/files/routes/oauth.py b/files/routes/oauth.py index 16e3ec6de..488874740 100644 --- a/files/routes/oauth.py +++ b/files/routes/oauth.py @@ -51,7 +51,19 @@ def request_api_keys(v): body_html = sanitize(body, noimages=True) - send_admin(NOTIFICATIONS_ID, body_html) + + new_comment = Comment(author_id=NOTIFICATIONS_ID, + parent_submission=None, + level=1, + body_html=body_html, + sentto=2 + ) + g.db.add(new_comment) + g.db.flush() + for admin in g.db.query(User).filter(User.admin_level > 2).all(): + notif = Notification(comment_id=new_comment.id, user_id=admin.id) + g.db.add(notif) + g.db.commit() diff --git a/files/routes/static.py b/files/routes/static.py index abbb16e69..1c715937e 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -304,7 +304,21 @@ def submit_contact(v): body_html += f"

{url}

" else: return {"error": "Image/Video files only"}, 400 - send_admin(v.id, body_html) + + + new_comment = Comment(author_id=v.id, + parent_submission=None, + level=1, + body_html=body_html, + sentto=2 + ) + g.db.add(new_comment) + g.db.flush() + for admin in g.db.query(User).filter(User.admin_level > 1).all(): + notif = Notification(comment_id=new_comment.id, user_id=admin.id) + g.db.add(notif) + + g.db.commit() return render_template("contact.html", v=v, msg="Your message has been sent.")