feat: dup report
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user