rDrama/files/routes/reporting.py

231 lines
7.0 KiB
Python
Raw Normal View History

2022-05-04 23:09:46 +00:00
from flask import g
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.classes.flags import Flag, CommentFlag
from files.classes.mod_logs import ModAction
from files.classes.sub_logs import SubAction
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
from files.routes.front import frontlist
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
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
@app.post("/report/post/<int:pid>")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit(DEFAULT_RATELIMIT)
2023-02-26 01:42:39 +00:00
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
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-11-30 17:37:35 +00:00
execute_under_siege(v, post, reason, 'flag')
2022-10-21 00:28:05 +00:00
execute_blackjack(v, post, reason, 'flag')
if v.is_muted: abort(403, "You are forbidden from making reports!")
2022-05-04 23:09:46 +00:00
reason = reason[:100]
2022-12-13 16:54:11 +00:00
og_flair = reason[1:]
2022-05-04 23:09:46 +00:00
reason = filter_emojis_only(reason)
2022-12-28 09:50:48 +00:00
if len(reason) > 350:
abort(400, "Report reason 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:]
2023-03-16 06:27:58 +00:00
g.db.add(post)
if v.admin_level >= PERMS['POST_COMMENT_MODERATION']:
ma=ModAction(
kind="flair_post",
user_id=v.id,
target_submission_id=post.id,
_note=f'"{post.flair}"'
)
2023-03-16 06:27:58 +00:00
g.db.add(ma)
position = 'a site admin'
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
)
2023-03-16 06:27:58 +00:00
g.db.add(ma)
position = f'a /h/{post.sub} 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)
return {"message": "Post flaired successfully!"}
2022-09-29 09:39:37 +00:00
moved = move_post(post, v, reason)
if moved: return {"message": moved}
2023-01-01 11:36:20 +00:00
2023-03-16 06:27:58 +00:00
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)
2023-03-16 06:27:58 +00:00
g.db.add(flag)
2022-05-04 23:09:46 +00:00
if v.id != post.author_id:
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!"}
@app.post("/report/comment/<int:cid>")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit(DEFAULT_RATELIMIT)
2023-02-26 01:42:39 +00:00
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
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)
2023-01-01 11:36:20 +00:00
2023-03-16 06:27:58 +00:00
existing = g.db.query(CommentFlag.comment_id).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
if existing: abort(409, "You already reported this comment!")
2022-05-04 23:09:46 +00:00
reason = request.values.get("reason", "").strip()
2022-11-30 17:37:35 +00:00
execute_under_siege(v, comment, reason, 'flag')
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)
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)
2023-03-16 06:27:58 +00:00
g.db.add(flag)
2022-05-04 23:09:46 +00:00
if v.id != comment.author_id:
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!"}
@app.post('/del_report/post/<int:pid>/<int:uid>')
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
2023-02-26 01:42:39 +00:00
@limiter.limit("100/minute;300/hour;2000/day")
@limiter.limit("100/minute;300/hour;2000/day", key_func=get_ID)
@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)
except: abort(404)
2023-03-16 06:27:58 +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:
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_submission_id=pid
)
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!"}
@app.post('/del_report/comment/<int:cid>/<int:uid>')
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
2023-02-26 01:42:39 +00:00
@limiter.limit("100/minute;300/hour;2000/day")
@limiter.limit("100/minute;300/hour;2000/day", key_func=get_ID)
@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)
except: abort(404)
2023-03-16 06:27:58 +00:00
report = g.db.query(CommentFlag).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)
return {"message": "Report removed successfully!"}
2022-05-04 23:09:46 +00:00
def move_post(post:Submission, v:User, reason:str) -> Union[bool, str]:
if not reason.startswith('/h/') and 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)
sub_to = sub_to.name if sub_to else None
2023-01-01 11:36:20 +00:00
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_to == None:
sub_to_in_notif = 'the main feed'
else:
sub_to_in_notif = f'/h/{sub_to}'
if sub_from == sub_to: abort(409, f"Post is already in {sub_to_in_notif}")
if post.author.exiled_from(sub_to):
abort(403, f"User is exiled from this {HOLE_NAME}!")
if sub_to == 'changelog' and not v.admin_level >= PERMS['POST_TO_CHANGELOG']:
abort(403, "You don't have sufficient permissions to post in /h/changelog")
2022-12-23 22:22:41 +00:00
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_name} needs to be a member of House {sub_to.capitalize()} for their post to be moved to /h/{sub_to}")
2023-01-01 11:36:20 +00:00
post.sub = sub_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)
if v.id != post.author_id:
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>'
if v.admin_level:
ma = ModAction(
kind='move_hole',
user_id=v.id,
target_submission_id=post.id,
_note=f'{sub_from_str} → {sub_to_str}',
)
2023-03-16 06:27:58 +00:00
g.db.add(ma)
2023-03-15 02:16:41 +00:00
if sub_to == 'chudrama':
post.bannedfor = None
else:
ma = SubAction(
sub=sub_from,
kind='move_hole',
user_id=v.id,
target_submission_id=post.id,
_note=f'{sub_from_str} → {sub_to_str}',
)
2023-03-16 06:27:58 +00:00
g.db.add(ma)
2022-05-04 23:09:46 +00:00
if v.admin_level >= PERMS['POST_COMMENT_MODERATION']: position = 'a site admin'
else: position = f'a /h/{sub_from} mod'
if sub_from == None:
sub_from_in_notif = 'the main feed'
else:
sub_from_in_notif = f'/h/{sub_from}'
message = f"@{v.username} ({position}) has moved [{post.title}]({post.shortlink}) from {sub_from_in_notif} to {sub_to_in_notif}"
send_repeatable_notification(post.author_id, message)
cache.delete_memoized(frontlist)
return f"Post moved to {sub_to_in_notif} successfully!"