05/24 Fix bugs
This commit is contained in:
+24
-8
@@ -13,7 +13,7 @@ from flask import (Blueprint, render_template, request, redirect, url_for,
|
||||
from models import (
|
||||
get_all_criteria, get_active_criteria, create_criterion, update_criterion,
|
||||
delete_criterion, save_ai_analysis, get_ai_analysis_history,
|
||||
get_ai_analysis_detail, log_action,
|
||||
get_ai_analysis_detail, delete_ai_analysis, log_action,
|
||||
)
|
||||
from config import get_setting
|
||||
from utils.decorators import login_required, admin_required
|
||||
@@ -370,11 +370,27 @@ def analysis_detail(analysis_id):
|
||||
if user["role"] != "admin" and record["user_id"] != user["id"]:
|
||||
return jsonify({"error": "Access denied"}), 403
|
||||
return jsonify({
|
||||
"id": record["id"],
|
||||
"username": record.get("username"),
|
||||
"file_names": record["file_names"],
|
||||
"model": record["model"],
|
||||
"verdict": record["verdict"],
|
||||
"analyzed_at": str(record["analyzed_at"]),
|
||||
"summary_text": record["summary_text"],
|
||||
"id": record["id"],
|
||||
"username": record.get("username"),
|
||||
"file_names": record["file_names"],
|
||||
"model": record["model"],
|
||||
"verdict": record["verdict"],
|
||||
"analyzed_at": str(record["analyzed_at"]),
|
||||
"summary_text": record["summary_text"],
|
||||
"criteria_snapshot": record.get("criteria_snapshot") or "",
|
||||
})
|
||||
|
||||
|
||||
@ai_summary_bp.route("/history/<int:analysis_id>/delete", methods=["POST"])
|
||||
@login_required
|
||||
def delete_analysis(analysis_id):
|
||||
record = get_ai_analysis_detail(analysis_id)
|
||||
if not record:
|
||||
return jsonify({"error": "Not found"}), 404
|
||||
user = session["user"]
|
||||
if user["role"] != "admin" and record["user_id"] != user["id"]:
|
||||
return jsonify({"error": "Access denied"}), 403
|
||||
delete_ai_analysis(analysis_id)
|
||||
log_action(user["id"], "DELETE_AI_ANALYSIS", "ai_analysis_log", analysis_id,
|
||||
f"Deleted AI analysis id={analysis_id}.")
|
||||
return jsonify({"ok": True})
|
||||
|
||||
@@ -8,6 +8,7 @@ from models import (
|
||||
authenticate, check_login_allowed, change_password, log_action,
|
||||
get_user_by_email, create_password_reset_token,
|
||||
get_password_reset_user, consume_password_reset_token,
|
||||
purge_expired_reset_tokens,
|
||||
)
|
||||
from utils.decorators import login_required
|
||||
from utils.email import send_email
|
||||
@@ -46,6 +47,10 @@ def login():
|
||||
"role": user["role"],
|
||||
"email": user.get("email", ""),
|
||||
}
|
||||
try:
|
||||
purge_expired_reset_tokens()
|
||||
except Exception:
|
||||
pass # non-critical cleanup; never fail a login because of it
|
||||
logger.info(f"User '{username}' logged in from {ip}.")
|
||||
flash(f"You have been signed in. Welcome, {session['user']['full_name']}!", "success")
|
||||
if user["role"] == "admin":
|
||||
|
||||
Reference in New Issue
Block a user