diff --git a/files/routes/reporting.py b/files/routes/reporting.py
index 797fd8ad4..6518ccbb7 100644
--- a/files/routes/reporting.py
+++ b/files/routes/reporting.py
@@ -14,9 +14,8 @@ from files.helpers.sanitize import filter_emojis_only
def flag_post(pid, v):
post = get_post(pid)
reason = request.values.get("reason", "").strip()
-
execute_blackjack(v, post, reason, 'flag')
- if v.is_muted: abort(400, "You are forbidden from making reports.")
+ if v.is_muted: abort(403, "You are forbidden from making reports.")
reason = reason[:100]
reason = filter_emojis_only(reason)
if len(reason) > 350: abort(400, "Too long.")
@@ -41,63 +40,15 @@ def flag_post(pid, v):
_note=f'"{post.flair}"'
)
g.db.add(ma)
+ return {"message": "Post flaired successfully!"}
- elif reason.startswith('/h/') and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == post.author_id or (reason == '/h/chudrama' and v.mods(post.sub))):
-
- sub_from = post.sub
- sub_to = reason[3:].strip().lower()
- sub_to = g.db.get(Sub, sub_to)
- sub_to = sub_to.name if sub_to else None
-
- if sub_from == sub_to: abort(400, f"Post is already in /h/{sub_to}")
-
- if post.author.exiled_from(sub_to):
- abort(400, 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'/h/{sub_from}'
- sub_to_str = 'main feed' 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)
- else:
- ma = SubAction(
- sub=sub_from,
- kind='move_chudrama',
- user_id=v.id,
- target_submission_id=post.id
- )
- g.db.add(ma)
-
- if v.id != post.author_id:
- 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 {"message": f"Post moved to /h/{post.sub}"}
- else:
- 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)
-
+ 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)
return {"message": "Post reported!"}
@@ -134,7 +85,7 @@ def remove_report_post(v, pid, uid):
try:
pid = int(pid)
uid = int(uid)
- except: abort(400)
+ except: abort(404)
report = g.db.query(Flag).filter_by(post_id=pid, user_id=uid).one_or_none()
if report:
@@ -147,8 +98,6 @@ def remove_report_post(v, pid, uid):
)
g.db.add(ma)
-
-
return {"message": "Report removed successfully!"}
@@ -159,7 +108,7 @@ def remove_report_comment(v, cid, uid):
try:
cid = int(cid)
uid = int(uid)
- except: abort(400)
+ except: abort(404)
report = g.db.query(CommentFlag).filter_by(comment_id=cid, user_id=uid).one_or_none()
if report:
@@ -172,6 +121,56 @@ def remove_report_comment(v, cid, uid):
)
g.db.add(ma)
-
-
return {"message": "Report removed successfully!"}
+
+def move_post(post:Submission, v:User, reason:str) -> Union[bool, str]:
+ if not reason.startswith('/h/'): return False
+ sub_from = post.sub
+ sub_to = get_sub_by_name(reason[:3].strip().lower())
+ 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'/h/{sub_from}'
+ sub_to_str = 'main feed' 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)
+ else:
+ ma = SubAction(
+ sub=sub_from,
+ kind='move_chudrama',
+ user_id=v.id,
+ target_submission_id=post.id
+ )
+ g.db.add(ma)
+
+ 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}"