From 6bdbd8117e1562e7eb5f70548854ffeb518b6b99 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 5 Dec 2021 22:22:57 +0200 Subject: [PATCH] fdsdsf --- files/classes/submission.py | 1 + files/routes/reporting.py | 33 ++++++++++++------------- files/templates/comments.html | 2 +- files/templates/report_post_modal.html | 2 +- files/templates/submission.html | 8 +++--- files/templates/submission_listing.html | 3 ++- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/files/classes/submission.py b/files/classes/submission.py index 54af7298f..8932fa57a 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -50,6 +50,7 @@ class Submission(Base): url = Column(String) body = Column(String) body_html = Column(String) + flair = Column(String) ban_reason = Column(String) embed_url = Column(String) diff --git a/files/routes/reporting.py b/files/routes/reporting.py index f0b24c48c..f38a84022 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -4,48 +4,47 @@ from flask import g from files.__main__ import app, limiter from os import path -@app.post("/flag/post/") +@app.post("/report/post/") @limiter.limit("1/second") -@auth_desired +@auth_required def api_flag_post(pid, v): post = get_post(pid) - if v and not v.shadowbanned: - existing = g.db.query(Flag.id).filter_by(user_id=v.id, post_id=post.id).first() - - if existing: return "", 409 - + if not v.shadowbanned: reason = request.values.get("reason", "").strip()[:100] if "<" in reason: return {"error": f"Reasons can't contain <"} + if not reason.startswith('!'): + existing = g.db.query(Flag.id).filter_by(user_id=v.id, post_id=post.id).first() + if existing: return "", 409 + for i in re.finditer(':(.{1,30}?):', reason): if path.isfile(f'./files/assets/images/emojis/{i.group(1)}.webp'): reason = reason.replace(f':{i.group(1)}:', f':{i.group(1)}:') if len(reason) > 350: return {"error": f"Too long."} - flag = Flag(post_id=post.id, - user_id=v.id, - reason=reason, - ) - - - g.db.add(flag) + if reason.startswith('!') and v.admin_level > 1: + post.flair = reason[1:] + g.db.add(post) + else: + flag = Flag(post_id=post.id, user_id=v.id, reason=reason) + g.db.add(flag) g.db.commit() return {"message": "Post reported!"} -@app.post("/flag/comment/") +@app.post("/report/comment/") @limiter.limit("1/second") -@auth_desired +@auth_required def api_flag_comment(cid, v): comment = get_comment(cid) - if v and not v.shadowbanned: + if not v.shadowbanned: existing = g.db.query(CommentFlag.id).filter_by( user_id=v.id, comment_id=comment.id).first() diff --git a/files/templates/comments.html b/files/templates/comments.html index 5e5964f26..a209560b6 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -749,7 +749,7 @@ {% if v %} - + {% endif %} diff --git a/files/templates/report_post_modal.html b/files/templates/report_post_modal.html index 33ed1350c..210208cc3 100644 --- a/files/templates/report_post_modal.html +++ b/files/templates/report_post_modal.html @@ -32,4 +32,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/files/templates/submission.html b/files/templates/submission.html index 42f5c565e..db2383840 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -401,12 +401,14 @@ {% endif %} {% if p.realurl(v) %}

- {% if p.club %}{{cc}}{% endif %} + {% if p.club %}{{cc}}{% endif %} + {% if p.flair %}{{p.flair}}{% endif %} {{p.realtitle(v) | safe}}

{% else %}

- {% if p.club %}{{cc}}{% endif %} + {% if p.club %}{{cc}}{% endif %} + {% if p.flair %}{{p.flair}}{% endif %} {{p.realtitle(v) | safe}}

{% endif %} @@ -902,7 +904,7 @@ {% if not p.comment_count %} {% if v %} - + {% include "award_modal.html" %} {% include "emoji_modal.html" %} {% include "gif_modal.html" %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 160119639..e9bfb1863 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -198,7 +198,8 @@
- {% if p.club %}{{cc}}{% endif %} + {% if p.club %}{{cc}}{% endif %} + {% if p.flair %}{{p.flair}}{% endif %} {{p.realtitle(v) | safe}}