Jun 26 - Update AI Analysis History viewable for every user, removable only for Admin

This commit is contained in:
2026-06-26 13:48:47 -04:00
parent adb39a4aa8
commit fedb782b69
2 changed files with 12 additions and 13 deletions
+4 -9
View File
@@ -35,9 +35,7 @@ SUPPORTED_EXT = {".txt", ".md", ".csv", ".pdf", ".doc", ".docx", ".xlsx", ".xls"
def ai_summary(): def ai_summary():
user = session["user"] user = session["user"]
criteria = get_all_criteria() criteria = get_all_criteria()
history = get_ai_analysis_history( history = get_ai_analysis_history(user_id=None)
user_id=(None if user["role"] == "admin" else user["id"])
)
groq_key = get_setting("groq.api_key", "") groq_key = get_setting("groq.api_key", "")
groq_model = get_setting("groq.model", GROQ_MODELS[0]) groq_model = get_setting("groq.model", GROQ_MODELS[0])
return render_template("ai_summary.html", return render_template("ai_summary.html",
@@ -366,9 +364,6 @@ def analysis_detail(analysis_id):
record = get_ai_analysis_detail(analysis_id) record = get_ai_analysis_detail(analysis_id)
if not record: if not record:
return jsonify({"error": "Not found"}), 404 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
return jsonify({ return jsonify({
"id": record["id"], "id": record["id"],
"username": record.get("username"), "username": record.get("username"),
@@ -384,12 +379,12 @@ def analysis_detail(analysis_id):
@ai_summary_bp.route("/history/<int:analysis_id>/delete", methods=["POST"]) @ai_summary_bp.route("/history/<int:analysis_id>/delete", methods=["POST"])
@login_required @login_required
def delete_analysis(analysis_id): def delete_analysis(analysis_id):
user = session["user"]
if user["role"] != "admin":
return jsonify({"error": "Access denied"}), 403
record = get_ai_analysis_detail(analysis_id) record = get_ai_analysis_detail(analysis_id)
if not record: if not record:
return jsonify({"error": "Not found"}), 404 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) delete_ai_analysis(analysis_id)
log_action(user["id"], "DELETE_AI_ANALYSIS", "ai_analysis_log", analysis_id, log_action(user["id"], "DELETE_AI_ANALYSIS", "ai_analysis_log", analysis_id,
f"Deleted AI analysis id={analysis_id}.") f"Deleted AI analysis id={analysis_id}.")
+7 -3
View File
@@ -128,7 +128,7 @@
<thead> <thead>
<tr> <tr>
<th>Date</th> <th>Date</th>
{% if is_admin %}<th>User</th>{% endif %} <th>User</th>
<th>Files</th> <th>Files</th>
<th>Verdict</th> <th>Verdict</th>
</tr> </tr>
@@ -137,7 +137,7 @@
{% for h in history %} {% for h in history %}
<tr class="history-row" data-id="{{ h.id }}" style="cursor:pointer" title="Click to view result"> <tr class="history-row" data-id="{{ h.id }}" style="cursor:pointer" title="Click to view result">
<td class="nowrap text-muted">{{ h.analyzed_at.strftime('%Y-%m-%d %H:%M') if h.analyzed_at else '—' }}</td> <td class="nowrap text-muted">{{ h.analyzed_at.strftime('%Y-%m-%d %H:%M') if h.analyzed_at else '—' }}</td>
{% if is_admin %}<td class="text-muted">{{ h.username or '—' }}</td>{% endif %} <td class="text-muted">{{ h.username or '—' }}</td>
<td class="text-muted">{{ h.file_names[:50] }}{% if h.file_names|length > 50 %}…{% endif %}</td> <td class="text-muted">{{ h.file_names[:50] }}{% if h.file_names|length > 50 %}…{% endif %}</td>
<td> <td>
{% if h.verdict %} {% if h.verdict %}
@@ -148,7 +148,7 @@
</td> </td>
</tr> </tr>
{% else %} {% else %}
<tr><td colspan="{{ 5 if is_admin else 4 }}" style="padding:2.5rem 1rem;text-align:center"> <tr><td colspan="4" style="padding:2.5rem 1rem;text-align:center">
<div style="font-size:2rem;margin-bottom:.5rem">🤖</div> <div style="font-size:2rem;margin-bottom:.5rem">🤖</div>
<p class="text-muted" style="margin:0 0 .75rem">No analyses yet. Upload a document above to get started.</p> <p class="text-muted" style="margin:0 0 .75rem">No analyses yet. Upload a document above to get started.</p>
<button class="btn btn-primary btn-sm" onclick="document.getElementById('ai-files').scrollIntoView({behavior:'smooth'});document.getElementById('ai-files').focus()">Start Analyzing</button> <button class="btn btn-primary btn-sm" onclick="document.getElementById('ai-files').scrollIntoView({behavior:'smooth'});document.getElementById('ai-files').focus()">Start Analyzing</button>
@@ -256,6 +256,8 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js"></script>
<script> <script>
var IS_ADMIN = {{ 'true' if is_admin else 'false' }};
/* ─── Markdown renderer config ──────────────────────────────── */ /* ─── Markdown renderer config ──────────────────────────────── */
marked.setOptions({ breaks: true, gfm: true }); marked.setOptions({ breaks: true, gfm: true });
@@ -483,7 +485,9 @@ document.querySelectorAll('.history-row').forEach(function(row) {
document.getElementById('hist-body').innerHTML = document.getElementById('hist-body').innerHTML =
renderAI(d.summary_text || ''); renderAI(d.summary_text || '');
if (IS_ADMIN) {
document.getElementById('btn-delete-analysis').style.display = ''; document.getElementById('btn-delete-analysis').style.display = '';
}
}) })
.catch(function() { .catch(function() {
document.getElementById('hist-body').textContent = 'Failed to load analysis.'; document.getElementById('hist-body').textContent = 'Failed to load analysis.';