From aed298118fecee8ed8c342982cba0752e1f5bd55 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Tue, 26 Mar 2024 22:18:05 +1300 Subject: [PATCH] filter reports by local or remote #21 --- app/chat/routes.py | 2 +- app/community/routes.py | 12 +++---- app/constants.py | 8 ++++- app/models.py | 5 +-- app/post/routes.py | 5 +-- .../community/community_moderate.html | 2 -- app/templates/post/add_reply.html | 11 ++++-- app/templates/post/continue_discussion.html | 11 ++++-- app/templates/post/post.html | 11 ++++-- app/templates/post/post_reply_edit.html | 11 ++++-- app/user/routes.py | 2 +- .../versions/04697ae91fac_report_source.py | 34 +++++++++++++++++++ 12 files changed, 91 insertions(+), 23 deletions(-) create mode 100644 migrations/versions/04697ae91fac_report_source.py diff --git a/app/chat/routes.py b/app/chat/routes.py index f859c236..f5185b7a 100644 --- a/app/chat/routes.py +++ b/app/chat/routes.py @@ -145,7 +145,7 @@ def chat_report(conversation_id): if form.validate_on_submit(): report = Report(reasons=form.reasons_to_string(form.reasons.data), description=form.description.data, - type=4, reporter_id=current_user.id, suspect_conversation_id=conversation_id) + type=4, reporter_id=current_user.id, suspect_conversation_id=conversation_id, source_instance_id=1) db.session.add(report) # Notify site admin diff --git a/app/community/routes.py b/app/community/routes.py index ff04d57a..5ebc165a 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -578,7 +578,7 @@ def community_report(community_id: int): form = ReportCommunityForm() if form.validate_on_submit(): report = Report(reasons=form.reasons_to_string(form.reasons.data), description=form.description.data, - type=1, reporter_id=current_user.id, suspect_community_id=community.id) + type=1, reporter_id=current_user.id, suspect_community_id=community.id, source_instance_id=1) db.session.add(report) # Notify admin @@ -924,13 +924,13 @@ def community_moderate(actor): reports = Report.query.filter_by(status=0, in_community_id=community.id) if local_remote == 'local': - reports = reports.filter_by(ap_id=None) + reports = reports.filter(Report.source_instance_id == 1) if local_remote == 'remote': - reports = reports.filter(Report.ap_id != None) - reports = reports.order_by(desc(Report.created_at)).paginate(page=page, per_page=1000, error_out=False) + reports = reports.filter(Report.source_instance_id != 1) + reports = reports.filter(Report.status >= 0).order_by(desc(Report.created_at)).paginate(page=page, per_page=1000, error_out=False) - next_url = url_for('admin.admin_reports', page=reports.next_num) if reports.has_next else None - prev_url = url_for('admin.admin_reports', page=reports.prev_num) if reports.has_prev and page != 1 else None + next_url = url_for('community.community_moderate', page=reports.next_num) if reports.has_next else None + prev_url = url_for('community.community_moderate', page=reports.prev_num) if reports.has_prev and page != 1 else None return render_template('community/community_moderate.html', title=_('Moderation of %(community)s', community=community.display_name()), community=community, reports=reports, current='reports', diff --git a/app/constants.py b/app/constants.py index 97001e31..a6e64f05 100644 --- a/app/constants.py +++ b/app/constants.py @@ -16,4 +16,10 @@ SUBSCRIPTION_NONMEMBER = 0 SUBSCRIPTION_PENDING = -1 SUBSCRIPTION_BANNED = -2 -THREAD_CUTOFF_DEPTH = 4 \ No newline at end of file +THREAD_CUTOFF_DEPTH = 4 + +REPORT_STATE_NEW = 0 +REPORT_STATE_ESCALATED = 1 +REPORT_STATE_APPEALED = 2 +REPORT_STATE_RESOLVED = 3 +REPORT_STATE_DISCARDED = -1 diff --git a/app/models.py b/app/models.py index f7c5df44..3ccb3022 100644 --- a/app/models.py +++ b/app/models.py @@ -1193,7 +1193,7 @@ class Report(db.Model): id = db.Column(db.Integer, primary_key=True) reasons = db.Column(db.String(256)) description = db.Column(db.String(256)) - status = db.Column(db.Integer, default=0) + status = db.Column(db.Integer, default=0) # 0 = new, 1 = escalated to admin, 2 = being appealed, 3 = resolved, 4 = discarded type = db.Column(db.Integer, default=0) # 0 = user, 1 = post, 2 = reply, 3 = community, 4 = conversation reporter_id = db.Column(db.Integer, db.ForeignKey('user.id')) suspect_community_id = db.Column(db.Integer, db.ForeignKey('community.id')) @@ -1202,6 +1202,7 @@ class Report(db.Model): suspect_post_reply_id = db.Column(db.Integer, db.ForeignKey('post_reply.id')) suspect_conversation_id = db.Column(db.Integer, db.ForeignKey('conversation.id')) in_community_id = db.Column(db.Integer, db.ForeignKey('community.id')) + source_instance_id = db.Column(db.Integer, db.ForeignKey('instance.id')) # the instance of the reporter. mostly used to distinguish between local (instance 1) and remote reports created_at = db.Column(db.DateTime, default=utcnow) updated = db.Column(db.DateTime, default=utcnow) @@ -1214,7 +1215,7 @@ class Report(db.Model): return types[self.type] def is_local(self): - return True + return self.source_instance == 1 class IpBan(db.Model): diff --git a/app/post/routes.py b/app/post/routes.py index 79a5e4d3..cc9becb0 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -848,7 +848,7 @@ def post_report(post_id: int): if form.validate_on_submit(): 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) + suspect_community_id=post.community.id, in_community_id=post.community.id, source_instance_id=1) db.session.add(report) # Notify moderators @@ -952,7 +952,8 @@ def post_reply_report(post_id: int, comment_id: int): if form.validate_on_submit(): 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) + suspect_user_id=post_reply.author.id, suspect_post_reply_id=post_reply.id, in_community_id=post.community.id, + source_instance_id=1) db.session.add(report) # Notify moderators diff --git a/app/templates/community/community_moderate.html b/app/templates/community/community_moderate.html index 38bcf75c..df481696 100644 --- a/app/templates/community/community_moderate.html +++ b/app/templates/community/community_moderate.html @@ -57,8 +57,6 @@ View {% elif report.suspect_user_id %} View - {% elif report.suspect_community_id %} - View {% endif %} diff --git a/app/templates/post/add_reply.html b/app/templates/post/add_reply.html index 7a7e9d7e..75120dcd 100644 --- a/app/templates/post/add_reply.html +++ b/app/templates/post/add_reply.html @@ -82,8 +82,15 @@

