2022-05-04 23:09:46 +00:00
|
|
|
from flask import g
|
2022-11-15 09:19:08 +00:00
|
|
|
|
2023-06-23 16:49:23 +00:00
|
|
|
from files.classes.reports import Report, CommentReport
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.classes.mod_logs import ModAction
|
2023-10-07 17:55:50 +00:00
|
|
|
from files.classes.hole_logs import HoleAction
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.helpers.actions import *
|
|
|
|
from files.helpers.alerts import *
|
|
|
|
from files.helpers.get import *
|
2022-05-04 23:09:46 +00:00
|
|
|
from files.helpers.sanitize import filter_emojis_only
|
2022-11-14 09:14:41 +00:00
|
|
|
from files.routes.front import frontlist
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.routes.wrappers import *
|
|
|
|
from files.__main__ import app, limiter, cache
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/report/post/<int:pid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-08-05 02:26:08 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-05-04 23:09:46 +00:00
|
|
|
@auth_required
|
2023-06-23 16:49:23 +00:00
|
|
|
def report_post(pid, v):
|
2022-05-04 23:09:46 +00:00
|
|
|
post = get_post(pid)
|
|
|
|
reason = request.values.get("reason", "").strip()
|
2023-05-14 20:36:05 +00:00
|
|
|
execute_under_siege(v, post, reason, 'report')
|
|
|
|
execute_blackjack(v, post, reason, 'report')
|
2024-01-02 18:54:08 +00:00
|
|
|
|
|
|
|
if len(reason) > 100:
|
|
|
|
abort(400, "Report reason is too long (max 100 characters)")
|
|
|
|
|
2022-12-13 16:54:11 +00:00
|
|
|
og_flair = reason[1:]
|
2023-04-27 15:35:07 +00:00
|
|
|
reason_html = filter_emojis_only(reason)
|
|
|
|
if len(reason_html) > 350:
|
2024-02-14 09:34:49 +00:00
|
|
|
abort(400, "Rendered report reason is too long!")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-01-12 07:18:04 +00:00
|
|
|
if reason.startswith('!') and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or post.hole and v.mods_hole(post.hole)):
|
2023-04-27 15:35:07 +00:00
|
|
|
post.flair = reason_html[1:]
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(post)
|
2022-10-06 01:58:43 +00:00
|
|
|
if v.admin_level >= PERMS['POST_COMMENT_MODERATION']:
|
2024-01-31 21:56:32 +00:00
|
|
|
ma = ModAction(
|
2022-08-20 20:14:20 +00:00
|
|
|
kind="flair_post",
|
|
|
|
user_id=v.id,
|
2023-06-07 23:26:32 +00:00
|
|
|
target_post_id=post.id,
|
2022-08-20 20:14:20 +00:00
|
|
|
_note=f'"{post.flair}"'
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-12-13 17:11:26 +00:00
|
|
|
position = 'a site admin'
|
2022-09-29 09:39:37 +00:00
|
|
|
else:
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=post.hole,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind="flair_post",
|
|
|
|
user_id=v.id,
|
2023-06-07 23:26:32 +00:00
|
|
|
target_post_id=post.id,
|
2022-09-29 10:18:27 +00:00
|
|
|
_note=f'"{post.flair}"'
|
2022-09-29 09:39:37 +00:00
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2023-10-07 17:55:50 +00:00
|
|
|
position = f'a /h/{post.hole} mod'
|
2022-11-11 17:04:31 +00:00
|
|
|
|
|
|
|
if v.id != post.author_id:
|
2022-12-13 16:54:11 +00:00
|
|
|
message = f'@{v.username} ({position}) has flaired [{post.title}]({post.shortlink}) with the flair: `"{og_flair}"`'
|
2022-11-11 17:04:31 +00:00
|
|
|
send_repeatable_notification(post.author_id, message)
|
|
|
|
|
2022-11-03 00:24:00 +00:00
|
|
|
return {"message": "Post flaired successfully!"}
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-07-22 16:37:57 +00:00
|
|
|
if v.is_muted: abort(403, "You are forbidden from making reports!")
|
|
|
|
|
2023-06-23 16:49:23 +00:00
|
|
|
existing = g.db.query(Report.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none()
|
2022-11-03 00:24:00 +00:00
|
|
|
if existing: abort(409, "You already reported this post!")
|
2023-06-23 16:49:23 +00:00
|
|
|
report = Report(post_id=post.id, user_id=v.id, reason=reason_html)
|
|
|
|
g.db.add(report)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-11-18 13:20:21 +00:00
|
|
|
if v.id != post.author_id and not post.author.has_blocked(v) and not post.author.has_muted(v):
|
2023-03-18 10:59:30 +00:00
|
|
|
message = f'@{v.username} reported [{post.title}]({post.shortlink})\n\n> {reason}'
|
|
|
|
send_repeatable_notification(post.author_id, message)
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
return {"message": "Post reported!"}
|
|
|
|
|
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/report/comment/<int:cid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-08-05 02:26:08 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-05-04 23:09:46 +00:00
|
|
|
@auth_required
|
2023-06-23 16:49:23 +00:00
|
|
|
def report_comment(cid, v):
|
2023-03-22 22:27:56 +00:00
|
|
|
if v.is_muted: abort(403, "You are forbidden from making reports!")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
comment = get_comment(cid)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2023-06-23 16:49:23 +00:00
|
|
|
existing = g.db.query(CommentReport.comment_id).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
2022-10-11 14:51:14 +00:00
|
|
|
if existing: abort(409, "You already reported this comment!")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
reason = request.values.get("reason", "").strip()
|
2023-05-14 20:36:05 +00:00
|
|
|
execute_under_siege(v, comment, reason, 'report')
|
|
|
|
execute_blackjack(v, comment, reason, 'report')
|
2024-01-02 18:54:08 +00:00
|
|
|
|
|
|
|
if len(reason) > 100:
|
|
|
|
abort(400, "Report reason is too long (max 100 characters)")
|
|
|
|
|
2023-04-27 15:35:07 +00:00
|
|
|
reason_html = filter_emojis_only(reason)
|
2024-02-14 09:34:49 +00:00
|
|
|
if len(reason_html) > 350:
|
|
|
|
abort(400, "Rendered report reason is too long!")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-06-23 16:49:23 +00:00
|
|
|
report = CommentReport(comment_id=comment.id, user_id=v.id, reason=reason_html)
|
|
|
|
g.db.add(report)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-11-18 13:20:21 +00:00
|
|
|
if v.id != comment.author_id and not comment.author.has_blocked(v) and not comment.author.has_muted(v):
|
2023-03-18 10:59:30 +00:00
|
|
|
message = f'@{v.username} reported your [comment]({comment.shortlink})\n\n> {reason}'
|
|
|
|
send_repeatable_notification(comment.author_id, message)
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
return {"message": "Comment reported!"}
|
|
|
|
|
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post('/del_report/post/<int:pid>/<int:uid>')
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit("100/minute;300/hour;2000/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("100/minute;300/hour;2000/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2024-01-31 21:14:20 +00:00
|
|
|
@auth_required
|
2022-05-04 23:09:46 +00:00
|
|
|
def remove_report_post(v, pid, uid):
|
2023-06-23 16:49:23 +00:00
|
|
|
report = g.db.query(Report).filter_by(post_id=pid, user_id=uid).one_or_none()
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-06-07 10:32:48 +00:00
|
|
|
if report:
|
2024-01-31 21:14:20 +00:00
|
|
|
if v.id != report.user_id and v.admin_level < PERMS['REPORTS_REMOVE']:
|
|
|
|
abort(403, "You can't remove this report!")
|
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.delete(report)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-01-31 21:56:15 +00:00
|
|
|
if v.id != report.user_id:
|
2024-01-31 21:56:32 +00:00
|
|
|
ma = ModAction(
|
2024-01-31 21:56:15 +00:00
|
|
|
kind="delete_report",
|
|
|
|
user_id=v.id,
|
|
|
|
target_post_id=pid
|
|
|
|
)
|
2024-01-31 22:15:21 +00:00
|
|
|
g.db.add(ma)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
return {"message": "Report removed successfully!"}
|
|
|
|
|
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post('/del_report/comment/<int:cid>/<int:uid>')
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit("100/minute;300/hour;2000/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("100/minute;300/hour;2000/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2024-01-31 21:14:20 +00:00
|
|
|
@auth_required
|
2022-05-04 23:09:46 +00:00
|
|
|
def remove_report_comment(v, cid, uid):
|
2023-06-23 16:49:23 +00:00
|
|
|
report = g.db.query(CommentReport).filter_by(comment_id=cid, user_id=uid).one_or_none()
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-06-07 10:32:48 +00:00
|
|
|
if report:
|
2024-01-31 21:14:20 +00:00
|
|
|
if v.id != report.user_id and v.admin_level < PERMS['REPORTS_REMOVE']:
|
|
|
|
abort(403, "You can't remove this report!")
|
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.delete(report)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-01-31 21:56:15 +00:00
|
|
|
if v.id != report.user_id:
|
2024-01-31 21:56:32 +00:00
|
|
|
ma = ModAction(
|
2024-01-31 21:56:15 +00:00
|
|
|
kind="delete_report",
|
|
|
|
user_id=v.id,
|
|
|
|
target_comment_id=cid
|
|
|
|
)
|
2024-01-31 22:15:21 +00:00
|
|
|
g.db.add(ma)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-11-03 00:24:00 +00:00
|
|
|
return {"message": "Report removed successfully!"}
|