diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index d842c56bd..6da73cc28 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -164,4 +164,24 @@ if PUSHER_ID != 'blahblahblah': } }, ) - stdout.flush() \ No newline at end of file + stdout.flush() + + + +def on_post_hole_entered(post, v=None): + if not post.sub or not post.subr: + return + hole = post.subr.name + author = post.author + + # Notify hole followers + if not post.ghost and not post.private and not author.shadowbanned: + text = f"/h/{hole} has a new " \ + + f"post: [{post.title}]({post.shortlink}) by @{author.username}" + cid = notif_comment(text, autojanny=True) + for follow in post.subr.followers: + if follow.user_id == author.id or (v and follow.user_id == v.id): + continue + user = get_account(follow.user_id) + if post.club and not user.paid_dues: continue + add_notif(cid, user.id) \ No newline at end of file diff --git a/files/routes/posts.py b/files/routes/posts.py index 01bba4816..c990fbfb3 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -10,7 +10,6 @@ from files.helpers.regex import * from files.helpers.slots import * from files.helpers.get import * from files.classes import * -from files.routes.subs import on_post_hole_entered from flask import * from io import BytesIO from files.__main__ import app, limiter, cache, db_session diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 3f317f5ef..9ed6178b9 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -1,10 +1,10 @@ from files.helpers.wrappers import * from files.helpers.get import * +from files.helpers.alerts import * from flask import g from files.__main__ import app, limiter from os import path from files.helpers.sanitize import filter_emojis_only -from files.routes.subs import rehole_post @app.post("/report/post/") @limiter.limit("1/second;30/minute;200/hour;1000/day") @@ -40,8 +40,33 @@ def api_flag_post(pid, v): _note=f'"{post.flair}"' ) g.db.add(ma) - elif reason.startswith('/h/') and v.admin_level >= 2: - rehole_post(pid=post.id, hole=reason[3:]) + elif reason.startswith('/h/') and v.admin_level >= 2 or v.id == post.author_id: + + sub_from = post.sub + sub_to = reason[3:].strip().lower() + sub_to = g.db.query(Sub).filter_by(name=sub_to).one_or_none() + sub_to = sub_to.name if sub_to else None + + if sub_from == sub_to: abort(400) + post.sub = sub_to + g.db.add(post) + + if v.admin_level and v.id != post.author_id: + sub_from_str = 'frontpage' if sub_from is None else \ + f'/h/{sub_from}' + sub_to_str = 'frontpage' if sub_to is None else \ + f'/h/{sub_to}' + ma = ModAction( + kind='move_hole', + user_id=v.id, + target_submission_id=post.id, + _note=f'{sub_from_str} → {sub_to_str}', + ) + g.db.add(ma) + + on_post_hole_entered(post, v) + + return {"message": f"Post moved to /h/{post.sub}"} else: flag = Flag(post_id=post.id, user_id=v.id, reason=reason) g.db.add(flag) diff --git a/files/routes/subs.py b/files/routes/subs.py index 42cbdfdf7..0fed0e7ba 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -315,56 +315,6 @@ def kick(v, pid): return {"message": "Post kicked successfully!"} -@app.post("/rehole/", defaults={'hole': ''}) -@app.post("/rehole//") -@admin_level_required(2) -def rehole_post(v, pid, hole): - post = get_post(pid) - - sub_from = post.sub - sub_to = hole.strip().lower() - sub_to = g.db.query(Sub).filter_by(name=sub_to).one_or_none() - sub_to = sub_to.name if sub_to else None - - if sub_from == sub_to: - abort(400) - post.sub = sub_to - g.db.add(post) - - sub_from_str = 'frontpage' if sub_from is None else \ - f'/h/{sub_from}' - sub_to_str = 'frontpage' if sub_to is None else \ - f'/h/{sub_to}' - ma = ModAction( - kind='move_hole', - user_id=v.id, - target_submission_id=post.id, - _note=f'{sub_from_str} → {sub_to_str}', - ) - g.db.add(ma) - - on_post_hole_entered(post, v) - - return {"message": f"Post moved to {sub_to_str}!"} - -def on_post_hole_entered(post, v=None): - if not post.sub or not post.subr: - return - hole = post.subr.name - author = post.author - - # Notify hole followers - if not post.ghost and not post.private and not author.shadowbanned: - text = f"/h/{hole} has a new " \ - + f"post: [{post.title}]({post.shortlink}) by @{author.username}" - cid = notif_comment(text, autojanny=True) - for follow in post.subr.followers: - if follow.user_id == author.id or (v and follow.user_id == v.id): - continue - user = get_account(follow.user_id) - if post.club and not user.paid_dues: continue - add_notif(cid, user.id) - @app.get('/h//settings') @is_not_permabanned def sub_settings(v, sub):