split off muting and unmuting

remotes/1693176582716663532/tmp_refs/heads/watchparty
Aevann1 2022-11-12 11:11:31 +02:00
parent dd3c8c6a32
commit 42e40c1691
4 changed files with 33 additions and 41 deletions

View File

@ -47,17 +47,3 @@ function approveComment(t,comment_id,button1,button2,cls) {
}
);
}
function adminToggleMute(userId, muteStatus, buttonId) {
const xhr = createXhrWithFormKey(`/mute_user/${userId}/${muteStatus}`);
xhr[0].onload = function() {
let data
try {data = JSON.parse(xhr[0].response)}
catch(e) {console.log(e)}
success = xhr[0].status >= 200 && xhr[0].status < 300;
showToast(success, getMessageFromJsonData(success, data));
};
xhr[0].send(xhr[1]);
document.getElementById('mute-user-' + buttonId).classList.toggle("d-none");
document.getElementById('unmute-user-' + buttonId).classList.toggle("d-none");
}

View File

@ -1096,35 +1096,43 @@ def unban_user(user_id, v):
return {"message": f"@{user.username} has been unbanned!"}
@app.post("/mute_user/<int:user_id>/<int:mute_status>")
@app.post("/mute_user/<int:user_id>")
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@admin_level_required(PERMS['USER_BAN'])
def mute_user(v, user_id, mute_status):
def mute_user(v, user_id):
user = get_account(user_id)
if mute_status != 0 and not user.is_muted:
if not user.is_muted:
user.is_muted = True
log_action = 'mod_mute_user'
success_msg = f"@{user.username} has been muted!"
elif mute_status == 0 and user.is_muted:
ma = ModAction(
kind='mod_mute_user',
user_id=v.id,
target_user_id=user.id,
)
g.db.add(user)
g.db.add(ma)
return {"message": f"@{user.username} has been muted!"}
@app.post("/unmute_user/<int:user_id>")
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@admin_level_required(PERMS['USER_BAN'])
def unmute_user(v, user_id):
user = get_account(user_id)
if user.is_muted:
user.is_muted = False
log_action = 'mod_unmute_user'
success_msg = f"@{user.username} has been un-muted!"
else:
abort(400)
ma = ModAction(
kind='mod_unmute_user',
user_id=v.id,
target_user_id=user.id,
)
g.db.add(user)
g.db.add(ma)
ma = ModAction(
kind=log_action,
user_id=v.id,
target_user_id=user.id,
)
return {"message": f"@{user.username} has been unmuted!"}
g.db.add(user)
g.db.add(ma)
if 'redir' in request.values:
return redirect(user.url)
else:
return {"message": success_msg}
@app.post("/remove_post/<post_id>")
@limiter.limit("1/second;30/minute;200/hour;1000/day")

View File

@ -569,8 +569,8 @@
<button type="button" class="btn btn-primary nobackground" onclick="ToggleReplyBox('reply-message-{{c.id}}')">Reply</button>
{% if (v and v.admin_level >= PERMS['USER_BAN']) and (c.sentto == 2) %}
<button type="button" class="btn btn-primary ml-3 {% if c.author.is_muted %}d-none{% endif %}" id="mute-user-{{c.id}}" onclick="adminToggleMute({{c.author_id}}, 1, {{c.id}})">Mute</button>
<button type="button" class="btn btn-primary ml-3 {% if not c.author.is_muted %}d-none{% endif %}" id="unmute-user-{{c.id}}" onclick="adminToggleMute({{c.author_id}}, 0, {{c.id}})">Unmute</button>
<button type="button" class="btn btn-primary ml-3 {% if c.author.is_muted %}d-none{% endif %}" id="mute-user-{{c.id}}" onclick="postToastSwitch(this,'/mute_user/{{c.author.id}}','mute-user-{{c.id}}','unmute-user-{{c.id}}','d-none')">Mute</button>
<button type="button" class="btn btn-primary ml-3 {% if not c.author.is_muted %}d-none{% endif %}" id="unmute-user-{{c.id}}" onclick="postToastSwitch(this,'/unmute_user/{{c.author.id}}','mute-user-{{c.id}}','unmute-user-{{c.id}}','d-none')">Unmute</button>
{% endif %}
<div id="reply-message-{{c.id}}" class="d-none">

View File

@ -46,7 +46,6 @@
<form id="ban-{{deviceType}}" class="my-3 {% if u.is_suspended %}d-none{% endif %}" action="/ban_user/{{u.id}}" method="post" onsubmit="sendFormXHRSwitch(event)">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<input type="hidden" name="redir" value="true">
<input autocomplete="off" style="font-size:11px" type="text" class="form-control" maxlength="256" name="reason" placeholder="Ban Reason" oninput="document.getElementById('user-ban-submit-{{deviceType}}').disabled=false" required>
<input autocomplete="off" style="font-size:11px" type="number" step="any" class="form-control" name="days" placeholder="Days (blank = permanent)">
<div class="custom-control custom-checkbox mb-1">
@ -74,7 +73,6 @@
<form id="agendaposter-{{deviceType}}" class="my-3 {% if u.agendaposter %}d-none{% endif %}" action="/agendaposter/{{u.id}}" method="post" onsubmit="sendFormXHRSwitch(event)">
<input type="hidden" name="formkey", value="{{v.formkey}}">
<input type="hidden" name="redir" value="true">
<input autocomplete="off" type="number" step="any" name="days" class="form-control" placeholder="Days (0 or blank = permanent)">
<input type="submit" onclick="disable(this)" class="btn btn-danger" value="Chud">
</form>
@ -92,8 +90,8 @@
{% endif %}
{% if v.admin_level >= PERMS['USER_BAN'] %}
<button type="button" id="mute-user-{{deviceType}}" class="{% if u.is_muted %}d-none{% endif %} btn btn-danger" onclick="postToastSwitch(this,'/mute_user/{{u.id}}/1','mute-user-{{deviceType}}','unmute-user-{{deviceType}}','d-none')">Mute</button>
<button type="button" id="unmute-user-{{deviceType}}" class="mb-1 {% if not u.is_muted %}d-none{% endif %} btn btn-success" onclick="postToastSwitch(this,'/mute_user/{{u.id}}/0','mute-user-{{deviceType}}','unmute-user-{{deviceType}}','d-none')">Unmute</button>
<button type="button" id="mute-user-{{deviceType}}" class="{% if u.is_muted %}d-none{% endif %} btn btn-danger" onclick="postToastSwitch(this,'/mute_user/{{u.id}}','mute-user-{{deviceType}}','unmute-user-{{deviceType}}','d-none')">Mute</button>
<button type="button" id="unmute-user-{{deviceType}}" class="mb-1 {% if not u.is_muted %}d-none{% endif %} btn btn-success" onclick="postToastSwitch(this,'/unmute_user/{{u.id}}','mute-user-{{deviceType}}','unmute-user-{{deviceType}}','d-none')">Unmute</button>
{% endif %}
{% if v and v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %}
<form action="/admin/unnuke_user" method="post" onsubmit="sendFormXHR(event)">