Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add name management functionality for Characters and Pets #5

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 64 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,70 @@ def dashboard():

return render_template('private/dashboard.html', current_user=current_user, resources=resources)

# Name approval dashboard
@app.route('/approve_names', methods=['GET', 'POST'])
@login_required
def approve_names():
message = ''
error = ''
connection = db.engine
if current_user.gm_level != 9:
abort(403)
return

if request.method == 'POST':

pending_name = request.form['pending_name']
approved = int(request.form['approved'])

# Character name approvals
if "char_id" in request.form and "pet_id" not in request.form:
char_id = request.form['char_id']
if approved > 0:
query = "UPDATE charinfo SET name = %s, pending_name = '' WHERE id = %s"
try:
connection.execute(query, (pending_name, char_id))
except BaseException as error:
error = "Error running query. Message: {}".format(error)
else:
message = 'Character name {} approved'.format(pending_name)
else:
query = "UPDATE charinfo SET needs_rename = true WHERE id = %s"
try:
connection.execute(query, (char_id))
except BaseException as error:
error = "Error running query. Message: {}".format(error)
else:
message = 'Character {} marked for rename'.format(pending_name)
# Pet name approvals
elif "pet_id" in request.form and "char_id" not in request.form:
pet_id = request.form['pet_id']
print(pet_id)
print(approved)
if approved > 0:
query = "UPDATE pet_names SET approved = 2 WHERE id = %s"
try:
connection.execute(query, (pet_id))
except BaseException as error:
error = "Error running query. Message: {}".format(error)
else:
message = 'Pet name {} approved'.format(pending_name)
else:
query = "UPDATE pet_names SET approved = 0 WHERE id = %s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server itself does not seem to support rejecting pet names yet. Unless I am missing something it only supports pending approval (1) and approved (2) at the moment, see relevant code.

Would it make sense to omit rejecting pet names for now, until that has been implemented server-side?
Otherwise it might cause issues in the future when it is implemented for the server but they chose a different implementation, other than using value 0 to represent renaming required.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server itself does not seem to support rejecting pet names yet. Unless I am missing something it only supports pending approval (1) and approved (2) at the moment, see relevant code.

Would it make sense to omit rejecting pet names for now, until that has been implemented server-side? Otherwise it might cause issues in the future when it is implemented for the server but they chose a different implementation, other than using value 0 to represent renaming required.

The server does support rejecting names. Changing the approved value to 0 rejects the name, and forces the user to rename the pet when they bring it out next.

However, that being said, it does NOT support forcing a user to rename a pet that's already been approved. To accomplish this, you need to set a 0 in the pet_names table AND set a 0 on the m tag in the respective pet tag in the user's xml data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification!

However, that being said, it does NOT support forcing a user to rename a pet that's already been approved.

This might not be an issue (for now) because if I understand these changes correctly, only unapproved pet names are displayed. So unless you are manually editing the database to change an already approved name back to unapproved, this situation should not occur.

