Switch over comment reporting to use the new system

This commit is contained in:
Julian Rota 2022-07-03 18:31:04 -04:00 committed by Ben Rog-Wilhelm
parent a0488f2b23
commit bd5fd8fb21
4 changed files with 37 additions and 51 deletions

View file

@ -50,6 +50,10 @@ function filter_new_comment_status(id, new_status) {
const commentRow = document.getElementById(`comment-${id}`); const commentRow = document.getElementById(`comment-${id}`);
if(document.location.pathname === '/admin/filtered/comments' || document.location.pathname === '/admin/reported/comments' ) { if(document.location.pathname === '/admin/filtered/comments' || document.location.pathname === '/admin/reported/comments' ) {
commentRow.parentElement.removeChild(commentRow); commentRow.parentElement.removeChild(commentRow);
const postRow = document.querySelector(`div.post-row-cid-${id}`);
if (postRow) {
postRow.parentElement.removeChild(postRow);
}
} else { } else {
const approveLink = commentRow.querySelector('button#filter-approve') const approveLink = commentRow.querySelector('button#filter-approve')
const removeLink = commentRow.querySelector('button#filter-remove') const removeLink = commentRow.querySelector('button#filter-remove')
@ -57,6 +61,16 @@ function filter_new_comment_status(id, new_status) {
approveLink.parentElement.removeChild(approveLink); approveLink.parentElement.removeChild(approveLink);
removeLink.parentElement.removeChild(removeLink); removeLink.parentElement.removeChild(removeLink);
} }
const reportButtonCell = document.getElementById(`flaggers-${id}`);
if(reportButtonCell) {
reportButtonCell.classList.add('d-none')
}
const reportButton = document.getElementById(`report-btn-${id}`);
if(reportButton) {
reportButton.parentElement.removeChild(reportButton);
}
} }
document.getElementById('toast-post-success-text').innerText = json.result; document.getElementById('toast-post-success-text').innerText = json.result;

View file

@ -559,16 +559,20 @@ def reported_comments(v):
is_approved=None, is_approved=None,
is_banned=False is_banned=False
).join(Comment.reports).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all() ).join(Comment.reports).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all()
comments_just_ids = g.db.query(Comment) \
.filter(Comment.filter_state == 'reported') \
.order_by(Comment.id.desc()) \
.offset(25 * (page - 1)) \
.limit(26) \
.with_entities(Comment.id)
listing = [c.id for c in listing] comment_ids = [c.id for c in comments_just_ids]
next_exists = len(listing) > 25 next_exists = len(comment_ids) > 25
listing = listing[:25] comments = get_comments(comment_ids[:25], v=v)
listing = get_comments(listing, v=v)
return render_template("admin/reported_comments.html", return render_template("admin/reported_comments.html",
next_exists=next_exists, next_exists=next_exists,
listing=listing, listing=comments,
page=page, page=page,
v=v, v=v,
standalone=True) standalone=True)

View file

@ -42,49 +42,14 @@ def api_flag_post(pid, v):
def api_flag_comment(cid, v): def api_flag_comment(cid, v):
comment = get_comment(cid) comment = get_comment(cid)
reason = request.values.get("reason", "").strip()[:100]
existing = g.db.query(CommentFlag.comment_id).filter_by( user_id=v.id, comment_id=comment.id).one_or_none()
if existing: return "", 409
reason = request.values.get("reason", "").strip()
if blackjack and any(i in reason.lower() for i in blackjack.split()):
v.shadowbanned = 'AutoJanny'
send_repeatable_notification(CARP_ID, f"reports on {comment.permalink}")
reason = reason[:100]
reason = filter_emojis_only(reason) reason = filter_emojis_only(reason)
if len(reason) > 350: return {"error": "Too long."}
flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason) flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason)
g.db.add(flag) g.db.add(flag)
g.db.query(Comment) \
.where(Comment.id == comment.id, Comment.filter_state != 'ignored') \
.update({Comment.filter_state: 'reported'})
g.db.commit() g.db.commit()
return {"message": "Comment reported!"} return {"message": "Comment reported!"}
@app.post('/del_report/comment/<cid>/<uid>')
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@admin_level_required(2)
def remove_report_comment(v, cid, uid):
cid = int(cid)
uid = int(uid)
report = g.db.query(CommentFlag).filter_by(comment_id=cid, user_id=uid).one()
g.db.delete(report)
ma=ModAction(
kind="delete_report",
user_id=v.id,
target_comment_id=cid
)
g.db.add(ma)
g.db.commit()
return {"message": "Report removed successfully!"}

