diff --git a/app/routes.py b/app/routes.py index ee922c0..efb080f 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,4 +1,4 @@ -from flask import Blueprint, render_template, request, flash,redirect, url_for +from flask import abort, Blueprint, render_template, request, flash,redirect, url_for from sqlalchemy import or_ from flask_login import login_required, current_user from app import db @@ -144,12 +144,17 @@ def report_detail(report_id): ) # === 独立的举报处理视图 (仅限 Admin) === # 这个视图只处理动作,不渲染页面。它接收来自详情页按钮的 POST 请求。 -@main.route('/admin/report//process/', methods=['POST']) +@main.route('/admin/report//process', methods=['POST']) @login_required -@admin_required # 严格限制为 admin -def process_report(report_id, action): +@admin_required +def process_report(report_id): report = Report.query.get_or_404(report_id) - + action = request.form.get('action') + + if action not in ['confirm', 'invalidate']: + flash('无效的操作。', 'danger') + return redirect(url_for('main.report_detail', report_id=report_id)) + if action == 'confirm': report.status = 'approved' # 检查是否已在黑名单中 @@ -276,10 +281,10 @@ def reject_user(user_id): def create_appeal(blacklist_id): blacklist_entry = Blacklist.query.get_or_404(blacklist_id) - # 安全检查:确保用户只能为自己的黑名单记录申诉 - # 注意:请根据你的 User 模型修改 current_user.reported_uid - if not (hasattr(current_user, 'reported_uid') and current_user.reported_uid == blacklist_entry.uid) and not (current_user.email == blacklist_entry.email): - abort(403) # Forbidden + # 安全检查:确保用户只能为自己的黑名单记录申诉(邮箱匹配 或 UID+站点匹配) + if not (current_user.email == blacklist_entry.email or + (current_user.uid == blacklist_entry.uid and current_user.pt_site == blacklist_entry.pt_site)): + abort(403) # 检查是否已有进行中的申诉 if blacklist_entry.appeals.filter(Appeal.status.in_(['awaiting_admin_reply', 'awaiting_user_reply'])).first(): flash('您已有一个正在进行中的申诉,请勿重复提交。', 'warning') diff --git a/app/templates/admin/report_detail.html b/app/templates/admin/report_detail.html index bd93fb0..51883ea 100644 --- a/app/templates/admin/report_detail.html +++ b/app/templates/admin/report_detail.html @@ -39,10 +39,14 @@
管理员操作
{% if report.status == 'pending' or report.status == 'in_review' %} -
+ + +
-
+ + +
{% elif report.status == 'approved' %} diff --git a/app/templates/appeal_detail.html b/app/templates/appeal_detail.html index 9cab1c0..d0c9b6a 100644 --- a/app/templates/appeal_detail.html +++ b/app/templates/appeal_detail.html @@ -21,8 +21,12 @@


针对黑名单记录
+ {% if appeal.blacklist_entry %}

站点: {{ appeal.blacklist_entry.pt_site }}

UID: {{ appeal.blacklist_entry.uid }}

+ {% else %} +

黑名单记录已删除

+ {% endif %}