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')
|
2022-05-04 23:09:46 +00:00
|
|
|
reason = reason[:100]
|
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:
|
2022-12-28 09:50:48 +00:00
|
|
|
abort(400, "Report reason too long!")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if reason.startswith('!') and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or post.hole and v.mods(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']:
|
2022-08-20 20:14:20 +00:00
|
|
|
ma=ModAction(
|
|
|
|
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
|
|
|
|
2022-11-03 00:24:00 +00:00
|
|
|
moved = move_post(post, v, reason)
|
|
|
|
if moved: return {"message": moved}
|
2023-01-01 11:36:20 +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-10-04 19:34:00 +00:00
|
|
|
if v.id != post.author_id and not post.author.has_blocked(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')
|
2022-05-04 23:09:46 +00:00
|
|
|
reason = reason[:100]
|
2023-04-27 15:35:07 +00:00
|
|
|
reason_html = filter_emojis_only(reason)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-04-27 15:35:07 +00:00
|
|
|
if len(reason_html) > 350: abort(400, "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-10-04 19:34:00 +00:00
|
|
|
if v.id != comment.author_id and not comment.author.has_blocked(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)
|
2023-06-23 16:49:23 +00:00
|
|
|
@admin_level_required(PERMS['REPORTS_REMOVE'])
|
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:
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.delete(report)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-06-07 10:32:48 +00:00
|
|
|
ma=ModAction(
|
|
|
|
kind="delete_report",
|
|
|
|
user_id=v.id,
|
2023-06-07 23:26:32 +00:00
|
|
|
target_post_id=pid
|
2022-06-07 10:32:48 +00:00
|
|
|
)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-03-16 06:27:58 +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)
|
2023-06-23 16:49:23 +00:00
|
|
|
@admin_level_required(PERMS['REPORTS_REMOVE'])
|
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:
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.delete(report)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-06-07 10:32:48 +00:00
|
|
|
ma=ModAction(
|
|
|
|
kind="delete_report",
|
|
|
|
user_id=v.id,
|
|
|
|
target_comment_id=cid
|
|
|
|
)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-11-03 00:24:00 +00:00
|
|
|
return {"message": "Report removed successfully!"}
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def move_post(post, v, reason):
|
2023-03-13 18:51:30 +00:00
|
|
|
if not reason.startswith('/h/') and not reason.startswith('h/'):
|
|
|
|
return False
|
|
|
|
|
2023-11-04 16:16:23 +00:00
|
|
|
if post.ghost:
|
|
|
|
abort(403, "You can't move ghost posts into holes!")
|
|
|
|
|
|
|
|
if 'movie night' in post.title.lower() or 'movie night' in post.body.lower():
|
|
|
|
abort(403, "You can't move this post out of /h/countryclub")
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
hole_from = post.hole
|
|
|
|
hole_to = get_hole(reason, graceful=True)
|
|
|
|
hole_to = hole_to.name if hole_to else None
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
can_move_post = v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (post.hole and v.mods(hole_from))
|
|
|
|
if hole_from != 'chudrama': # posts can only be moved out of /h/chudrama by admins
|
2022-11-03 00:24:00 +00:00
|
|
|
can_move_post = can_move_post or post.author_id == v.id
|
|
|
|
if not can_move_post: return False
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if hole_to == None:
|
2023-08-25 02:25:09 +00:00
|
|
|
if HOLE_REQUIRED:
|
|
|
|
abort(403, "All posts are required to be flaired!")
|
2023-10-07 17:55:50 +00:00
|
|
|
hole_to_in_notif = 'the main feed'
|
2023-03-12 10:39:17 +00:00
|
|
|
else:
|
2023-10-07 17:55:50 +00:00
|
|
|
hole_to_in_notif = f'/h/{hole_to}'
|
2023-03-12 10:39:17 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if hole_from == hole_to: abort(409, f"Post is already in {hole_to_in_notif}")
|
2023-03-12 10:39:17 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if post.author.exiler_username(hole_to):
|
2023-10-07 18:04:12 +00:00
|
|
|
abort(403, f"User is exiled from this hole!")
|
2022-11-03 00:24:00 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if hole_to == 'changelog':
|
2023-04-29 16:31:51 +00:00
|
|
|
abort(403, "/h/changelog is archived!")
|
2023-02-17 23:26:38 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if hole_to in {'furry','vampire','racist','femboy','edgy'} and not v.client and not post.author.house.lower().startswith(hole_to):
|
2022-11-03 00:24:00 +00:00
|
|
|
if v.id == post.author_id:
|
2023-10-07 17:55:50 +00:00
|
|
|
abort(403, f"You need to be a member of House {hole_to.capitalize()} to post in /h/{hole_to}")
|
2022-11-03 00:24:00 +00:00
|
|
|
else:
|
2023-10-07 17:55:50 +00:00
|
|
|
abort(403, f"@{post.author_name} needs to be a member of House {hole_to.capitalize()} for their post to be moved to /h/{hole_to}")
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
post.hole = hole_to
|
2022-11-18 19:58:12 +00:00
|
|
|
post.hole_pinned = None
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(post)
|
2022-11-03 00:24:00 +00:00
|
|
|
|
|
|
|
if v.id != post.author_id:
|
2023-10-07 17:55:50 +00:00
|
|
|
hole_from_str = 'main feed' if hole_from is None else \
|
|
|
|
f'<a href="/h/{hole_from}">/h/{hole_from}</a>'
|
|
|
|
hole_to_str = 'main feed' if hole_to is None else \
|
|
|
|
f'<a href="/h/{hole_to}">/h/{hole_to}</a>'
|
2023-03-18 06:06:54 +00:00
|
|
|
|
2023-08-31 10:31:04 +00:00
|
|
|
if v.admin_level >= PERMS['POST_COMMENT_MODERATION']:
|
2022-11-03 00:24:00 +00:00
|
|
|
ma = ModAction(
|
|
|
|
kind='move_hole',
|
|
|
|
user_id=v.id,
|
2023-06-07 23:26:32 +00:00
|
|
|
target_post_id=post.id,
|
2023-10-07 17:55:50 +00:00
|
|
|
_note=f'{hole_from_str} → {hole_to_str}',
|
2022-11-03 00:24:00 +00:00
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-11-03 00:24:00 +00:00
|
|
|
else:
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole_from,
|
2023-03-18 06:06:54 +00:00
|
|
|
kind='move_hole',
|
2022-11-03 00:24:00 +00:00
|
|
|
user_id=v.id,
|
2023-06-07 23:26:32 +00:00
|
|
|
target_post_id=post.id,
|
2023-10-07 17:55:50 +00:00
|
|
|
_note=f'{hole_from_str} → {hole_to_str}',
|
2022-11-03 00:24:00 +00:00
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-12-13 17:11:26 +00:00
|
|
|
if v.admin_level >= PERMS['POST_COMMENT_MODERATION']: position = 'a site admin'
|
2023-10-07 17:55:50 +00:00
|
|
|
else: position = f'a /h/{hole_from} mod'
|
2022-12-13 17:11:26 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if hole_from == None:
|
|
|
|
hole_from_in_notif = 'the main feed'
|
2022-12-13 17:11:26 +00:00
|
|
|
else:
|
2023-10-07 17:55:50 +00:00
|
|
|
hole_from_in_notif = f'/h/{hole_from}'
|
2022-12-13 17:11:26 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
message = f"@{v.username} ({position}) has moved [{post.title}]({post.shortlink}) from {hole_from_in_notif} to {hole_to_in_notif}"
|
2022-11-03 00:24:00 +00:00
|
|
|
send_repeatable_notification(post.author_id, message)
|
2022-11-14 05:34:48 +00:00
|
|
|
|
|
|
|
cache.delete_memoized(frontlist)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return f"Post moved to {hole_to_in_notif} successfully!"
|