From 2cf2d869de1119ce18c4d948b44f08906b674ded Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 17 Mar 2023 16:37:13 +0200 Subject: [PATCH] refactor banning and chudding on posts/comments --- files/assets/js/admin/punish_modal.js | 32 +++++++++ files/assets/js/ban_modal.js | 43 ------------ files/routes/admin.py | 4 +- files/templates/comments.html | 22 ++++--- files/templates/modals/ban.html | 66 ------------------- files/templates/modals/punish.html | 57 ++++++++++++++++ files/templates/post_actions.html | 10 +-- .../templates/post_admin_actions_mobile.html | 10 +-- files/templates/submission_listing.html | 2 +- files/templates/userpage/admintools.html | 4 +- 10 files changed, 119 insertions(+), 131 deletions(-) create mode 100644 files/assets/js/admin/punish_modal.js delete mode 100644 files/assets/js/ban_modal.js delete mode 100644 files/templates/modals/ban.html create mode 100644 files/templates/modals/punish.html diff --git a/files/assets/js/admin/punish_modal.js b/files/assets/js/admin/punish_modal.js new file mode 100644 index 000000000..26a171f1f --- /dev/null +++ b/files/assets/js/admin/punish_modal.js @@ -0,0 +1,32 @@ +function punishModal(t, kind, link, name, fullname) { + const kind_title = kind.charAt(0).toUpperCase() + kind.slice(1) + + document.getElementById(`${kind}ModalTitle`).innerHTML = `${kind_title} @${name}`; + document.getElementById(`${kind}_reason`).value = link; + + const btn = document.getElementById(`${kind}UserButton`) + btn.innerHTML = `${kind_title} @${name}`; + + btn.onclick = () => { + const values = { + "days": document.getElementById(`${kind}_days`).value, + "reason": document.getElementById(`${kind}_reason`).value + } + + if (kind == "ban") { + values["alts"] = document.getElementById(`${kind}_alts`).value; + } + + postToast(t, `/${kind}_user/${fullname}`, + values, + () => { + document.getElementById(`un${kind}-${fullname}`).classList.remove("d-none"); + document.getElementById(`un${kind}2-${fullname}`).classList.remove("d-none"); + const days = document.getElementById(`${kind}_days`).value + if (!days) { + t.classList.add("d-none") + } + } + ); + } +} diff --git a/files/assets/js/ban_modal.js b/files/assets/js/ban_modal.js deleted file mode 100644 index 2f8dab8c2..000000000 --- a/files/assets/js/ban_modal.js +++ /dev/null @@ -1,43 +0,0 @@ -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").addEventListener('click', function() { - let form = new FormData(document.getElementById("banModalForm")); - const xhr = createXhrWithFormKey(`/ban_user/${fullname}?form`, "POST", form); - xhr[0].onload = function() { - let data - try {data = JSON.parse(xhr[0].response)} - catch(e) {console.error(e)} - success = xhr[0].status >= 200 && xhr[0].status < 300; - showToast(success, getMessageFromJsonData(success, data)); - document.getElementById(`unban-${fullname}`).classList.toggle(cls); - document.getElementById(`unban2-${fullname}`).classList.toggle(cls); - }; - - xhr[0].send(xhr[1]); - }) -} - -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").addEventListener('click', function() { - let form = new FormData(document.getElementById("chudModalForm")); - const xhr = createXhrWithFormKey(`/agendaposter/${fullname}?form`, "POST", form); - xhr[0].onload = function() { - let data - try {data = JSON.parse(xhr[0].response)} - catch(e) {console.error(e)} - success = xhr[0].status >= 200 && xhr[0].status < 300; - showToast(success, getMessageFromJsonData(success, data)); - document.getElementById(`unchud-${fullname}`).classList.toggle(cls); - document.getElementById(`unchud2-${fullname}`).classList.toggle(cls); - }; - - xhr[0].send(xhr[1]); - }) -} diff --git a/files/routes/admin.py b/files/routes/admin.py index 870aaba31..66b91c917 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -751,7 +751,7 @@ def admin_removed_comments(v): next_exists=next_exists ) -@app.post("/unagendaposter/") +@app.post("/unchud_user/") @limiter.limit('1/second', scope=rpath) @limiter.limit(DEFAULT_RATELIMIT) @limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) @@ -995,7 +995,7 @@ def ban_user(id, v): return {"message": f"@{user.username} has been banned {duration}!"} -@app.post("/agendaposter/") +@app.post("/chud_user/") @limiter.limit('1/second', scope=rpath) @limiter.limit(DEFAULT_RATELIMIT) @limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) diff --git a/files/templates/comments.html b/files/templates/comments.html index 35a99f962..b772ec15c 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -480,13 +480,15 @@ {% 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 %} @@ -693,13 +695,15 @@ {% 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'] %} @@ -728,7 +732,7 @@ {% include "modals/gif.html" %} {% include "modals/emoji.html" %} {% if v.admin_level >= PERMS['USER_BAN'] %} - {% include "modals/ban.html" %} + {% include "modals/punish.html" %} {% endif %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index f03de852f..bd9dd2b64 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -284,7 +284,7 @@ {% include "modals/delete_post.html" %} {% include "modals/report_post.html" %} {% if v.admin_level >= PERMS['USER_BAN'] %} - {% include "modals/ban.html" %} + {% include "modals/punish.html" %} {% endif %} {% endif %} diff --git a/files/templates/userpage/admintools.html b/files/templates/userpage/admintools.html index 86bd28134..0ea2fdc7f 100644 --- a/files/templates/userpage/admintools.html +++ b/files/templates/userpage/admintools.html @@ -65,9 +65,9 @@ {% endif %} {% if v.admin_level >= PERMS['USER_AGENDAPOSTER'] %} - + -
+