forked from MarseyWorld/MarseyWorld
refactor banned domains a little bit
parent
25c5c8fb7d
commit
c78579ec5a
|
@ -1417,28 +1417,19 @@ def admin_banned_domains(v):
|
|||
banned_domains = g.db.query(BannedDomain).all()
|
||||
return render_template("admin/banned_domains.html", v=v, banned_domains=banned_domains)
|
||||
|
||||
@app.post("/admin/banned_domains")
|
||||
@app.post("/admin/ban_domain")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@admin_level_required(PERMS['DOMAINS_BAN'])
|
||||
def admin_toggle_ban_domain(v):
|
||||
def ban_domain(v):
|
||||
|
||||
domain=request.values.get("domain", "").strip()
|
||||
if not domain: abort(400)
|
||||
|
||||
reason=request.values.get("reason").strip()
|
||||
|
||||
d = g.db.query(BannedDomain).filter_by(domain=domain).one_or_none()
|
||||
if d:
|
||||
g.db.delete(d)
|
||||
ma = ModAction(
|
||||
kind="unban_domain",
|
||||
user_id=v.id,
|
||||
_note=domain
|
||||
)
|
||||
g.db.add(ma)
|
||||
|
||||
else:
|
||||
if not reason: abort(400, 'Reason is required!')
|
||||
|
||||
existing = g.db.get(BannedDomain, domain)
|
||||
if not existing:
|
||||
d = BannedDomain(domain=domain, reason=reason)
|
||||
g.db.add(d)
|
||||
ma = ModAction(
|
||||
|
@ -1448,9 +1439,28 @@ def admin_toggle_ban_domain(v):
|
|||
)
|
||||
g.db.add(ma)
|
||||
|
||||
|
||||
return redirect("/admin/banned_domains/")
|
||||
|
||||
|
||||
@app.post("/admin/unban_domain/<domain>")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@admin_level_required(PERMS['DOMAINS_BAN'])
|
||||
def unban_domain(v, domain):
|
||||
existing = g.db.get(BannedDomain, domain)
|
||||
if not existing: abort(400, 'Domain is not banned!')
|
||||
|
||||
g.db.delete(existing)
|
||||
ma = ModAction(
|
||||
kind="unban_domain",
|
||||
user_id=v.id,
|
||||
_note=domain
|
||||
)
|
||||
g.db.add(ma)
|
||||
|
||||
return {"message": f"{domain} has been unbanned!"}
|
||||
|
||||
|
||||
|
||||
@app.post("/admin/nuke_user")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@admin_level_required(PERMS['POST_COMMENT_MODERATION'])
|
||||
|
|
|
@ -10,28 +10,43 @@
|
|||
|
||||
</pre>
|
||||
|
||||
<div class="overflow-x-auto"><table class="table table-striped mb-5">
|
||||
<script>
|
||||
function unbanDomain(t, domain) {
|
||||
post_toast(t,'/admin/unban_domain/' + domain);
|
||||
t.parentElement.parentElement.remove();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table table-striped mb-5" id="domains-table">
|
||||
<thead class="bg-primary text-white">
|
||||
<tr>
|
||||
<th>Domain</th>
|
||||
<th>Ban reason</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for domain in banned_domains %}
|
||||
<tr>
|
||||
<td>{{domain.domain}}</td>
|
||||
<td>{{domain.reason}}</td>
|
||||
<td>
|
||||
<button class="btn btn-danger" onclick="unbanDomain(this, '{{domain.domain}}')">Unban</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<form action="/admin/banned_domains" method="post">
|
||||
<form action="/admin/ban_domain" method="post">
|
||||
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||
<input autocomplete="off" name="domain" placeholder="Enter domain here.." class="form-control" required>
|
||||
<input autocomplete="off" name="reason" placeholder="Enter ban reason here.." oninput="document.getElementById('ban-submit').disabled=false" class="form-control">
|
||||
<input autocomplete="off" id="ban-submit" type="submit" onclick="disable(this)" class="btn btn-primary" value="Toggle ban" disabled>
|
||||
</form>
|
||||
<input autocomplete="off" name="reason" placeholder="Enter ban reason here.." oninput="document.getElementById('ban-submit').disabled=false" class="form-control mt-2">
|
||||
<input autocomplete="off" id="ban-submit" type="submit" onclick="disable(this)" class="btn btn-primary mt-2" value="Ban domain" disabled>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in New Issue