2022-05-04 23:09:46 +00:00
|
|
|
from files.helpers.wrappers import *
|
|
|
|
from files.helpers.get import *
|
2022-07-04 02:19:43 +00:00
|
|
|
from files.helpers.alerts import *
|
2022-10-21 00:28:05 +00:00
|
|
|
from files.helpers.actions import *
|
2022-05-04 23:09:46 +00:00
|
|
|
from flask import g
|
|
|
|
from files.__main__ import app, limiter
|
|
|
|
from os import path
|
|
|
|
from files.helpers.sanitize import filter_emojis_only
|
|
|
|
|
|
|
|
@app.post("/report/post/<pid>")
|
|
|
|
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
2022-07-13 18:14:37 +00:00
|
|
|
@limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}')
|
2022-05-04 23:09:46 +00:00
|
|
|
@auth_required
|
2022-08-11 04:05:23 +00:00
|
|
|
def flag_post(pid, v):
|
2022-05-04 23:09:46 +00:00
|
|
|
post = get_post(pid)
|
|
|
|
reason = request.values.get("reason", "").strip()
|
2022-10-21 00:28:05 +00:00
|
|
|
execute_blackjack(v, post, reason, 'flag')
|
2022-11-03 00:24:00 +00:00
|
|
|
if v.is_muted: abort(403, "You are forbidden from making reports.")
|
2022-05-04 23:09:46 +00:00
|
|
|
reason = reason[:100]
|
|
|
|
reason = filter_emojis_only(reason)
|
2022-10-11 13:01:39 +00:00
|
|
|
if len(reason) > 350: abort(400, "Too long.")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-10-06 08:40:33 +00:00
|
|
|
if reason.startswith('!') and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or post.sub and v.mods(post.sub)):
|
2022-05-04 23:09:46 +00:00
|
|
|
post.flair = reason[1:]
|
|
|
|
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,
|
|
|
|
target_submission_id=post.id,
|
|
|
|
_note=f'"{post.flair}"'
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
else:
|
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=post.sub,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind="flair_post",
|
|
|
|
user_id=v.id,
|
2022-09-29 10:18:27 +00:00
|
|
|
target_submission_id=post.id,
|
|
|
|
_note=f'"{post.flair}"'
|
2022-09-29 09:39:37 +00:00
|
|
|
)
|
|
|
|
g.db.add(ma)
|
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}
|
|
|
|
|
|
|
|
existing = g.db.query(Flag.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none()
|
|
|
|
if existing: abort(409, "You already reported this post!")
|
|
|
|
flag = Flag(post_id=post.id, user_id=v.id, reason=reason)
|
|
|
|
g.db.add(flag)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
return {"message": "Post reported!"}
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/report/comment/<cid>")
|
|
|
|
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
2022-07-13 18:14:37 +00:00
|
|
|
@limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}')
|
2022-05-04 23:09:46 +00:00
|
|
|
@auth_required
|
2022-08-11 04:05:23 +00:00
|
|
|
def flag_comment(cid, v):
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
comment = get_comment(cid)
|
|
|
|
|
2022-08-17 20:30:07 +00:00
|
|
|
existing = g.db.query(CommentFlag.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()
|
2022-10-21 00:28:05 +00:00
|
|
|
execute_blackjack(v, comment, reason, 'flag')
|
2022-05-04 23:09:46 +00:00
|
|
|
reason = reason[:100]
|
|
|
|
reason = filter_emojis_only(reason)
|
|
|
|
|
2022-10-11 13:01:39 +00:00
|
|
|
if len(reason) > 350: abort(400, "Too long.")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason)
|
|
|
|
|
|
|
|
g.db.add(flag)
|
|
|
|
|
|
|
|
return {"message": "Comment reported!"}
|
|
|
|
|
|
|
|
|
|
|
|
@app.post('/del_report/post/<pid>/<uid>')
|
2022-07-09 00:46:44 +00:00
|
|
|
@limiter.limit("4/second;100/minute;300/hour;2000/day")
|
2022-07-07 03:45:33 +00:00
|
|
|
@admin_level_required(PERMS['FLAGS_REMOVE'])
|
2022-05-04 23:09:46 +00:00
|
|
|
def remove_report_post(v, pid, uid):
|
|
|
|
try:
|
|
|
|
pid = int(pid)
|
|
|
|
uid = int(uid)
|
2022-11-03 00:24:00 +00:00
|
|
|
except: abort(404)
|
2022-06-07 10:32:48 +00:00
|
|
|
report = g.db.query(Flag).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:
|
|
|
|
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_submission_id=pid
|
|
|
|
)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-06-07 10:32:48 +00:00
|
|
|
g.db.add(ma)
|
2022-05-04 23:09:46 +00:00
|
|
|
return {"message": "Report removed successfully!"}
|
|
|
|
|
|
|
|
|
|
|
|
@app.post('/del_report/comment/<cid>/<uid>')
|
2022-07-09 00:46:44 +00:00
|
|
|
@limiter.limit("4/second;100/minute;300/hour;2000/day")
|
2022-07-07 03:45:33 +00:00
|
|
|
@admin_level_required(PERMS['FLAGS_REMOVE'])
|
2022-05-04 23:09:46 +00:00
|
|
|
def remove_report_comment(v, cid, uid):
|
2022-10-16 09:51:42 +00:00
|
|
|
try:
|
|
|
|
cid = int(cid)
|
|
|
|
uid = int(uid)
|
2022-11-03 00:24:00 +00:00
|
|
|
except: abort(404)
|
2022-06-07 10:32:48 +00:00
|
|
|
report = g.db.query(CommentFlag).filter_by(comment_id=cid, user_id=uid).one_or_none()
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-06-07 10:32:48 +00:00
|
|
|
if report:
|
|
|
|
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
|
|
|
|
2022-06-07 10:32:48 +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
|
|
|
|
2022-11-03 00:24:00 +00:00
|
|
|
def move_post(post:Submission, v:User, reason:str) -> Union[bool, str]:
|
|
|
|
if not reason.startswith('/h/'): return False
|
|
|
|
sub_from = post.sub
|
2022-11-03 00:30:00 +00:00
|
|
|
sub_to = get_sub_by_name(reason, graceful=True)
|
2022-11-03 00:24:00 +00:00
|
|
|
sub_to = sub_to.name if sub_to else None
|
|
|
|
|
|
|
|
can_move_post = v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (post.sub and v.mods(sub_from))
|
|
|
|
if sub_from != 'chudrama': # posts can only be moved out of /h/chudrama by admins
|
|
|
|
can_move_post = can_move_post or post.author_id == v.id
|
|
|
|
if not can_move_post: return False
|
|
|
|
|
|
|
|
if sub_from == sub_to: abort(409, f"Post is already in /h/{sub_to}")
|
|
|
|
if post.author.exiled_from(sub_to):
|
|
|
|
abort(403, f"User is exiled from this {HOLE_NAME}!")
|
|
|
|
|
|
|
|
if sub_to in ('furry','vampire','racist','femboy') and not v.client and not post.author.house.lower().startswith(sub_to):
|
|
|
|
if v.id == post.author_id:
|
|
|
|
abort(403, f"You need to be a member of House {sub_to.capitalize()} to post in /h/{sub_to}")
|
|
|
|
else:
|
|
|
|
abort(403, f"@{post.author.username} needs to be a member of House {sub_to.capitalize()} for their post to be moved to /h/{sub_to}")
|
|
|
|
|
|
|
|
post.sub = sub_to
|
|
|
|
g.db.add(post)
|
|
|
|
|
|
|
|
if v.id != post.author_id:
|
|
|
|
if v.admin_level:
|
|
|
|
sub_from_str = 'main feed' if sub_from is None else \
|
|
|
|
f'<a href="/h/{sub_from}">/h/{sub_from}</a>'
|
|
|
|
sub_to_str = 'main feed' if sub_to is None else \
|
|
|
|
f'<a href="/h/{sub_to}">/h/{sub_to}</a>'
|
|
|
|
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)
|
|
|
|
else:
|
|
|
|
ma = SubAction(
|
|
|
|
sub=sub_from,
|
|
|
|
kind='move_chudrama',
|
|
|
|
user_id=v.id,
|
|
|
|
target_submission_id=post.id
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-11-03 00:24:00 +00:00
|
|
|
if v.admin_level >= PERMS['POST_COMMENT_MODERATION']: position = 'Admin'
|
|
|
|
else: position = 'Mod'
|
|
|
|
message = f"@{v.username} ({position}) has moved [{post.title}]({post.shortlink}) to /h/{post.sub}"
|
|
|
|
send_repeatable_notification(post.author_id, message)
|
|
|
|
return f"Post moved to /h/{post.sub}"
|