restore blocks to its own page in the settings

pull/146/head
Aevann 2023-05-05 05:16:19 +03:00
parent 998df31700
commit 2156f9ef03
6 changed files with 120 additions and 98 deletions

View File

@ -0,0 +1,32 @@
function block_user() {
const usernameField = document.getElementById("block-username");
const isValidUsername = usernameField.checkValidity();
username = usernameField.value;
if (isValidUsername) {
const xhr = new XMLHttpRequest();
xhr.open("post", "/settings/block");
xhr.setRequestHeader('xhr', 'xhr');
f=new FormData();
f.append("username", username);
f.append("formkey", formkey());
xhr.onload=function(){
if (xhr.status<300) {
location.reload();
}
else {
showToast(false, "Error, please try again later.");
}
}
xhr.send(f)
}
}
function unblock_user(t, url) {
postToast(t, url,
{
},
() => {
t.parentElement.parentElement.remove();
}
);
}

View File

@ -9,37 +9,4 @@ function emailVerifyText() {
document.getElementById("email-verify-text").innerHTML = "Verification email sent! Please check your inbox.";
}
function block_user() {
const usernameField = document.getElementById("block-username");
const isValidUsername = usernameField.checkValidity();
username = usernameField.value;
if (isValidUsername) {
const xhr = new XMLHttpRequest();
xhr.open("post", "/settings/block");
xhr.setRequestHeader('xhr', 'xhr');
f=new FormData();
f.append("username", username);
f.append("formkey", formkey());
xhr.onload=function(){
if (xhr.status<300) {
location.reload();
}
else {
showToast(false, "Error, please try again later.");
}
}
xhr.send(f)
}
}
function unblock_user(t, url) {
postToast(t, url,
{
},
() => {
t.parentElement.parentElement.remove();
}
);
}
document.getElementById('2faToggle').addEventListener('change', () => {twoStepModal.show()})

View File

@ -649,6 +649,11 @@ def settings_security(v:User):
msg=get_msg()
)
@app.get("/settings/blocks")
@auth_required
def settings_blocks(v:User):
return render_template("settings/blocks.html", v=v)
@app.post("/settings/block")
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)

View File

@ -21,6 +21,7 @@
<li class="nav-item"><a class="nav-link{% if request.path=='/settings/advanced' %} active{% endif %}" href="/settings/advanced">Advanced</a></li>
<li class="nav-item"><a class="nav-link{% if request.path=='/settings/css' %} active{% endif %}" href="/settings/css">CSS</a></li>
<li class="nav-item"><a class="nav-link{% if request.path=='/settings/security' %} active{% endif %}" href="/settings/security">Security</a></li>
<li class="nav-item"><a class="nav-link{% if request.path=='/settings/blocks' %} active{% endif %}" href="/settings/blocks">Blocks</a></li>
{% if FEATURES["BOTS"] %}
<li class="nav-item"><a class="nav-link{% if request.path=='/settings/apps' %} active{% endif %}" href="/settings/apps">Apps/Bots</a></li>
{% endif %}

View File

