From 11f0a9e1838734ce47806d4926c22ad788d2e2e3 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 6 Apr 2024 14:10:23 +1300 Subject: [PATCH] Option for mods to ignore reports about a post, comment or user #21 --- app/community/routes.py | 41 ++++++++++++++++++- app/post/routes.py | 14 +++++++ .../community/community_moderate.html | 2 + app/templates/post/_post_full.html | 4 +- app/templates/post/_post_teaser.html | 4 +- app/templates/post/_post_teaser_masonry.html | 2 +- app/user/routes.py | 10 +++++ 7 files changed, 71 insertions(+), 6 deletions(-) diff --git a/app/community/routes.py b/app/community/routes.py index b28b6452..de5e842b 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -19,7 +19,8 @@ from app.community.util import search_for_community, community_url_exists, actor opengraph_parse, url_to_thumbnail_file, save_post, save_icon_file, save_banner_file, send_to_remote_instance, \ delete_post_from_community, delete_post_reply_from_community from app.constants import SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER, POST_TYPE_LINK, POST_TYPE_ARTICLE, POST_TYPE_IMAGE, \ - SUBSCRIPTION_PENDING, SUBSCRIPTION_MODERATOR, REPORT_STATE_NEW, REPORT_STATE_ESCALATED, REPORT_STATE_RESOLVED + SUBSCRIPTION_PENDING, SUBSCRIPTION_MODERATOR, REPORT_STATE_NEW, REPORT_STATE_ESCALATED, REPORT_STATE_RESOLVED, \ + REPORT_STATE_DISCARDED from app.inoculation import inoculation from app.models import User, Community, CommunityMember, CommunityJoinRequest, CommunityBan, Post, \ File, PostVote, utcnow, Report, Notification, InstanceBlock, ActivityPubLog, Topic, Conversation, PostReply @@ -1084,6 +1085,44 @@ def community_moderate_report_resolve(community_id, report_id): return render_template('community/community_moderate_report_resolve.html', form=form) +@bp.route('/community//moderate_report//ignore', methods=['GET', 'POST']) +@login_required +def community_moderate_report_ignore(community_id, report_id): + community = Community.query.get_or_404(community_id) + if community.is_moderator() or current_user.is_admin(): + report = Report.query.filter_by(in_community_id=community.id, id=report_id).first() + if report: + # Set the 'reports' counter on the comment, post or user to -1 to ignore all future reports + if report.suspect_post_reply_id: + post_reply = PostReply.query.get(report.suspect_post_reply_id) + post_reply.reports = -1 + elif report.suspect_post_id: + post = Post.query.get(report.suspect_post_id) + post.reports = -1 + elif report.suspect_user_id: + user = User.query.get(report.suspect_user_id) + user.reports = -1 + db.session.commit() + + # todo: append to mod log + + if report.suspect_post_reply_id: + db.session.execute(text('UPDATE "report" SET status = :new_status WHERE suspect_post_reply_id = :suspect_post_reply_id'), + {'new_status': REPORT_STATE_DISCARDED, + 'suspect_post_reply_id': report.suspect_post_reply_id}) + # todo: remove unread notifications about these reports + elif report.suspect_post_id: + db.session.execute(text('UPDATE "report" SET status = :new_status WHERE suspect_post_id = :suspect_post_id'), + {'new_status': REPORT_STATE_DISCARDED, + 'suspect_post_id': report.suspect_post_id}) + # todo: remove unread notifications about these reports + db.session.commit() + flash(_('Report ignored.')) + return redirect(url_for('community.community_moderate', actor=community.link())) + else: + abort(404) + + @bp.route('/lookup//') def lookup(community, domain): if domain == current_app.config['SERVER_NAME']: diff --git a/app/post/routes.py b/app/post/routes.py index b54b4457..a03fccb8 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -888,7 +888,12 @@ def post_delete(post_id: int): def post_report(post_id: int): post = Post.query.get_or_404(post_id) form = ReportPostForm() + if post.reports == -1: # When a mod decides to ignore future reports, post.reports is set to -1 + flash(_('Moderators have already assessed reports regarding this post, no further reports are necessary.'), 'warning') if form.validate_on_submit(): + if post.reports == -1: + flash(_('Post has already been reported, thank you!')) + return redirect(post.community.local_url()) report = Report(reasons=form.reasons_to_string(form.reasons.data), description=form.description.data, type=1, reporter_id=current_user.id, suspect_user_id=post.author.id, suspect_post_id=post.id, suspect_community_id=post.community.id, in_community_id=post.community.id, source_instance_id=1) @@ -992,7 +997,16 @@ def post_reply_report(post_id: int, comment_id: int): post = Post.query.get_or_404(post_id) post_reply = PostReply.query.get_or_404(comment_id) form = ReportPostForm() + + if post_reply.reports == -1: # When a mod decides to ignore future reports, post_reply.reports is set to -1 + flash(_('Moderators have already assessed reports regarding this comment, no further reports are necessary.'), 'warning') + if form.validate_on_submit(): + + if post_reply.reports == -1: + flash(_('Comment has already been reported, thank you!')) + return redirect(post.community.local_url()) + report = Report(reasons=form.reasons_to_string(form.reasons.data), description=form.description.data, type=2, reporter_id=current_user.id, suspect_post_id=post.id, suspect_community_id=post.community.id, suspect_user_id=post_reply.author.id, suspect_post_reply_id=post_reply.id, in_community_id=post.community.id, diff --git a/app/templates/community/community_moderate.html b/app/templates/community/community_moderate.html index 0e2db665..6c1805b0 100644 --- a/app/templates/community/community_moderate.html +++ b/app/templates/community/community_moderate.html @@ -66,6 +66,8 @@
  • {{ _('Escalate') }}
  • {{ _('Resolve') }}
  • + +
  • {{ _('Ignore') }}
  • diff --git a/app/templates/post/_post_full.html b/app/templates/post/_post_full.html index a24cb457..ebbdb807 100644 --- a/app/templates/post/_post_full.html +++ b/app/templates/post/_post_full.html @@ -24,7 +24,7 @@

    {{ post.url|shorten_url }}

    {% endif %} -

    {% if post.reports and current_user.is_authenticated and post.community.is_moderator(current_user) %} +

    {% if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator(current_user) %} {% endif %}submitted {{ moment(post.posted_at).fromNow() }} by {{ render_username(post.author) }} {% if post.edited_at %} edited {{ moment(post.edited_at).fromNow() }}{% endif %} @@ -72,7 +72,7 @@ width="{{ post.image.thumbnail_width }}" height="{{ post.image.thumbnail_height }}" loading="lazy" /> {% endif %} -

    {% if post.reports and current_user.is_authenticated and post.community.is_moderator(current_user) %} +

    {% if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator(current_user) %} {% endif %}submitted {{ moment(post.posted_at).fromNow() }} by {{ render_username(post.author) }} diff --git a/app/templates/post/_post_teaser.html b/app/templates/post/_post_teaser.html index 7f3ddd37..cfaf9c98 100644 --- a/app/templates/post/_post_teaser.html +++ b/app/templates/post/_post_teaser.html @@ -2,7 +2,7 @@ {% if content_blocked and content_blocked == '-1' %} {# do nothing - blocked by keyword filter #} {% else %} -