50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
"""
|
|
routes/admin_logs.py — Activity log and app log routes.
|
|
"""
|
|
|
|
import logging
|
|
from flask import Blueprint, render_template, request, redirect, url_for, flash, session
|
|
from models import get_activity_log, get_app_log, purge_app_log, log_action
|
|
from utils.decorators import admin_required
|
|
|
|
logger = logging.getLogger("routes.admin_logs")
|
|
admin_logs_bp = Blueprint("admin_logs", __name__, url_prefix="/admin/logs")
|
|
|
|
|
|
@admin_logs_bp.route("/")
|
|
@admin_required
|
|
def logs():
|
|
tab = request.args.get("tab", "activity")
|
|
search = request.args.get("search", "").strip()
|
|
limit = int(request.args.get("limit", 200))
|
|
|
|
activity_rows = []
|
|
app_rows = []
|
|
level_filter = request.args.get("level", "")
|
|
|
|
if tab == "activity":
|
|
activity_rows = get_activity_log(limit=limit, search=search)
|
|
else:
|
|
app_rows = get_app_log(limit=limit, level_filter=level_filter, search=search)
|
|
|
|
return render_template("admin/logs.html",
|
|
tab=tab,
|
|
activity_rows=activity_rows,
|
|
app_rows=app_rows,
|
|
search=search,
|
|
level_filter=level_filter,
|
|
limit=limit)
|
|
|
|
|
|
@admin_logs_bp.route("/purge", methods=["POST"])
|
|
@admin_required
|
|
def purge():
|
|
days = int(request.form.get("days", 30))
|
|
admin = session["user"]
|
|
deleted = purge_app_log(older_than_days=days)
|
|
log_action(admin["id"], "PURGE_APP_LOG", "app_log", None,
|
|
f"Purged {deleted} app log records older than {days} days.")
|
|
flash(f"Purged {deleted} app log records older than {days} days.", "success")
|
|
logger.info(f"App log purged: {deleted} records by admin_id={admin['id']}.")
|
|
return redirect(url_for("admin_logs.logs", tab="app"))
|