{{ _('Community Settings') }}

-

{{ _('Moderate') }}

-

{{ _('Settings') }}

+ {% if is_moderator or is_owner or is_admin %} +

{{ _('Moderate') }}

+ {% endif %} + {% if is_owner or is_admin %} +

{{ _('Settings') }}

+ {% endif %} + {% if community.is_local() and (community.is_owner() or current_user.is_admin()) %} +

Delete community

+ {% endif %}
{% endif %} diff --git a/app/templates/post/continue_discussion.html b/app/templates/post/continue_discussion.html index d0e19b7e..46f0c787 100644 --- a/app/templates/post/continue_discussion.html +++ b/app/templates/post/continue_discussion.html @@ -133,8 +133,15 @@

{{ _('Community Settings') }}

-

{{ _('Moderate') }}

-

{{ _('Settings') }}

+ {% if is_moderator or is_owner or is_admin %} +

{{ _('Moderate') }}

+ {% endif %} + {% if is_owner or is_admin %} +

{{ _('Settings') }}

+ {% endif %} + {% if community.is_local() and (community.is_owner() or current_user.is_admin()) %} +

Delete community

+ {% endif %}
{% endif %} diff --git a/app/templates/post/post.html b/app/templates/post/post.html index 3aed36a8..7d7f7c6a 100644 --- a/app/templates/post/post.html +++ b/app/templates/post/post.html @@ -227,8 +227,15 @@

{{ _('Community Settings') }}

-

{{ _('Moderate') }}

-

{{ _('Settings') }}

+ {% if is_moderator or is_owner or is_admin %} +

{{ _('Moderate') }}

+ {% endif %} + {% if is_owner or is_admin %} +

{{ _('Settings') }}

+ {% endif %} + {% if community.is_local() and (community.is_owner() or current_user.is_admin()) %} +

Delete community

+ {% endif %}
{% endif %} diff --git a/app/templates/post/post_reply_edit.html b/app/templates/post/post_reply_edit.html index 74a2af66..5c3c2339 100644 --- a/app/templates/post/post_reply_edit.html +++ b/app/templates/post/post_reply_edit.html @@ -78,8 +78,15 @@

{{ _('Community Settings') }}

-

{{ _('Moderate') }}

-

{{ _('Settings') }}

+ {% if is_moderator or is_owner or is_admin %} +

{{ _('Moderate') }}

+ {% endif %} + {% if is_owner or is_admin %} +

{{ _('Settings') }}

+ {% endif %} + {% if community.is_local() and (community.is_owner() or current_user.is_admin()) %} +

Delete community

+ {% endif %}
{% endif %} diff --git a/app/user/routes.py b/app/user/routes.py index bb17fd9d..baa391a6 100644 --- a/app/user/routes.py +++ b/app/user/routes.py @@ -338,7 +338,7 @@ def report_profile(actor): if user and not user.banned: if form.validate_on_submit(): report = Report(reasons=form.reasons_to_string(form.reasons.data), description=form.description.data, - type=0, reporter_id=current_user.id, suspect_user_id=user.id) + type=0, reporter_id=current_user.id, suspect_user_id=user.id, source_instance_id=1) db.session.add(report) # Notify site admin diff --git a/migrations/versions/04697ae91fac_report_source.py b/migrations/versions/04697ae91fac_report_source.py new file mode 100644 index 00000000..7dffd32d --- /dev/null +++ b/migrations/versions/04697ae91fac_report_source.py @@ -0,0 +1,34 @@ +"""report source + +Revision ID: 04697ae91fac +Revises: 2b028a70bd7a +Create Date: 2024-03-26 22:13:16.749010 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '04697ae91fac' +down_revision = '2b028a70bd7a' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('report', schema=None) as batch_op: + batch_op.add_column(sa.Column('source_instance_id', sa.Integer(), nullable=True)) + batch_op.create_foreign_key('fk_report_source_instance_id', 'instance', ['source_instance_id'], ['id']) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('report', schema=None) as batch_op: + batch_op.drop_constraint('fk_report_source_instance_id', type_='foreignkey') + batch_op.drop_column('source_instance_id') + + # ### end Alembic commands ###