From 3eb06884604ac0d14a7bcc0095b7d2c944a1ea14 Mon Sep 17 00:00:00 2001 From: DengDai <29502593+zzhhxx@users.noreply.github.com> Date: Mon, 24 Nov 2025 16:43:43 +0800 Subject: [PATCH] feat: dup report --- app/routes.py | 50 ++++++++++++++++++++++---- app/templates/admin/report_detail.html | 17 +++++++++ 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/app/routes.py b/app/routes.py index efb080f..4b7a1fa 100644 --- a/app/routes.py +++ b/app/routes.py @@ -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, @@ -134,13 +143,20 @@ def report_detail(report_id): return redirect(url_for('main.report_detail', report_id=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, + '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) - flash('举报已批准,并已将相关信息添加到黑名单。', 'success') + + # 自动处理同一邮箱的其他待审核举报 + 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') diff --git a/app/templates/admin/report_detail.html b/app/templates/admin/report_detail.html index bf35437..7f1eef4 100644 --- a/app/templates/admin/report_detail.html +++ b/app/templates/admin/report_detail.html @@ -59,6 +59,23 @@ {% endif %} + + {% if related_reports %} +
+
相关举报 (同一邮箱)
+
+ {% for r in related_reports %} + +
+ #{{ r.id }} - {{ r.reason_category | translate_reason }} + {{ r.status | translate_status }} +
+ {{ r.created_at.strftime('%Y-%m-%d') }} | 举报人: {{ r.reporter.username }} +
+ {% endfor %} +
+
+ {% endif %}