View file

@ -118,7 +118,7 @@
{% endif %} {% endif %}
{% if standalone and level==1 %} {% if standalone and level==1 %}
<div class="post-info mb-1 mr-2 {% if request.path == '/notifications' %}mt-5{% else %}mt-3{% endif %}"> <div class="post-info post-row-cid-{{c.id}} mb-1 mr-2 {% if request.path == '/notifications' %}mt-5{% else %}mt-3{% endif %}">
{% if c.post and c.post.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %} {% if c.post and c.post.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %}
<span class="align-top"> <span class="align-top">
{% if c.post %} {% if c.post %}
@ -181,7 +181,7 @@
{% if c.bannedfor %} {% if c.bannedfor %}
<a role="button"><i class="fas fa-hammer-crash text-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="User was banned for this comment{% if c.author.banned_by %} by @{{c.author.banned_by.username}}{% endif %}"></i></a> <a role="button"><i class="fas fa-hammer-crash text-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="User was banned for this comment{% if c.author.banned_by %} by @{{c.author.banned_by.username}}{% endif %}"></i></a>
{% endif %} {% endif %}
{% if c.active_flags(v) %}<a class="btn btn-primary" style="padding:1px 5px; font-size:10px"role="button" onclick="document.getElementById('flaggers-{{c.id}}').classList.toggle('d-none')">{{c.active_flags(v)}} Reports</a>{% endif %} {% if v and c.filter_state == 'reported' and v.can_manage_reports() %}<a class="btn btn-primary" id="report-btn-{{c.id}}" style="padding:1px 5px; font-size:10px" role="button" onclick="document.getElementById('flaggers-{{c.id}}').classList.toggle('d-none')">{{c.active_flags(v)}} Reports</a>{% endif %}
{% if c.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %} {% if c.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %}
{% if v and v.admin_level > 1 and c.author.shadowbanned %}<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Shadowbanned by @{{c.author.shadowbanned}}"></i>{% endif %} {% if v and v.admin_level > 1 and c.author.shadowbanned %}<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Shadowbanned by @{{c.author.shadowbanned}}"></i>{% endif %}
{% if c.is_pinned %} {% if c.is_pinned %}
@ -245,13 +245,16 @@
{{c.wordle_html(v) | safe}} {{c.wordle_html(v) | safe}}
{% endif %} {% endif %}
</div> </div>
{% if c.active_flags(v) %} {% if v and c.filter_state == 'reported' and v.can_manage_reports() %}
<div id="flaggers-{{c.id}}" class="flaggers d-none"> <div id="flaggers-{{c.id}}" class="flaggers d-none">
<strong><i class="far fa-fw fa-flag"></i> Reported by:</strong> <strong><i class="far fa-fw fa-flag"></i> Reports:</strong>
<a class="btn btn-primary" style="margin:1px 5px" onclick="filter_new_comment_status({{c.id}}, 'normal')">Approve</a>
<a class="btn btn-secondary" style="margin:1px 5px" onclick="filter_new_comment_status({{c.id}}, 'ignored')">Approve and Ignore</a>
<a class="btn btn-danger" style="margin:1px 5px" onclick="filter_new_comment_status({{c.id}}, 'removed')">Remove</a>
<pre></pre> <pre></pre>
<ul style="padding-left:20px; margin-bottom: 0;word-wrap:break-word"> <ul style="padding-left:20px; margin-bottom: 0;word-wrap:break-word">
{% for f in c.flags(v) %} {% for f in c.flags(v) %}
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a role="button" onclick="post_toast(this,'/del_report/comment/{{f.comment_id}}/{{f.user_id}}')">[remove]</a>{% endif %}</li> <li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %}</li>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
@ -848,7 +851,7 @@
{% if v and v.admin_level > 1 %} {% if v and v.admin_level > 1 %}
<script src="/assets/js/comments_admin.js?v=250"></script> <script src="/assets/js/comments_admin.js?v=250"></script>
{% if v.admin_level > 2 %} {% if v.admin_level > 2 %}
<script src="/assets/js/filter_actions.js?v=2"></script> <script src="/assets/js/filter_actions.js?v=6"></script>
{% endif %} {% endif %}
{% endif %} {% endif %}