From 1113295c5bf0076902e57442dc45337d8e1428dc Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 2 Apr 2022 22:32:22 -0500 Subject: [PATCH] allow players to view their bug reports --- app/bug_reports.py | 54 +++++++++++++++++++++++++----------- app/templates/header.html.j2 | 9 ++++++ 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/app/bug_reports.py b/app/bug_reports.py index fe0998f..c378f0a 100644 --- a/app/bug_reports.py +++ b/app/bug_reports.py @@ -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 app.models import db, BugReport, CharacterInfo from datatables import ColumnDT, DataTables @@ -11,16 +11,21 @@ bug_report_blueprint = Blueprint('bug_reports', __name__) @bug_report_blueprint.route('/', methods=['GET']) @login_required -@gm_level(3) def index(status): return render_template('bug_reports/index.html.j2', status=status) @bug_report_blueprint.route('/view/', methods=['GET']) @login_required -@gm_level(3) def view(id): 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: rb = report.resoleved_by.username else: @@ -64,14 +69,28 @@ def get(status): ] query = None - if status == "all": - query = db.session.query().select_from(BugReport) - elif status == "resolved": - 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) + if current_user.gm_level > 0: + if status == "all": + query = db.session.query().select_from(BugReport) + elif status == "resolved": + 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: + raise Exception("Not a valid filter") else: - raise Exception("Not a valid filter") + 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() @@ -116,12 +135,15 @@ def get(status): else: character = CharacterInfo.query.filter(CharacterInfo.id == int(report["4"]) & 0xFFFFFFFF).first() if character: - report["4"] = f""" - - {character.name} - - """ + if current_user.gm_level > 3: + report["4"] = f""" + + {character.name} + + """ + else: + report["4"] = character.name else: report["4"] = "Player Deleted" diff --git a/app/templates/header.html.j2 b/app/templates/header.html.j2 index 2264f82..56622d5 100644 --- a/app/templates/header.html.j2 +++ b/app/templates/header.html.j2 @@ -73,6 +73,15 @@ {% endif %} + {% else %} + {% endif %} {% if current_user.is_authenticated and current_user.gm_level == 9 and config.REQUIRE_PLAY_KEY %}