@ -0,0 +1,82 @@
{% extends "settings.html" %}
{% block pagetitle %}Blocks{% endblock %}
{% block content %}
<script defer src="{{'js/settings_blocks.js' | asset}}"></script>
<div class="row settings-page" id="settings-page-blocks">
<div class="col col-lg-8">
<div class="settings">
<section id="site-settings-blocks-section" class="settings-section-section">
<div class="row">
<div class="col">
<div class="d-md-flex justify-content-between mb-3">
<div>
<h5>Users you block</h5>
<p class="text-small text-muted mb-md-0">You have blocked the following users. They cannot reply to your content or notify you with a username mention.</p>
</div>
<div class="mt-auto">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#blockmodal">Block user</button>
</div>
</div>
{% if v.blocking.first() %}
<div class="card mb-5">
<div class="overflow-x-auto"><table class="table table-hover rounded mb-0">
<thead class="thead-dark">
<tr>
<th>User</th>
<th>Unblock</th>
</tr>
</thead>
<tbody class="text-muted">
{% for block in v.blocking %}
{% set user=block.target %}
<tr>
<td>
{% include "user_in_table.html" %}
</td>
<td>
<button type="button" class="btn btn-primary" data-nonce="{{g.nonce}}" data-onclick="unblock_user(this, '/settings/unblock?username={{user.username}}&formkey={{v|formkey}}')">Unblock</button>
</td>
</tr>
{% else %}
<td>There are no blocked users</td>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
{{macros.ghost_box('No blocked users', '', 2)}}
{% endif %}
</div>
</div>
</section>
</div>
</div>
</div>
<div class="modal fade" id="blockmodal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Block user</h5>
<button type="button" class="close" data-bs-dismiss="modal">
<span><i class="far fa-times"></i></span>
</button>
</div>
<div class="modal-body">
<input hidden name="formkey" value="{{v|formkey}}">
<input autocomplete="off" type="text" name="username" placeholder="Enter username..." id="block-username" class="form-control" maxlength=25 required>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-link text-muted" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="blockUserButton" data-nonce="{{g.nonce}}" data-onclick="block_user()">Block user</button>
</div>
</div>
</div>
</div>
<div class="toast error" id="toast-exile-error" data-bs-animation="true" data-bs-autohide="true" data-bs-delay="5000">
<div class="toast-body text-center">
<i class="fas fa-exclamation-circle text-danger mr-2"></i><span id="toast-error-message">Error. Please try again.</span>
</div>
</div>
{% endblock %}

View File

@ -124,50 +124,6 @@
</div>
</form>
</section>
<section id="site-settings-blocks-section" class="settings-section-section">
<div class="row">
<div class="col">
<div class="d-md-flex justify-content-between mb-3">
<div>
<h5>Users you block</h5>
<p class="text-small text-muted mb-md-0">You have blocked the following users. They cannot reply to your content or notify you with a username mention.</p>
</div>
<div class="mt-auto">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#blockmodal">Block user</button>
</div>
</div>
{% if v.blocking.first() %}
<div class="card mb-5">
<div class="overflow-x-auto"><table class="table table-hover rounded mb-0">
<thead class="thead-dark">
<tr>
<th>User</th>
<th>Unblock</th>
</tr>
</thead>
<tbody class="text-muted">
{% for block in v.blocking %}
{% set user=block.target %}
<tr>
<td>
{% include "user_in_table.html" %}
</td>
<td>
<button type="button" class="btn btn-primary" data-nonce="{{g.nonce}}" data-onclick="unblock_user(this, '/settings/unblock?username={{user.username}}&formkey={{v|formkey}}')">Unblock</button>
</td>
</tr>
{% else %}
<td>There are no blocked users</td>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
{{macros.ghost_box('No blocked users', '', 2)}}
{% endif %}
</div>
</div>
</section>
</div>
</div>
</div>
@ -229,27 +185,6 @@
</div>
</div>
<div class="modal fade" id="blockmodal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Block user</h5>
<button type="button" class="close" data-bs-dismiss="modal">
<span><i class="far fa-times"></i></span>
</button>
</div>
<div class="modal-body">
<input hidden name="formkey" value="{{v|formkey}}">
<input autocomplete="off" type="text" name="username" placeholder="Enter username..." id="block-username" class="form-control" maxlength=25 required>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-link text-muted" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="blockUserButton" data-nonce="{{g.nonce}}" data-onclick="block_user()">Block user</button>
</div>
</div>
</div>
</div>
<div class="toast error" id="toast-exile-error" data-bs-animation="true" data-bs-autohide="true" data-bs-delay="5000">
<div class="toast-body text-center">
<i class="fas fa-exclamation-circle text-danger mr-2"></i><span id="toast-error-message">Error. Please try again.</span>