This commit is contained in:
Aaron Kimbre 2022-05-11 12:49:42 -05:00
parent 1dbb637053
commit 1dbe0ce980
2 changed files with 94 additions and 3 deletions

View File

@ -2,7 +2,20 @@ from flask import render_template, Blueprint, redirect, url_for, request, curren
from flask_user import login_required, current_user
from datatables import ColumnDT, DataTables
import datetime
from app.models import Account, db
from app.models import (
Account,
CharacterInfo,
ActivityLog,
Leaderboard,
Mail,
Property,
PropertyContent,
UGC,
AuditLog,
BugReport,
AccountInvitation,
db
)
from app.schemas import AccountSchema
from app import gm_level, log_audit
from app.forms import EditGMLevelForm
@ -113,6 +126,48 @@ def mute(id, days=0):
return redirect(request.referrer if request.referrer else url_for("main.index"))
@accounts_blueprint.route('/delete/<id>/', methods=['GET', 'POST'])
@login_required
@gm_level(9)
def delete(id):
account = Account.query.filter(Account.id == id).first()
message = f"Deleted Account ({account.id}){account.username}"
chars = CharacterInfo.query.filter(CharacterInfo.account_id == id).all()
for char in chars:
activities = ActivityLog.query.filter(ActivityLog.character_id == char.id).all()
for activity in activities:
activity.delete()
lb_entries = Leaderboard.query.filter(Leaderboard.character_id == char.id).all()
for lb_entry in lb_entries:
lb_entry.delete()
mails = Mail.query.filter(Mail.receiver_id == char.id).all()
for mail in mails:
mail.delete()
props = Property.query.filter(Property.owner_id == char.id).all()
for prop in props:
prop_contents = PropertyContent.query.filter(PropertyContent.property_id == prop.id).all()
for prop_content in prop_contents:
if prop_content.lot == "14":
UGC.query.filter(UGC.id == prop.ugc_id).first().delete()
prop_content.delete()
prop.delete()
char.delete()
# This is for GM stuff, it will be permnently delete logs
bugs = BugReport.query.filter(BugReport.resolve_by_id == id).all()
for bug in bugs:
bug.delete()
audits = AuditLog.query.filter(AuditLog.account_id == id).all()
for audit in audits:
audit.delete()
invites = AccountInvitation.query.filter(AccountInvitation.invited_by_user_id == id).all()
for invite in invites:
invite.delete()
account.delete()
flash(message, "danger")
log_audit(message)
return redirect(url_for("main.index"))
@accounts_blueprint.route('/get', methods=['GET'])
@login_required
@gm_level(3)

View File

@ -141,9 +141,9 @@
{% endif %}
</div>
</div>
{% endif %}
{% endif %}
{% if current_user.id != account_data.id and current_user.gm_level > 3 %}
{% if current_user.id != account_data.id and current_user.gm_level > 3 %}
<hr class="bg-primary"/>
<div class="row">
<div class="col text-center">
@ -191,6 +191,42 @@
Mute for 1 year
</a>
{% endif %}
{% if current_user.gm_level == 9 %}
<button type="button" class="btn btn-danger btn-block" data-toggle="modal" data-target="#deleteModal">
Delete Account
</button>
{% endif %}
</div>
{% endif %}
</div>
{% if current_user.gm_level == 9 %}
{# delete Modal #}
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content bg-dark">
<div class="modal-header">
<h1 class="modal-title" id="deleteModalLabel">
Permanently Delete this Account?
</h1>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<h2> This can NOT be undone! </h2>
<br/>
This user is a GM {{account_data.gm_level}} !!!<br/>
This will delete their everything, including but not limited to:<br/>
Properties, Audit Logs, Bug Reports, and Invitations!
</div>
<div class="modal-footer">
<a role="button" class="btn btn-danger btn-block"
href='{{ url_for('accounts.delete', id=account_data.id) }}'>
Permanently Delete
</a>
</div>
</div>
</div>
</div>
{% endif %}