Audit log view

move error logs to logs
Add links for new logs in header
This commit is contained in:
Aaron Kimbre
2022-02-12 15:30:43 -06:00
parent 24a398b89c
commit d77eaf16d1
5 changed files with 110 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
from flask import render_template, Blueprint, request, url_for
from flask_user import login_required, current_user
from app.models import CommandLog, ActivityLog, db, Account, CharacterInfo
from app.models import CommandLog, ActivityLog, db, Account, CharacterInfo, AuditLog
from datatables import ColumnDT, DataTables
import time
from app import gm_level
@@ -21,6 +21,20 @@ def command():
return render_template('logs/command.html.j2')
@log_blueprint.route('/errors')
@gm_level(8)
def error():
with open('nexus_dashboard.log', 'r') as file:
logs = '</br>'.join(file.read().split('\n')[-100:])
return render_template('logs/error.html.j2', logs=logs)
@log_blueprint.route('/audits')
@gm_level(8)
def audit():
return render_template('logs/audit.html.j2')
@log_blueprint.route('/get_activities', methods=['GET'])
@login_required
@gm_level(8)
@@ -96,3 +110,33 @@ def get_commands():
"""
return data
@log_blueprint.route('/get_audits', methods=['GET'])
@login_required
@gm_level(8)
def get_audits():
columns = [
ColumnDT(AuditLog.id), # 0
ColumnDT(AuditLog.account_id), # 1
ColumnDT(AuditLog.action), # 2
ColumnDT(AuditLog.date), # 2
]
query = db.session.query().select_from(AuditLog)
params = request.args.to_dict()
rowTable = DataTables(params, query, columns)
data = rowTable.output_result()
for audit in data["data"]:
char_id = audit["1"]
audit["1"] = f"""
<a role="button" class="btn btn-primary btn btn-block"
href='{url_for('accounts.view', id=char_id)}'>
{Account.query.filter(Account.id==audit['1']).first().username}
</a>
"""
return data