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()
|
banned_domains = g.db.query(BannedDomain).all()
|
||||||
return render_template("admin/banned_domains.html", v=v, banned_domains=banned_domains)
|
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")
|
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||||
@admin_level_required(PERMS['DOMAINS_BAN'])
|
@admin_level_required(PERMS['DOMAINS_BAN'])
|
||||||
def admin_toggle_ban_domain(v):
|
def ban_domain(v):
|
||||||
|
|
||||||
domain=request.values.get("domain", "").strip()
|
domain=request.values.get("domain", "").strip()
|
||||||
if not domain: abort(400)
|
if not domain: abort(400)
|
||||||
|
|
||||||
reason=request.values.get("reason").strip()
|
reason=request.values.get("reason").strip()
|
||||||
|
if not reason: abort(400, 'Reason is required!')
|
||||||
|
|
||||||
d = g.db.query(BannedDomain).filter_by(domain=domain).one_or_none()
|
existing = g.db.get(BannedDomain, domain)
|
||||||
if d:
|
if not existing:
|
||||||
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!')
|
|
||||||
d = BannedDomain(domain=domain, reason=reason)
|
d = BannedDomain(domain=domain, reason=reason)
|
||||||
g.db.add(d)
|
g.db.add(d)
|
||||||
ma = ModAction(
|
ma = ModAction(
|
||||||
|
@ -1448,9 +1439,28 @@ def admin_toggle_ban_domain(v):
|
||||||
)
|
)
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
|
|
||||||
|
|
||||||
return redirect("/admin/banned_domains/")
|
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")
|
@app.post("/admin/nuke_user")
|
||||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||||
@admin_level_required(PERMS['POST_COMMENT_MODERATION'])
|
@admin_level_required(PERMS['POST_COMMENT_MODERATION'])
|
||||||
|
|
|
@ -10,28 +10,43 @@
|
||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<div class="overflow-x-auto"><table class="table table-striped mb-5">
|
<script>
|
||||||
<thead class="bg-primary text-white">
|
function unbanDomain(t, domain) {
|
||||||
<tr>
|
post_toast(t,'/admin/unban_domain/' + domain);
|
||||||
<th>Domain</th>
|
t.parentElement.parentElement.remove();
|
||||||
<th>Ban reason</th>
|
}
|
||||||
</tr>
|
</script>
|
||||||
</thead>
|
|
||||||
|
|
||||||
{% for domain in banned_domains %}
|
<div class="overflow-x-auto">
|
||||||
<tr>
|
<table class="table table-striped mb-5" id="domains-table">
|
||||||
<td>{{domain.domain}}</td>
|
<thead class="bg-primary text-white">
|
||||||
<td>{{domain.reason}}</td>
|
<tr>
|
||||||
</tr>
|
<th>Domain</th>
|
||||||
{% endfor %}
|
<th>Ban reason</th>
|
||||||
</table>
|
<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 %}
|
||||||
|
</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 type="hidden" name="formkey" value="{{v.formkey}}">
|
||||||
<input autocomplete="off" name="domain" placeholder="Enter domain here.." class="form-control" required>
|
<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" 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" value="Toggle ban" disabled>
|
<input autocomplete="off" id="ban-submit" type="submit" onclick="disable(this)" class="btn btn-primary mt-2" value="Ban domain" disabled>
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue