forked from MarseyWorld/MarseyWorld
templates: remove redundant badge_remove template
templates: fix badge admin template when removing a badgemaster
parent
3a6dfdf2de
commit
e6ce4edbd8
|
@ -508,25 +508,24 @@ def under_attack(v):
|
|||
return {"message": f"Under attack mode {enable_disable_str}d!"}
|
||||
|
||||
@app.get("/admin/badge_grant")
|
||||
@app.get("/admin/badge_remove")
|
||||
@admin_level_required(PERMS['USER_BADGES'])
|
||||
@feature_required('BADGES')
|
||||
def badge_grant_get(v):
|
||||
grant = request.url.endswith("grant")
|
||||
badges = g.db.query(BadgeDef).order_by(BadgeDef.id).all()
|
||||
return render_template("admin/badge_grant.html", v=v, badge_types=badges)
|
||||
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=grant)
|
||||
|
||||
@app.post("/admin/badge_grant")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@admin_level_required(PERMS['USER_BADGES'])
|
||||
@feature_required('BADGES')
|
||||
def badge_grant_post(v):
|
||||
|
||||
|
||||
badges = g.db.query(BadgeDef).order_by(BadgeDef.id).all()
|
||||
|
||||
user = get_user(request.values.get("username").strip(), graceful=True)
|
||||
if not user:
|
||||
return render_template("admin/badge_grant.html", v=v, badge_types=badges, error="User not found.")
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=True, error="User not found.")
|
||||
|
||||
try: badge_id = int(request.values.get("badge_id"))
|
||||
except: abort(400)
|
||||
|
@ -538,7 +537,7 @@ def badge_grant_post(v):
|
|||
abort(403)
|
||||
|
||||
if user.has_badge(badge_id):
|
||||
return render_template("admin/badge_grant.html", v=v, badge_types=badges, error="User already has that badge.")
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=True, error="User already has that badge.")
|
||||
|
||||
new_badge = Badge(badge_id=badge_id, user_id=user.id)
|
||||
|
||||
|
@ -564,34 +563,18 @@ def badge_grant_post(v):
|
|||
_note=new_badge.name
|
||||
)
|
||||
g.db.add(ma)
|
||||
|
||||
return render_template("admin/badge_grant.html", v=v, badge_types=badges, msg=f"{new_badge.name} Badge granted to @{user.username} successfully!")
|
||||
|
||||
|
||||
|
||||
@app.get("/admin/badge_remove")
|
||||
@admin_level_required(PERMS['USER_BADGES'])
|
||||
@feature_required('BADGES')
|
||||
def badge_remove_get(v):
|
||||
|
||||
|
||||
badges = g.db.query(BadgeDef).order_by(BadgeDef.id).all()
|
||||
|
||||
return render_template("admin/badge_remove.html", v=v, badge_types=badges)
|
||||
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=True, msg=f"{new_badge.name} Badge granted to @{user.username} successfully!")
|
||||
|
||||
@app.post("/admin/badge_remove")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@admin_level_required(PERMS['USER_BADGES'])
|
||||
@feature_required('BADGES')
|
||||
def badge_remove_post(v):
|
||||
|
||||
|
||||
badges = g.db.query(BadgeDef).order_by(BadgeDef.id).all()
|
||||
|
||||
user = get_user(request.values.get("username").strip(), graceful=True)
|
||||
if not user:
|
||||
return render_template("admin/badge_remove.html", v=v, badge_types=badges, error="User not found.")
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=False, error="User not found.")
|
||||
|
||||
try: badge_id = int(request.values.get("badge_id"))
|
||||
except: abort(400)
|
||||
|
@ -601,7 +584,7 @@ def badge_remove_post(v):
|
|||
|
||||
badge = user.has_badge(badge_id)
|
||||
if not badge:
|
||||
return render_template("admin/badge_remove.html", v=v, badge_types=badges, error="User doesn't have that badge.")
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=False, error="User doesn't have that badge.")
|
||||
|
||||
if v.id != user.id:
|
||||
text = f"@{v.username} (Admin) has removed the following profile badge from you:\n\n![]({badge.path})\n\n**{badge.name}**\n\n{badge.badge.description}"
|
||||
|
@ -614,11 +597,8 @@ def badge_remove_post(v):
|
|||
_note=badge.name
|
||||
)
|
||||
g.db.add(ma)
|
||||
|
||||
g.db.delete(badge)
|
||||
|
||||
|
||||
return render_template("admin/badge_remove.html", v=v, badge_types=badges, msg=f"{badge.name} Badge removed from @{user.username} successfully!")
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=False, msg=f"{badge.name} Badge removed from @{user.username} successfully!")
|
||||
|
||||
|
||||
@app.get("/admin/users")
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
{% extends "default.html" %}
|
||||
|
||||
{% block title %}
|
||||
<title>Badge Grant</title>
|
||||
{% endblock %}
|
||||
|
||||
{% if grant %}
|
||||
{% set title="Badge Grant" %}
|
||||
{% else %}
|
||||
{% set title="Badge Remove" %}
|
||||
{% endif %}
|
||||
{% block pagetitle %}{{title}}{% endblock %}
|
||||
{% block pagetype %}message{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -31,12 +32,17 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
<h5 class="mt-2">Badge Grant</h5>
|
||||
<h5 class="mt-2">{{title}}</h5>
|
||||
|
||||
<form action="/admin/badge_grant", method="post">
|
||||
{% if grant %}
|
||||
{% set form_action="/admin/badge_grant" %}
|
||||
{% else %}
|
||||
{% set form_action="/admin/badge_remove" %}
|
||||
{% endif %}
|
||||
|
||||
<form action="{{form_action}}", method="post">
|
||||
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||
|
||||
|
||||
<label for="input-username">Username</label><br>
|
||||
<input autocomplete="off" id="input-username" class="form-control" type="text" name="username" required>
|
||||
|
||||
|
@ -68,13 +74,13 @@
|
|||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% if grant %}
|
||||
<label for="input-url">URL</label><br>
|
||||
<input autocomplete="off" id="input-url" class="form-control" type="text" name="url" type="url" placeholder="Optional">
|
||||
|
||||
<label for="input-description">Custom description</label><br>
|
||||
<input autocomplete="off" id="input-description" class="form-control" type="text" name="description" placeholder="Leave blank for badge default">
|
||||
|
||||
{% endif %}
|
||||
<input autocomplete="off" class="btn btn-primary mt-3" type="submit" onclick="disable(this)">
|
||||
|
||||
</form>
|
|
@ -1,91 +0,0 @@
|
|||
{% extends "default.html" %}
|
||||
|
||||
{% block title %}
|
||||
<title>Badge Remove</title>
|
||||
{% endblock %}
|
||||
|
||||
{% block pagetype %}message{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if error %}
|
||||
<div class="alert alert-danger alert-dismissible fade show my-3" role="alert">
|
||||
<i class="fas fa-exclamation-circle my-auto"></i>
|
||||
<span>
|
||||
{{error}}
|
||||
</span>
|
||||
<button type="button" class="close" data-bs-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true"><i class="far fa-times"></i></span>
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if msg %}
|
||||
<div class="alert alert-success alert-dismissible fade show my-3" role="alert">
|
||||
<i class="fas fa-check-circle my-auto" aria-hidden="true"></i>
|
||||
<span>
|
||||
{{msg}}
|
||||
</span>
|
||||
<button type="button" class="close" data-bs-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true"><i class="far fa-times"></i></span>
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<h5 class="mt-2">Badge Remove</h5>
|
||||
|
||||
<form action="/admin/badge_remove", method="post">
|
||||
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||
|
||||
|
||||
<label for="input-username">Username</label><br>
|
||||
<input autocomplete="off" id="input-username" class="form-control" type="text" name="username" required>
|
||||
|
||||
<div class="overflow-x-auto"><table class="table table-striped">
|
||||
<thead class="bg-primary text-white">
|
||||
<tr>
|
||||
<th scope="col">Select</th>
|
||||
<th scope="col">Image</th>
|
||||
<th scope="col">Name</th>
|
||||
<th scope="col">Default Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for badge in badge_types %}
|
||||
<tr>
|
||||
<td>
|
||||
<div class="custom-control">
|
||||
<input autocomplete="off" class="custom-control-input" type="radio" id="{{badge.id}}" name="badge_id" value="{{badge.id}}">
|
||||
<label class="custom-control-label" for="{{badge.id}}"></label>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<label for="badge-{{badge.id}}">
|
||||
<img class="contain" alt="{{badge.name}}" loading="lazy" src="{{badge.path}}?b=4" width=64.16 height=70>
|
||||
</label>
|
||||
</td>
|
||||
<td>{{badge.name}}</td>
|
||||
<td>{{badge.description}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
<label for="input-url">URL</label><br>
|
||||
<input autocomplete="off" id="input-url" class="form-control" type="text" name="url" type="url" placeholder="Optional">
|
||||
|
||||
<label for="input-description">Custom description</label><br>
|
||||
<input autocomplete="off" id="input-description" class="form-control" type="text" name="description" placeholder="Leave blank for badge default">
|
||||
|
||||
<input autocomplete="off" class="btn btn-primary mt-3" type="submit" onclick="disable(this)">
|
||||
|
||||
</form>
|
||||
|
||||
<style>
|
||||
@media (max-width: 767.98px) {
|
||||
table {
|
||||
display: inline-block;
|
||||
overflow: auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in New Issue