allow players to view their bug reports

This commit is contained in:
Aaron Kimbre 2022-04-02 22:32:22 -05:00
parent e45fb3233a
commit 1113295c5b
2 changed files with 47 additions and 16 deletions

View File

@ -1,4 +1,4 @@
from flask import render_template, Blueprint, redirect, url_for, request, flash from flask import render_template, Blueprint, redirect, url_for, request, flash, redirect
from flask_user import login_required, current_user from flask_user import login_required, current_user
from app.models import db, BugReport, CharacterInfo from app.models import db, BugReport, CharacterInfo
from datatables import ColumnDT, DataTables from datatables import ColumnDT, DataTables
@ -11,16 +11,21 @@ bug_report_blueprint = Blueprint('bug_reports', __name__)
@bug_report_blueprint.route('/<status>', methods=['GET']) @bug_report_blueprint.route('/<status>', methods=['GET'])
@login_required @login_required
@gm_level(3)
def index(status): def index(status):
return render_template('bug_reports/index.html.j2', status=status) return render_template('bug_reports/index.html.j2', status=status)
@bug_report_blueprint.route('/view/<id>', methods=['GET']) @bug_report_blueprint.route('/view/<id>', methods=['GET'])
@login_required @login_required
@gm_level(3)
def view(id): def view(id):
report = BugReport.query.filter(BugReport.id == id).first() report = BugReport.query.filter(BugReport.id == id).first()
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))
if report.resoleved_by: if report.resoleved_by:
rb = report.resoleved_by.username rb = report.resoleved_by.username
else: else:
@ -64,6 +69,7 @@ def get(status):
] ]
query = None query = None
if current_user.gm_level > 0:
if status == "all": if status == "all":
query = db.session.query().select_from(BugReport) query = db.session.query().select_from(BugReport)
elif status == "resolved": elif status == "resolved":
@ -72,6 +78,19 @@ def get(status):
query = db.session.query().select_from(BugReport).filter(BugReport.resolved_time == None) query = db.session.query().select_from(BugReport).filter(BugReport.resolved_time == None)
else: else:
raise Exception("Not a valid filter") raise Exception("Not a valid filter")
else:
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 status == "all":
query = db.session.query().select_from(BugReport).filter(BugReport.reporter_id.in_(char_ids))
elif status == "resolved":
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:
raise Exception("Not a valid filter")
params = request.args.to_dict() params = request.args.to_dict()
@ -116,12 +135,15 @@ def get(status):
else: else:
character = CharacterInfo.query.filter(CharacterInfo.id == int(report["4"]) & 0xFFFFFFFF).first() character = CharacterInfo.query.filter(CharacterInfo.id == int(report["4"]) & 0xFFFFFFFF).first()
if character: if character:
if current_user.gm_level > 3:
report["4"] = f""" report["4"] = f"""
<a role="button" class="btn btn-primary btn btn-block" <a role="button" class="btn btn-primary btn btn-block"
href='{url_for('characters.view', id=(int(report["4"]) & 0xFFFFFFFF))}'> href='{url_for('characters.view', id=(int(report["4"]) & 0xFFFFFFFF))}'>
{character.name} {character.name}
</a> </a>
""" """
else:
report["4"] = character.name
else: else:
report["4"] = "Player Deleted" report["4"] = "Player Deleted"

View File

@ -73,6 +73,15 @@
{% endif %} {% endif %}
</div> </div>
</li> </li>
{% else %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Bug Reports</a>
<div class="dropdown-menu">
<a class="dropdown-item text-center" href='{{ url_for('bug_reports.index', status='unresolved') }}'>Unresolved Reports</a>
<a class="dropdown-item text-center" href='{{ url_for('bug_reports.index', status='resolved') }}'>Resolved Reports</a>
<a class="dropdown-item text-center" href='{{ url_for('bug_reports.index', status='all') }}'>All Reports</a>
</div>
</li>
{% endif %} {% endif %}
{% if current_user.is_authenticated and current_user.gm_level == 9 and config.REQUIRE_PLAY_KEY %} {% if current_user.is_authenticated and current_user.gm_level == 9 and config.REQUIRE_PLAY_KEY %}