(Though @Lego6245 can probably answer that better.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct on all counts.

While there is no reference in server code, in client code, it handles the state of '0' correctly.

Only pending names are shown. There is no way to re-force a name to be approved (currently).

try:
connection.execute(query, (pet_id))
except BaseException as error:
error = "Error running query. Message: {}".format(error)
else:
message = 'Pet name {} marked for rename'.format(pending_name)
else:
error = 'Internal error: Both pet ID and character ID provided'

query = "SELECT id, account_id, name, pending_name FROM charinfo WHERE pending_name <> '' AND needs_rename = false"
result = connection.execute(query).all()
query = "SELECT id, pet_name FROM pet_names WHERE approved = 1"
pet_result = connection.execute(query).all()
return render_template('private/approve_names.html', message=message, error=error, names=result, pet_names=pet_result, current_user=current_user, resources=resources)

"""
App configuration
Expand Down
18 changes: 18 additions & 0 deletions templates/private/admin_base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends "bootstrap/base.html" %}

{% block navbar %}
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="{{ url_for('dashboard') }}">Dashboard</a>
</div>
<ul class="nav navbar-nav">
<a class="navbar-brand" href="{{ url_for('approve_names') }}">Name Approval</a>
</ul>
<ul class="nav navbar-nav" style="float: right">
<li class="active"><a href="#">Welcome {{ current_user.username }}!</a></li>
<li><a href="{{ url_for('logout') }}">Logout</a></li>
</ul>
</div>
</nav>
{% endblock navbar %}}
140 changes: 140 additions & 0 deletions templates/private/approve_names.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{% extends "private/admin_base.html" %}
{% block title %}Name Approval{% endblock %}

{% block content %}
{# LOGO #}
<div class="container" style="margin-top: 50px">

{# Display logo #}
<div style="margin-bottom: 50px">
<img
src="{{ url_for('static', filename=resources.LOGO) }}"
class="center-block img-responsive mx-auto d-block"
alt="Logo"
width="100"
height="100"
>
</div>

</div>

{# Key creation #}
<div class="container">
<div class="text-center">
<h3>Name Approval</h3>
</div>

<div class="col-lg-3">
</div>
<div class="col-lg-6">

{# If the error value is set, display the error in red text #}
{% if error %}
<div class="alert alert-danger">
{{ error }}
</div>
{% endif %}

{# If the message value is set, display the message in green text #}
{% if message %}
<div class="alert alert-success">
{{ message }}
</div>
{% endif %}

{% if names %}
<h3>Character Names</h3>
<table class="table table-striped">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about including some default text like "No pending approvals" when there are neither pending character name nor pet name approvals?
This would make it a little bit more obvious why the page is empty.

Though I am not a member of this project, so feel free to just ignore that suggestion.

<tr>
<th>Character ID</th>
<th>Account ID</th>
<th>Current Name</th>
<th>Custom Name</th>
<th>Approve?</th>
<th>Reject?</th>
</tr>
{% for name in names %}
<tr>
<td>{{ name.id }}</td>
<td>{{ name.account_id }}</td>
<td>{{ name.name }}</td>
<td>{{ name.pending_name }}</td>
<td><button class="btn btn-primary approvalButton" data-id="{{ name.id }}" data-pending_name="{{ name.pending_name }}">Approve</button></td>
<td><button class="btn btn-warning rejectButton" data-id="{{ name.id }}" data-pending_name="{{ name.pending_name }}">Reject</button></td>
</tr>
{% endfor %}
</table>
{% endif %}
{% if pet_names %}
<h3>Pet Names</h3>
<table class="table table-striped">
<tr>
<th>Pet ID</th>
<th>Current Name</th>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be "Custom Name" (or just "Name") to match the column header for character names?

<th>Approve?</th>
<th>Reject?</th>
</tr>
{% for name in pet_names %}
<tr>
<td>{{ name.id }}</td>
<td>{{ name.pet_name }}</td>
<td><button class="btn btn-primary approvalPetButton" data-id="{{ name.id }}" data-pending_name="{{ name.pet_name }}">Approve</button></td>
<td><button class="btn btn-warning rejectPetButton" data-id="{{ name.id }}" data-pending_name="{{ name.pet_name }}">Reject</button></td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
<div class="col-lg-3">
</div>
</div>
</div>
{% endblock %}

{% block scripts %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>

for (const button of document.querySelectorAll('.approvalButton')) {
button.addEventListener('click', (event) => {
$("body").load("{{ url_for('approve_names') }}", {
char_id: event.target.dataset.id,
pending_name: event.target.dataset.pending_name,
approved: 1,
});
});
}

for (const button of document.querySelectorAll('.rejectButton')) {
button.addEventListener('click', (event) => {
$("body").load("{{ url_for('approve_names') }}", {
char_id: event.target.dataset.id,
pending_name: event.target.dataset.pending_name,
approved: 0,
});
});
}

for (const button of document.querySelectorAll('.approvalPetButton')) {
button.addEventListener('click', (event) => {
$("body").load("{{ url_for('approve_names') }}", {
pet_id: event.target.dataset.id,
pending_name: event.target.dataset.pending_name,
approved: 1,
});
});
}

for (const button of document.querySelectorAll('.rejectPetButton')) {
button.addEventListener('click', (event) => {
$("body").load("{{ url_for('approve_names') }}", {
pet_id: event.target.dataset.id,
pending_name: event.target.dataset.pending_name,
approved: 0,
});
});
}

</script>

{% endblock %}
18 changes: 1 addition & 17 deletions templates/private/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
{% extends "bootstrap/base.html" %}
{% extends "private/admin_base.html" %}
{% block title %}Key Creation{% endblock %}

{% block navbar %}
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="{{ url_for('dashboard') }}">Dashboard</a>
</div>
<ul class="nav navbar-nav">
</ul>
<ul class="nav navbar-nav" style="float: right">
<li class="active"><a href="#">Welcome {{ current_user.username }}!</a></li>
<li><a href="{{ url_for('logout') }}">Logout</a></li>
</ul>
</div>
</nav>
{% endblock navbar %}}

{% block content %}
{# LOGO #}
<div class="container" style="margin-top: 50px">
Expand Down