From 6fa7ade6a3e726cae967a6d4d8cb0a4d951d5b76 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 2 Apr 2022 18:17:16 -0500 Subject: [PATCH] add reporter id to bug reports fix moderation status filters --- app/bug_reports.py | 62 ++++++++++++------- app/characters.py | 4 +- app/models.py | 7 ++- app/properties.py | 4 +- app/templates/bug_reports/index.html.j2 | 1 + .../versions/8e52b5c7568a_reporter_id.py | 51 +++++++++++++++ 6 files changed, 100 insertions(+), 29 deletions(-) create mode 100644 migrations/versions/8e52b5c7568a_reporter_id.py diff --git a/app/bug_reports.py b/app/bug_reports.py index 7d5e2ac..d17948b 100644 --- a/app/bug_reports.py +++ b/app/bug_reports.py @@ -54,21 +54,22 @@ def resolve(id): def get(status): columns = [ ColumnDT(BugReport.id), # 0 - ColumnDT(BugReport.body), # 1 - ColumnDT(BugReport.client_version), # 2 - ColumnDT(BugReport.other_player_id), # 3 - ColumnDT(BugReport.selection), # 4 - ColumnDT(BugReport.submitted), # 5 - ColumnDT(BugReport.resolved_time), # 6 + 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 ] 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 is not None) + 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 == "") + query = db.session.query().select_from(BugReport).filter(BugReport.resolved_time == None) else: raise Exception("Not a valid filter") @@ -86,31 +87,44 @@ def get(status): """ - if not report["6"]: + if report["7"] is not None: report["0"] += f""" - - Resolve - - """ - - if report["3"] == "0": - report["3"] = "None" + + Resolve + + """ else: - character = CharacterInfo.query.filter(CharacterInfo.id == int(report["3"]) & 0xFFFFFFFF).first() + report["7"] = '''

''' + + if report["1"]: + report["1"] = "None" + else: + character = CharacterInfo.query.filter(CharacterInfo.id == int(report["1"])).first() if character: - report["3"] = f""" + report["1"] = f""" + href='{url_for('characters.view', id=report['1'])}'> {character.name} """ else: - report["3"] = "Player Deleted" + report["1"] = "Player Deleted" - report["4"] = translate_from_locale(report["4"][2:-1]) + if report["4"] == "0": + report["4"] = "None" + else: + character = CharacterInfo.query.filter(CharacterInfo.id == int(report["4"]) & 0xFFFFFFFF).first() + if character: + report["4"] = f""" + + {character.name} + + """ + else: + report["4"] = "Player Deleted" - if not report["6"]: - report["6"] = '''

''' + report["5"] = translate_from_locale(report["5"][2:-1]) return data diff --git a/app/characters.py b/app/characters.py index a042652..fe67357 100644 --- a/app/characters.py +++ b/app/characters.py @@ -228,9 +228,9 @@ def get(status): if status == "all": query = db.session.query().select_from(CharacterInfo).join(Account) elif status == "approved": - query = db.session.query().select_from(CharacterInfo).join(Account).filter((CharacterInfo.pending_name == "") & (CharacterInfo.needs_rename is False)) + query = db.session.query().select_from(CharacterInfo).join(Account).filter((CharacterInfo.pending_name == "") & (CharacterInfo.needs_rename == False)) elif status == "unapproved": - query = db.session.query().select_from(CharacterInfo).join(Account).filter((CharacterInfo.pending_name != "") | (CharacterInfo.needs_rename is True)) + query = db.session.query().select_from(CharacterInfo).join(Account).filter((CharacterInfo.pending_name != "") | (CharacterInfo.needs_rename == True)) else: raise Exception("Not a valid filter") diff --git a/app/models.py b/app/models.py index 47910bb..b2fe160 100644 --- a/app/models.py +++ b/app/models.py @@ -8,7 +8,6 @@ from flask_sqlalchemy import BaseQuery from sqlalchemy.dialects import mysql from sqlalchemy.exc import OperationalError, StatementError from sqlalchemy.types import JSON -from sqlalchemy.ext.hybrid import hybrid_property from time import sleep import random import string @@ -956,6 +955,12 @@ class BugReport(db.Model): nullable=True ) + reporter_id = db.Column( + mysql.INTEGER(), + nullable=False, + server_default='0' + ) + def save(self): db.session.add(self) db.session.commit() diff --git a/app/properties.py b/app/properties.py index 654773c..3209983 100644 --- a/app/properties.py +++ b/app/properties.py @@ -199,11 +199,11 @@ def get(status="all"): elif status == "approved": query = db.session.query().select_from(Property).join( CharacterInfo, CharacterInfo.id == Property.owner_id - ).join(Account).filter(Property.mod_approved is True).filter(Property.privacy_option == 2) + ).join(Account).filter(Property.mod_approved == True).filter(Property.privacy_option == 2) elif status == "unapproved": query = db.session.query().select_from(Property).join( CharacterInfo, CharacterInfo.id == Property.owner_id - ).join(Account).filter(Property.mod_approved is False).filter(Property.privacy_option == 2) + ).join(Account).filter(Property.mod_approved == False).filter(Property.privacy_option == 2) else: raise Exception("Not a valid filter") diff --git a/app/templates/bug_reports/index.html.j2 b/app/templates/bug_reports/index.html.j2 index 8ebd2b4..69645e0 100644 --- a/app/templates/bug_reports/index.html.j2 +++ b/app/templates/bug_reports/index.html.j2 @@ -14,6 +14,7 @@ Actions + Reporter Body Client Version Other Player diff --git a/migrations/versions/8e52b5c7568a_reporter_id.py b/migrations/versions/8e52b5c7568a_reporter_id.py new file mode 100644 index 0000000..de07031 --- /dev/null +++ b/migrations/versions/8e52b5c7568a_reporter_id.py @@ -0,0 +1,51 @@ +"""reporter_id + +Revision ID: 8e52b5c7568a +Revises: fa97b0d0c351 +Create Date: 2022-04-02 17:35:54.814007 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql +from sqlalchemy import engine_from_config +from sqlalchemy.engine import reflection + +# revision identifiers, used by Alembic. +revision = '8e52b5c7568a' +down_revision = 'fa97b0d0c351' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + if not _table_has_column('bug_reports', 'reporter_id'): + op.add_column( + 'bug_reports', + sa.Column( + 'reporter_id', + mysql.INTEGER(), + server_default='0', + nullable=False + ) + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('bug_reports', 'reporter_id') + # ### end Alembic commands ### + +def _table_has_column(table, column): + config = op.get_context().config + engine = engine_from_config( + config.get_section(config.config_ini_section), prefix='sqlalchemy.') + insp = reflection.Inspector.from_engine(engine) + has_column = False + for col in insp.get_columns(table): + if column not in col['name']: + continue + has_column = True + return has_column