From bd5fd8fb210c4b50da9bf95df6acb0f2863e5edf Mon Sep 17 00:00:00 2001 From: Julian Rota Date: Sun, 3 Jul 2022 18:31:04 -0400 Subject: [PATCH] Switch over comment reporting to use the new system --- files/assets/js/filter_actions.js | 14 ++++++++++ files/routes/admin.py | 16 +++++++----- files/routes/reporting.py | 43 +++---------------------------- files/templates/comments.html | 15 ++++++----- 4 files changed, 37 insertions(+), 51 deletions(-) diff --git a/files/assets/js/filter_actions.js b/files/assets/js/filter_actions.js index bf3534400..076565a2a 100644 --- a/files/assets/js/filter_actions.js +++ b/files/assets/js/filter_actions.js @@ -50,6 +50,10 @@ function filter_new_comment_status(id, new_status) { const commentRow = document.getElementById(`comment-${id}`); if(document.location.pathname === '/admin/filtered/comments' || document.location.pathname === '/admin/reported/comments' ) { commentRow.parentElement.removeChild(commentRow); + const postRow = document.querySelector(`div.post-row-cid-${id}`); + if (postRow) { + postRow.parentElement.removeChild(postRow); + } } else { const approveLink = commentRow.querySelector('button#filter-approve') const removeLink = commentRow.querySelector('button#filter-remove') @@ -57,6 +61,16 @@ function filter_new_comment_status(id, new_status) { approveLink.parentElement.removeChild(approveLink); 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; diff --git a/files/routes/admin.py b/files/routes/admin.py index a96cc98f3..47f0a3c29 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -559,16 +559,20 @@ def reported_comments(v): is_approved=None, is_banned=False ).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] - next_exists = len(listing) > 25 - listing = listing[:25] - - listing = get_comments(listing, v=v) + comment_ids = [c.id for c in comments_just_ids] + next_exists = len(comment_ids) > 25 + comments = get_comments(comment_ids[:25], v=v) return render_template("admin/reported_comments.html", next_exists=next_exists, - listing=listing, + listing=comments, page=page, v=v, standalone=True) diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 3c0fbf8a2..1101fba56 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -42,49 +42,14 @@ def api_flag_post(pid, v): def api_flag_comment(cid, v): comment = get_comment(cid) - - 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 = request.values.get("reason", "").strip()[:100] 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) - 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() return {"message": "Comment reported!"} - -@app.post('/del_report/comment//') -@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!"} diff --git a/files/templates/comments.html b/files/templates/comments.html index 7b820b378..b9c8cad95 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -118,7 +118,7 @@ {% endif %} {% if standalone and level==1 %} -