From 80eedbd58d084ef54fecdfa983953abf2e6005e2 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 23 Oct 2022 18:24:17 +0200 Subject: [PATCH] more approval/removal refactors --- files/assets/js/comments_v.js | 18 ++++++++--- files/assets/js/delete_post_modal.js | 20 ++++++++---- files/assets/js/submission_listing_admin.js | 31 +++++++++++++++++++ files/routes/admin.py | 6 ++-- files/templates/post_actions.html | 10 +++--- .../templates/post_admin_actions_mobile.html | 11 +++---- files/templates/submission_listing.html | 3 ++ 7 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 files/assets/js/submission_listing_admin.js diff --git a/files/assets/js/comments_v.js b/files/assets/js/comments_v.js index 0f358e147..1a00d205d 100644 --- a/files/assets/js/comments_v.js +++ b/files/assets/js/comments_v.js @@ -98,11 +98,19 @@ function delete_commentModal(id) { try {data = JSON.parse(xhr[0].response)} catch(e) {console.log(e)} if (xhr[0].status >= 200 && xhr[0].status < 300 && data && data['message']) { - document.getElementsByClassName(`comment-${id}-only`)[0].classList.add('deleted'); - document.getElementById(`delete-${id}`).classList.add('d-none'); - document.getElementById(`undelete-${id}`).classList.remove('d-none'); - document.getElementById(`delete2-${id}`).classList.add('d-none'); - document.getElementById(`undelete2-${id}`).classList.remove('d-none'); + if (window.location.pathname == '/admin/reported/comments') + { + document.getElementById("post-info-"+id).remove() + document.getElementById("comment-"+id).remove() + } + else + { + document.getElementsByClassName(`comment-${id}-only`)[0].classList.add('deleted'); + document.getElementById(`delete-${id}`).classList.add('d-none'); + document.getElementById(`undelete-${id}`).classList.remove('d-none'); + document.getElementById(`delete2-${id}`).classList.add('d-none'); + document.getElementById(`undelete2-${id}`).classList.remove('d-none'); + } showToast(true, getMessageFromJsonData(true, data)); } else { showToast(false, getMessageFromJsonData(false, data)); diff --git a/files/assets/js/delete_post_modal.js b/files/assets/js/delete_post_modal.js index d059b6e37..16554f16b 100644 --- a/files/assets/js/delete_post_modal.js +++ b/files/assets/js/delete_post_modal.js @@ -8,15 +8,23 @@ function delete_postModal(id) { success = xhr[0].status >= 200 && xhr[0].status < 300; showToast(success, getMessageFromJsonData(success, data)); if (success && data["message"]) { - document.getElementById(`post-${id}`).classList.add('deleted'); - document.getElementById(`delete-${id}`).classList.add('d-none'); - document.getElementById(`undelete-${id}`).classList.remove('d-none'); - document.getElementById(`delete2-${id}`).classList.add('d-none'); - document.getElementById(`undelete2-${id}`).classList.remove('d-none'); + if (window.location.pathname == '/admin/reported/posts') + { + document.getElementById("flaggers-"+id).remove() + document.getElementById("post-"+id).remove() + } + else + { + document.getElementById(`post-${id}`).classList.add('deleted'); + document.getElementById(`delete-${id}`).classList.add('d-none'); + document.getElementById(`undelete-${id}`).classList.remove('d-none'); + document.getElementById(`delete2-${id}`).classList.add('d-none'); + document.getElementById(`undelete2-${id}`).classList.remove('d-none'); + } } else { showToast(false, getMessageFromJsonData(false, data)); } }; xhr[0].send(xhr[1]); }; -} \ No newline at end of file +} diff --git a/files/assets/js/submission_listing_admin.js b/files/assets/js/submission_listing_admin.js new file mode 100644 index 000000000..f85c8e310 --- /dev/null +++ b/files/assets/js/submission_listing_admin.js @@ -0,0 +1,31 @@ +function removePost(t,post_id,button1,button2,cls) { + url="/remove_post/"+post_id + + post_toast(t,url,button1,button2,cls) + + if (window.location.pathname == '/admin/reported/posts') + { + document.getElementById("flaggers-"+post_id).remove() + document.getElementById("post-"+post_id).remove() + } + else + { + document.getElementById("post-"+post_id).classList.add("banned"); + } +}; + +function approvePost(t,post_id,button1,button2,cls) { + url="/approve_post/"+post_id + + post_toast(t,url,button1,button2,cls) + + if (window.location.pathname == '/admin/reported/posts') + { + document.getElementById("flaggers-"+post_id).remove() + document.getElementById("post-"+post_id).remove() + } + else + { + document.getElementById("post-"+post_id).classList.remove("banned"); + } +} diff --git a/files/routes/admin.py b/files/routes/admin.py index c6fcdc867..0af8db88b 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -382,7 +382,8 @@ def reported_posts(v): listing = g.db.query(Submission).filter_by( is_approved=None, - is_banned=False + is_banned=False, + deleted_utc=0 ).join(Submission.flags).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26) listing = [p.id for p in listing] @@ -404,7 +405,8 @@ def reported_comments(v): listing = g.db.query(Comment ).filter_by( is_approved=None, - is_banned=False + is_banned=False, + deleted_utc=0 ).join(Comment.flags).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all() listing = [c.id for c in listing] diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index bd61dc5e0..0a46a53c1 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -61,14 +61,12 @@ {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} - {% if "/reported/" in request.path %} - {% if v.id != p.author.id %}Remove{% endif %} - Approve - {% else %} - {% if v.id != p.author.id %}Remove{% endif %} - Approve + {% if v.id != p.author.id %} + Remove {% endif %} + Approve + {% if p.oauth_app %} API App {% endif %} diff --git a/files/templates/post_admin_actions_mobile.html b/files/templates/post_admin_actions_mobile.html index 0a92ce53c..0e06b1616 100644 --- a/files/templates/post_admin_actions_mobile.html +++ b/files/templates/post_admin_actions_mobile.html @@ -25,13 +25,12 @@ {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} - {% if "/reported/" in request.path %} - - - {% else %} - - + + {% if v.id != p.author.id %} + {% endif %} + + {% endif %} {% if p.oauth_app and v.admin_level >= PERMS['APPS_MODERATION'] %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 5e1327d5c..8240edc4f 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -423,3 +423,6 @@ +{% if v and v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} + +{% endif %}