diff --git a/files/assets/js/ban_modal.js b/files/assets/js/ban_modal.js index 300a385ee5..ec01732d20 100644 --- a/files/assets/js/ban_modal.js +++ b/files/assets/js/ban_modal.js @@ -1,11 +1,11 @@ -function banModal(link, id, name, fullname, cls) { +function banModal(link, name, fullname, cls) { document.getElementById("banModalTitle").innerHTML = `Ban @${name}`; document.getElementById("ban-modal-link").value = link; document.getElementById("banUserButton").innerHTML = `Ban @${name}`; document.getElementById("banUserButton").onclick = function() { let form = new FormData(document.getElementById("banModalForm")); - const xhr = createXhrWithFormKey(`/ban_user/${id}?form`, "POST", form); + const xhr = createXhrWithFormKey(`/ban_user/${fullname}?form`, "POST", form); xhr[0].onload = function() { let data try {data = JSON.parse(xhr[0].response)} @@ -22,14 +22,14 @@ function banModal(link, id, name, fullname, cls) { } } -function chudModal(link, id, name, fullname, cls) { +function chudModal(link, name, fullname, cls) { document.getElementById("chudModalTitle").innerHTML = `Chud @${name}`; document.getElementById("chud-modal-link").value = link; document.getElementById("chudUserButton").innerHTML = `Chud @${name}`; document.getElementById("chudUserButton").onclick = function() { let form = new FormData(document.getElementById("chudModalForm")); - const xhr = createXhrWithFormKey(`/agendaposter/${id}?form`, "POST", form); + const xhr = createXhrWithFormKey(`/agendaposter/${fullname}?form`, "POST", form); xhr[0].onload = function() { let data try {data = JSON.parse(xhr[0].response)} diff --git a/files/routes/admin.py b/files/routes/admin.py index 8d7800cf43..9c756a1239 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -864,10 +864,20 @@ def admin_removed_comments(v): next_exists=next_exists ) -@app.post("/unagendaposter/") +@app.post("/unagendaposter/") @admin_level_required(PERMS['USER_AGENDAPOSTER']) -def unagendaposter(user_id, v): - user = get_account(user_id) +def unagendaposter(id, v): + + if id.startswith('p_'): + post_id = id.split('p_')[1] + post = g.db.get(Submission, post_id) + user = post.author + elif id.startswith('c_'): + comment_id = id.split('c_')[1] + comment = g.db.get(Comment, comment_id) + user = comment.author + else: + user = get_account(id) if not user.chudded_by: abort(403, "Jannies can't undo chud awards anymore!") @@ -983,11 +993,21 @@ def admin_title_change(user_id, v): return {"message": f"@{user.username}'s flair has been changed!"} -@app.post("/ban_user/") +@app.post("/ban_user/") @limiter.limit(DEFAULT_RATELIMIT_SLOWER) @admin_level_required(PERMS['USER_BAN']) -def ban_user(user_id, v): - user = get_account(user_id) +def ban_user(id, v): + + if id.startswith('p_'): + post_id = id.split('p_')[1] + post = g.db.get(Submission, post_id) + user = post.author + elif id.startswith('c_'): + comment_id = id.split('c_')[1] + comment = g.db.get(Comment, comment_id) + user = comment.author + else: + user = get_account(id) if user.admin_level > v.admin_level: abort(403) @@ -1055,10 +1075,20 @@ def ban_user(user_id, v): return {"message": f"@{user.username} has been banned {duration}!"} -@app.post("/agendaposter/") +@app.post("/agendaposter/") @admin_level_required(PERMS['USER_AGENDAPOSTER']) -def agendaposter(user_id, v): - user = get_account(user_id) +def agendaposter(id, v): + + if id.startswith('p_'): + post_id = id.split('p_')[1] + post = g.db.get(Submission, post_id) + user = post.author + elif id.startswith('c_'): + comment_id = id.split('c_')[1] + comment = g.db.get(Comment, comment_id) + user = comment.author + else: + user = get_account(id) if user.admin_level > v.admin_level: abort(403) @@ -1128,11 +1158,22 @@ def agendaposter(user_id, v): return {"message": f"@{user.username} has been chudded {duration}!"} -@app.post("/unban_user/") +@app.post("/unban_user/") @limiter.limit(DEFAULT_RATELIMIT_SLOWER) @admin_level_required(PERMS['USER_BAN']) -def unban_user(user_id, v): - user = get_account(user_id) +def unban_user(id, v): + + if id.startswith('p_'): + post_id = id.split('p_')[1] + post = g.db.get(Submission, post_id) + user = post.author + elif id.startswith('c_'): + comment_id = id.split('c_')[1] + comment = g.db.get(Comment, comment_id) + user = comment.author + else: + user = get_account(id) + if not user.is_banned: abort(400) diff --git a/files/templates/comments.html b/files/templates/comments.html index d88de2af6c..d16eaa9a26 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -464,13 +464,13 @@ {% endif %} {% if v.admin_level >= PERMS['USER_BAN'] and v.id != c.author_id %} - - + + {% endif %} {% if v.admin_level >= PERMS['USER_AGENDAPOSTER'] and v.id != c.author_id %} - - + + {% endif %} @@ -658,13 +658,13 @@ {% endif %} {% if v.id != c.author_id and v.admin_level >= PERMS['USER_BAN'] %} - - + + {% endif %} {% if v.id != c.author_id and v.admin_level >= PERMS['USER_AGENDAPOSTER'] %} - - + + {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index 3dd3b698e1..db797528d6 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -79,12 +79,12 @@ {% endif %} {% if v.admin_level >= PERMS['USER_BAN'] and v.id != p.author_id %} - - + + {% endif %} {% if v.admin_level >= PERMS['USER_AGENDAPOSTER'] and v.id != p.author_id %} - - + + {% endif %} {% endif %} diff --git a/files/templates/post_admin_actions_mobile.html b/files/templates/post_admin_actions_mobile.html index 54f4f118e6..d144b29dcb 100644 --- a/files/templates/post_admin_actions_mobile.html +++ b/files/templates/post_admin_actions_mobile.html @@ -37,13 +37,13 @@ {% endif %} {% if v.id != p.author_id and v.admin_level >= PERMS['USER_BAN'] %} - - + + {% endif %} {% if v.id != p.author_id and v.admin_level >= PERMS['USER_AGENDAPOSTER'] %} - - + + {% endif %}