master
Aevann1 2022-02-21 03:58:12 +02:00
parent 0dcd415c31
commit 833009bd14
6 changed files with 57 additions and 26 deletions

View File

@ -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)
return notify_users

View File

@ -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()

View File

@ -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)

View File

@ -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:

View File

@ -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()

View File

@ -304,7 +304,21 @@ def submit_contact(v):
body_html += f"<p>{url}</p>"
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.")