2022-04-03 03:32:22 +00:00
|
|
|
from flask import render_template, Blueprint, redirect, url_for, request, flash, redirect
|
2022-01-16 18:22:00 +00:00
|
|
|
from flask_user import login_required, current_user
|
|
|
|
from app.models import db, BugReport, CharacterInfo
|
|
|
|
from datatables import ColumnDT, DataTables
|
|
|
|
from app.forms import ResolveBugReportForm
|
|
|
|
from app import gm_level
|
|
|
|
from app.luclient import translate_from_locale
|
|
|
|
|
|
|
|
bug_report_blueprint = Blueprint('bug_reports', __name__)
|
|
|
|
|
2022-03-13 02:09:35 +00:00
|
|
|
|
2022-01-16 18:22:00 +00:00
|
|
|
@bug_report_blueprint.route('/<status>', methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def index(status):
|
|
|
|
return render_template('bug_reports/index.html.j2', status=status)
|
|
|
|
|
|
|
|
|
|
|
|
@bug_report_blueprint.route('/view/<id>', methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def view(id):
|
|
|
|
report = BugReport.query.filter(BugReport.id == id).first()
|
2022-04-03 03:32:22 +00:00
|
|
|
if current_user.gm_level < 3:
|
|
|
|
chars = CharacterInfo.query.with_entities(CharacterInfo.id).filter(CharacterInfo.account_id == current_user.id).all()
|
|
|
|
char_ids = []
|
|
|
|
for char in chars:
|
|
|
|
char_ids.append(char[0])
|
|
|
|
if report.reporter_id not in char_ids:
|
|
|
|
return redirect(url_for('bug_reports.index', status=all))
|
2022-01-16 18:22:00 +00:00
|
|
|
if report.resoleved_by:
|
|
|
|
rb = report.resoleved_by.username
|
|
|
|
else:
|
2022-03-13 02:09:35 +00:00
|
|
|
rb = ""
|
2022-01-16 18:22:00 +00:00
|
|
|
return render_template('bug_reports/view.html.j2', report=report, resolved_by=rb)
|
|
|
|
|
|
|
|
|
|
|
|
@bug_report_blueprint.route('/resolve/<id>', methods=['GET', 'POST'])
|
|
|
|
@login_required
|
|
|
|
@gm_level(3)
|
|
|
|
def resolve(id):
|
|
|
|
report = BugReport.query.filter(BugReport.id == id).first()
|
|
|
|
if report.resolved_time:
|
|
|
|
flash("Bug report already resolved!", "danger")
|
|
|
|
return redirect(request.referrer if request.referrer else url_for("main.index"))
|
|
|
|
|
|
|
|
form = ResolveBugReportForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
report.resolution = form.resolution.data
|
|
|
|
report.resoleved_by_id = current_user.id
|
|
|
|
report.resolved_time = db.func.now()
|
|
|
|
report.save()
|
|
|
|
return redirect(url_for("bug_reports.index", status="unresolved"))
|
|
|
|
|
|
|
|
return render_template('bug_reports/resolve.html.j2', form=form, report=report)
|
|
|
|
|
|
|
|
|
|
|
|
@bug_report_blueprint.route('/get/<status>', methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def get(status):
|
|
|
|
columns = [
|
|
|
|
ColumnDT(BugReport.id), # 0
|
2022-04-02 23:17:16 +00:00
|
|
|
ColumnDT(BugReport.reporter_id), # 1
|
|
|
|
ColumnDT(BugReport.body), # 2
|
|
|
|
ColumnDT(BugReport.client_version), # 3
|
|
|
|
ColumnDT(BugReport.other_player_id), # 4
|
|
|
|
ColumnDT(BugReport.selection), # 5
|
|
|
|
ColumnDT(BugReport.submitted), # 6
|
|
|
|
ColumnDT(BugReport.resolved_time), # 7
|
2022-01-16 18:22:00 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
query = None
|
2022-04-03 03:32:22 +00:00
|
|
|
if current_user.gm_level > 0:
|
2022-04-03 17:00:14 +00:00
|
|
|
if status == "resolved":
|
2022-04-03 03:32:22 +00:00
|
|
|
query = db.session.query().select_from(BugReport).filter(BugReport.resolved_time != None)
|
|
|
|
elif status == "unresolved":
|
|
|
|
query = db.session.query().select_from(BugReport).filter(BugReport.resolved_time == None)
|
|
|
|
else:
|
2022-04-03 17:00:14 +00:00
|
|
|
query = db.session.query().select_from(BugReport)
|
2022-01-16 18:22:00 +00:00
|
|
|
else:
|
2022-04-03 03:32:22 +00:00
|
|
|
chars = CharacterInfo.query.with_entities(CharacterInfo.id).filter(CharacterInfo.account_id == current_user.id).all()
|
|
|
|
char_ids = []
|
|
|
|
for char in chars:
|
|
|
|
char_ids.append(char[0])
|
2022-04-03 17:00:14 +00:00
|
|
|
if status == "resolved":
|
2022-04-03 03:32:22 +00:00
|
|
|
query = db.session.query().select_from(BugReport).filter(BugReport.reporter_id.in_(char_ids)).filter(BugReport.resolved_time != None)
|
|
|
|
elif status == "unresolved":
|
|
|
|
query = db.session.query().select_from(BugReport).filter(BugReport.reporter_id.in_(char_ids)).filter(BugReport.resolved_time == None)
|
|
|
|
else:
|
2022-04-03 17:00:14 +00:00
|
|
|
query = db.session.query().select_from(BugReport).filter(BugReport.reporter_id.in_(char_ids))
|
2022-01-16 18:22:00 +00:00
|
|
|
|
|
|
|
params = request.args.to_dict()
|
|
|
|
|
|
|
|
rowTable = DataTables(params, query, columns)
|
|
|
|
|
|
|
|
data = rowTable.output_result()
|
|
|
|
for report in data["data"]:
|
|
|
|
id = report["0"]
|
|
|
|
report["0"] = f"""
|
|
|
|
<a role="button" class="btn btn-primary btn btn-block"
|
|
|
|
href='{url_for('bug_reports.view', id=id)}'>
|
|
|
|
View
|
|
|
|
</a>
|
|
|
|
"""
|
|
|
|
|
2022-04-02 23:17:16 +00:00
|
|
|
if report["7"] is not None:
|
2022-01-16 18:22:00 +00:00
|
|
|
report["0"] += f"""
|
2022-04-02 23:17:16 +00:00
|
|
|
<a role="button" class="btn btn-danger btn btn-block"
|
|
|
|
href='{url_for('bug_reports.resolve', id=id)}'>
|
|
|
|
Resolve
|
|
|
|
</a>
|
|
|
|
"""
|
|
|
|
else:
|
|
|
|
report["7"] = '''<h1 class="far fa-times-circle text-danger"></h1>'''
|
2022-01-16 18:22:00 +00:00
|
|
|
|
2022-04-03 02:35:57 +00:00
|
|
|
if not report["1"]:
|
2022-04-02 23:17:16 +00:00
|
|
|
report["1"] = "None"
|
2022-01-16 18:22:00 +00:00
|
|
|
else:
|
2022-04-02 23:17:16 +00:00
|
|
|
character = CharacterInfo.query.filter(CharacterInfo.id == int(report["1"])).first()
|
2022-01-16 18:22:00 +00:00
|
|
|
if character:
|
2022-04-02 23:17:16 +00:00
|
|
|
report["1"] = f"""
|
2022-01-16 18:22:00 +00:00
|
|
|
<a role="button" class="btn btn-primary btn btn-block"
|
2022-04-02 23:17:16 +00:00
|
|
|
href='{url_for('characters.view', id=report['1'])}'>
|
2022-01-16 18:22:00 +00:00
|
|
|
{character.name}
|
|
|
|
</a>
|
|
|
|
"""
|
|
|
|
else:
|
2022-04-02 23:17:16 +00:00
|
|
|
report["1"] = "Player Deleted"
|
2022-01-16 18:22:00 +00:00
|
|
|
|
2022-04-02 23:17:16 +00:00
|
|
|
if report["4"] == "0":
|
|
|
|
report["4"] = "None"
|
|
|
|
else:
|
|
|
|
character = CharacterInfo.query.filter(CharacterInfo.id == int(report["4"]) & 0xFFFFFFFF).first()
|
|
|
|
if character:
|
2022-04-03 03:32:22 +00:00
|
|
|
if current_user.gm_level > 3:
|
|
|
|
report["4"] = f"""
|
|
|
|
<a role="button" class="btn btn-primary btn btn-block"
|
|
|
|
href='{url_for('characters.view', id=(int(report["4"]) & 0xFFFFFFFF))}'>
|
|
|
|
{character.name}
|
|
|
|
</a>
|
|
|
|
"""
|
|
|
|
else:
|
|
|
|
report["4"] = character.name
|
2022-04-02 23:17:16 +00:00
|
|
|
else:
|
|
|
|
report["4"] = "Player Deleted"
|
2022-01-16 18:22:00 +00:00
|
|
|
|
2022-04-02 23:17:16 +00:00
|
|
|
report["5"] = translate_from_locale(report["5"][2:-1])
|
2022-01-16 18:22:00 +00:00
|
|
|
|
|
|
|
return data
|