rDrama/drama/routes/flagging.py

50 lines
1.0 KiB
Python
Raw Normal View History

2021-07-22 19:19:49 +00:00
from drama.helpers.wrappers import *
from drama.helpers.get import *
2021-07-21 01:12:26 +00:00
from flask import g
2021-07-22 19:19:49 +00:00
from drama.__main__ import app
2021-08-02 14:39:59 +00:00
from drama.helpers.sanitize import sanitize
2021-07-21 01:12:26 +00:00
2021-07-31 04:48:47 +00:00
@app.post("/flag/post/<pid>")
2021-07-21 01:12:26 +00:00
@auth_desired
def api_flag_post(pid, v):
post = get_post(pid)
if v:
existing = g.db.query(Flag).filter_by(
2021-08-01 04:25:26 +00:00
user_id=v.id, post_id=post.id).first()
2021-07-21 01:12:26 +00:00
2021-08-02 14:39:59 +00:00
if existing: return "", 409
reason = sanitize(request.form.get("reason", "")[:100].strip(), flair=True)
2021-07-21 01:12:26 +00:00
flag = Flag(post_id=post.id,
user_id=v.id,
2021-07-24 18:15:26 +00:00
reason=reason,
2021-07-21 01:12:26 +00:00
)
g.db.add(flag)
return "", 204
2021-07-31 04:48:47 +00:00
@app.post("/flag/comment/<cid>")
2021-07-21 01:12:26 +00:00
@auth_desired
def api_flag_comment(cid, v):
comment = get_comment(cid)
if v:
existing = g.db.query(CommentFlag).filter_by(
2021-08-01 04:25:26 +00:00
user_id=v.id, comment_id=comment.id).first()
2021-07-21 01:12:26 +00:00
2021-08-02 14:39:59 +00:00
if existing: return "", 409
reason = sanitize(request.form.get("reason", "")[:100].strip(), flair=True)
2021-07-21 01:12:26 +00:00
flag = CommentFlag(comment_id=comment.id,
user_id=v.id,
2021-07-24 18:15:26 +00:00
reason=reason,
2021-07-21 01:12:26 +00:00
)
g.db.add(flag)
return "", 204