feat: dup report

This commit is contained in:
DengDai
2025-11-24 16:43:43 +08:00
parent 91a9be0868
commit 3eb0688460
2 changed files with 60 additions and 7 deletions

View File

@@ -49,6 +49,15 @@ def create_report():
active_sites = PartnerSite.query.filter_by(is_active=True).order_by(PartnerSite.name).all()
form.reported_pt_site.choices = [(site.name, site.name) for site in active_sites]
if form.validate_on_submit():
# 检查是否已有针对该邮箱的活跃举报
existing_report = Report.query.filter_by(
reported_email=form.reported_email.data,
status='pending'
).first()
if existing_report:
flash(f'该邮箱已有待审核的举报 (#{existing_report.id}),请勿重复提交。', 'warning')
return render_template('create_report.html', form=form)
# 1. 创建 Report 对象
new_report = Report(
reporter_id=current_user.id,
@@ -135,12 +144,19 @@ def report_detail(report_id):
comments = report.comments.order_by(Comment.created_at.desc()).all()
# 查找针对同一邮箱的其他举报
related_reports = Report.query.filter(
Report.reported_email == report.reported_email,
Report.id != report.id
).order_by(Report.created_at.desc()).all()
return render_template(
'admin/report_detail.html',
report=report,
form=comment_form,
revoke_form=revoke_form,
comments=comments
comments=comments,
related_reports=related_reports
)
# === 独立的举报处理视图 (仅限 Admin) ===
# 这个视图只处理动作,不渲染页面。它接收来自详情页按钮的 POST 请求。
@@ -170,9 +186,29 @@ def process_report(report_id):
username=report.reported_username or None
)
db.session.add(new_blacklist_entry)
# 自动处理同一邮箱的其他待审核举报
other_pending = Report.query.filter(
Report.reported_email == report.reported_email,
Report.id != report.id,
Report.status == 'pending'
).all()
for other_report in other_pending:
other_report.status = 'approved'
comment = Comment(
body=f'该举报已自动批准(关联举报 #{report.id} 已确认违规)',
report=other_report,
author=current_user._get_current_object()
)
db.session.add(comment)
if other_pending:
flash(f'举报已批准,并已将相关信息添加到黑名单。同时自动处理了 {len(other_pending)} 个相关举报。', 'success')
else:
flash('举报已批准,并已将相关信息添加到黑名单。', 'success')
else:
flash('举报状态已更新为“批准”。该举报已在黑名单中,无需重复添加。', 'info')
flash('举报状态已更新为"批准"。该举报已在黑名单中,无需重复添加。', 'info')
elif action == 'invalidate':
report.status = 'rejected'
flash('举报状态已更新为“无效”。', 'success')

View File

@@ -59,6 +59,23 @@
</div>
</div>
{% endif %}
{% if related_reports %}
<div class="card shadow-sm mb-4">
<div class="card-header"><h5 class="mb-0">相关举报 (同一邮箱)</h5></div>
<div class="list-group list-group-flush">
{% for r in related_reports %}
<a href="{{ url_for('main.report_detail', report_id=r.id) }}" class="list-group-item list-group-item-action">
<div class="d-flex justify-content-between">
<span><strong>#{{ r.id }}</strong> - {{ r.reason_category | translate_reason }}</span>
<span class="badge bg-secondary">{{ r.status | translate_status }}</span>
</div>
<small class="text-muted">{{ r.created_at.strftime('%Y-%m-%d') }} | 举报人: {{ r.reporter.username }}</small>
</a>
{% endfor %}
</div>
</div>
{% endif %}
</div>
<!-- 右侧评论区 -->