filter reports by local or remote #21

This commit is contained in:
rimu 2024-03-26 22:18:05 +13:00
parent 22731c1d38
commit aed298118f
12 changed files with 91 additions and 23 deletions

View file

@ -145,7 +145,7 @@ def chat_report(conversation_id):
if form.validate_on_submit(): if form.validate_on_submit():
report = Report(reasons=form.reasons_to_string(form.reasons.data), description=form.description.data, 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) db.session.add(report)
# Notify site admin # Notify site admin

View file

@ -578,7 +578,7 @@ def community_report(community_id: int):
form = ReportCommunityForm() form = ReportCommunityForm()
if form.validate_on_submit(): if form.validate_on_submit():
report = Report(reasons=form.reasons_to_string(form.reasons.data), description=form.description.data, 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) db.session.add(report)
# Notify admin # Notify admin
@ -924,13 +924,13 @@ def community_moderate(actor):
reports = Report.query.filter_by(status=0, in_community_id=community.id) reports = Report.query.filter_by(status=0, in_community_id=community.id)
if local_remote == 'local': if local_remote == 'local':
reports = reports.filter_by(ap_id=None) reports = reports.filter(Report.source_instance_id == 1)
if local_remote == 'remote': if local_remote == 'remote':
reports = reports.filter(Report.ap_id != None) reports = reports.filter(Report.source_instance_id != 1)
reports = reports.order_by(desc(Report.created_at)).paginate(page=page, per_page=1000, error_out=False) 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 next_url = url_for('community.community_moderate', 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 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()), return render_template('community/community_moderate.html', title=_('Moderation of %(community)s', community=community.display_name()),
community=community, reports=reports, current='reports', community=community, reports=reports, current='reports',

View file

@ -17,3 +17,9 @@ SUBSCRIPTION_PENDING = -1
SUBSCRIPTION_BANNED = -2 SUBSCRIPTION_BANNED = -2
THREAD_CUTOFF_DEPTH = 4 THREAD_CUTOFF_DEPTH = 4
REPORT_STATE_NEW = 0
REPORT_STATE_ESCALATED = 1
REPORT_STATE_APPEALED = 2
REPORT_STATE_RESOLVED = 3
REPORT_STATE_DISCARDED = -1

View file

@ -1193,7 +1193,7 @@ class Report(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
reasons = db.Column(db.String(256)) reasons = db.Column(db.String(256))
description = 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 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')) reporter_id = db.Column(db.Integer, db.ForeignKey('user.id'))
suspect_community_id = db.Column(db.Integer, db.ForeignKey('community.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_post_reply_id = db.Column(db.Integer, db.ForeignKey('post_reply.id'))
suspect_conversation_id = db.Column(db.Integer, db.ForeignKey('conversation.id')) suspect_conversation_id = db.Column(db.Integer, db.ForeignKey('conversation.id'))
in_community_id = db.Column(db.Integer, db.ForeignKey('community.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) created_at = db.Column(db.DateTime, default=utcnow)
updated = 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] return types[self.type]
def is_local(self): def is_local(self):
return True return self.source_instance == 1
class IpBan(db.Model): class IpBan(db.Model):

View file

@ -848,7 +848,7 @@ def post_report(post_id: int):
if form.validate_on_submit(): if form.validate_on_submit():
report = Report(reasons=form.reasons_to_string(form.reasons.data), description=form.description.data, 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, 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) db.session.add(report)
# Notify moderators # Notify moderators
@ -952,7 +952,8 @@ def post_reply_report(post_id: int, comment_id: int):
if form.validate_on_submit(): if form.validate_on_submit():
report = Report(reasons=form.reasons_to_string(form.reasons.data), description=form.description.data, 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, 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) db.session.add(report)
# Notify moderators # Notify moderators

View file

@ -57,8 +57,6 @@
<a href="/post/{{ report.suspect_post_id }}">View</a> <a href="/post/{{ report.suspect_post_id }}">View</a>
{% elif report.suspect_user_id %} {% elif report.suspect_user_id %}
<a href="/user/{{ report.suspect_user_id }}">View</a> <a href="/user/{{ report.suspect_user_id }}">View</a>
{% elif report.suspect_community_id %}
<a href="/user/{{ report.suspect_community_id }}">View</a>
{% endif %} {% endif %}
</td> </td>
</tr> </tr>

View file

@ -82,8 +82,15 @@
<h2>{{ _('Community Settings') }}</h2> <h2>{{ _('Community Settings') }}</h2>
</div> </div>
<div class="card-body"> <div class="card-body">
<p><a href="#" class="btn btn-primary">{{ _('Moderate') }}</a></p> {% if is_moderator or is_owner or is_admin %}
<p><a href="#" class="btn btn-primary">{{ _('Settings') }}</a></p> <p><a href="/community/{{ community.link() }}/moderate" class="btn btn-primary">{{ _('Moderate') }}</a></p>
{% endif %}
{% if is_owner or is_admin %}
<p><a href="{{ url_for('community.community_edit', community_id=community.id) }}" class="btn btn-primary">{{ _('Settings') }}</a></p>
{% endif %}
{% if community.is_local() and (community.is_owner() or current_user.is_admin()) %}
<p><a class="btn btn-primary btn-warning" href="{{ url_for('community.community_delete', community_id=community.id) }}" rel="nofollow">Delete community</a></p>
{% endif %}
</div> </div>
</div> </div>
{% endif %} {% endif %}

View file

@ -133,8 +133,15 @@
<h2>{{ _('Community Settings') }}</h2> <h2>{{ _('Community Settings') }}</h2>
</div> </div>
<div class="card-body"> <div class="card-body">
<p><a href="#" class="btn btn-primary">{{ _('Moderate') }}</a></p> {% if is_moderator or is_owner or is_admin %}
<p><a href="#" class="btn btn-primary">{{ _('Settings') }}</a></p> <p><a href="/community/{{ community.link() }}/moderate" class="btn btn-primary">{{ _('Moderate') }}</a></p>
{% endif %}
{% if is_owner or is_admin %}
<p><a href="{{ url_for('community.community_edit', community_id=community.id) }}" class="btn btn-primary">{{ _('Settings') }}</a></p>
{% endif %}
{% if community.is_local() and (community.is_owner() or current_user.is_admin()) %}
<p><a class="btn btn-primary btn-warning" href="{{ url_for('community.community_delete', community_id=community.id) }}" rel="nofollow">Delete community</a></p>
{% endif %}
</div> </div>
</div> </div>
{% endif %} {% endif %}

View file

@ -227,8 +227,15 @@
<h2>{{ _('Community Settings') }}</h2> <h2>{{ _('Community Settings') }}</h2>
</div> </div>
<div class="card-body"> <div class="card-body">
<p><a href="#" class="btn btn-primary">{{ _('Moderate') }}</a></p> {% if is_moderator or is_owner or is_admin %}
<p><a href="#" class="btn btn-primary">{{ _('Settings') }}</a></p> <p><a href="/community/{{ community.link() }}/moderate" class="btn btn-primary">{{ _('Moderate') }}</a></p>
{% endif %}
{% if is_owner or is_admin %}
<p><a href="{{ url_for('community.community_edit', community_id=community.id) }}" class="btn btn-primary">{{ _('Settings') }}</a></p>
{% endif %}
{% if community.is_local() and (community.is_owner() or current_user.is_admin()) %}
<p><a class="btn btn-primary btn-warning" href="{{ url_for('community.community_delete', community_id=community.id) }}" rel="nofollow">Delete community</a></p>
{% endif %}
</div> </div>
</div> </div>
{% endif %} {% endif %}

View file

@ -78,8 +78,15 @@
<h2>{{ _('Community Settings') }}</h2> <h2>{{ _('Community Settings') }}</h2>
</div> </div>
<div class="card-body"> <div class="card-body">
<p><a href="#" class="btn btn-primary">{{ _('Moderate') }}</a></p> {% if is_moderator or is_owner or is_admin %}
<p><a href="#" class="btn btn-primary">{{ _('Settings') }}</a></p> <p><a href="/community/{{ community.link() }}/moderate" class="btn btn-primary">{{ _('Moderate') }}</a></p>
{% endif %}
{% if is_owner or is_admin %}
<p><a href="{{ url_for('community.community_edit', community_id=community.id) }}" class="btn btn-primary">{{ _('Settings') }}</a></p>
{% endif %}
{% if community.is_local() and (community.is_owner() or current_user.is_admin()) %}
<p><a class="btn btn-primary btn-warning" href="{{ url_for('community.community_delete', community_id=community.id) }}" rel="nofollow">Delete community</a></p>
{% endif %}
</div> </div>
</div> </div>
{% endif %} {% endif %}

View file

@ -338,7 +338,7 @@ def report_profile(actor):
if user and not user.banned: if user and not user.banned:
if form.validate_on_submit(): if form.validate_on_submit():
report = Report(reasons=form.reasons_to_string(form.reasons.data), description=form.description.data, 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) db.session.add(report)
# Notify site admin # Notify site admin

View file

@ -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 ###