From 3e3d39e432205e68174244f1f357dda63d2f988c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 10 Dec 2022 16:57:19 +0200 Subject: [PATCH] minor /set_new rework --- files/classes/mod_logs.py | 10 +++++ files/routes/posts.py | 39 +++++++++++++++++-- files/templates/post_actions.html | 2 +- .../templates/post_admin_actions_mobile.html | 2 +- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/files/classes/mod_logs.py b/files/classes/mod_logs.py index a7ef59a70..bdc7fe068 100644 --- a/files/classes/mod_logs.py +++ b/files/classes/mod_logs.py @@ -313,6 +313,16 @@ ACTIONTYPES = { "icon": 'fa-award', "color": 'bg-primary' }, + 'set_new': { + "str": 'changed the default sorting of comments on {self.target_link} to `new`', + "icon": 'fa-sparkles', + "color": 'bg-primary' + }, + 'set_hot': { + "str": 'changed the default sorting of comments on {self.target_link} to `hot`', + "icon": 'fa-fire', + "color": 'bg-primary' + }, 'set_nsfw': { "str": 'set {self.target_link} as +18', "icon": 'fa-eye-evil', diff --git a/files/routes/posts.py b/files/routes/posts.py index c67107e59..bff42facc 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -988,15 +988,46 @@ def pin_post(post_id, v): else: return {"message": "Post unpinned!"} return abort(404, "Post not found!") -@app.route("/post//new", methods=["PUT", "DELETE"]) +@app.put("/post//new") @limiter.limit(DEFAULT_RATELIMIT_SLOWER) @auth_required -def toggle_new_sort(post_id:int, v:User): +def set_new_sort(post_id:int, v:User): post = get_post(post_id) if not v.can_edit(post): abort(403, "Only the post author can do that!") - post.new = request.method == "PUT" + post.new = True g.db.add(post) - return {"message": f"Turned {'on' if post.new else 'off'} sort by new"} + + if v.id != post.author_id: + ma = ModAction( + kind = "set_new", + user_id = v.id, + target_submission_id = post.id, + ) + g.db.add(ma) + send_repeatable_notification(post.author_id, f"@{v.username} (Admin) has changed the the default sorting of comments on [{post.title}](/post/{post.id}) to `new`") + + return {"message": f"Changed the the default sorting of comments on this post to 'new'"} + + +@app.delete("/post//new") +@limiter.limit(DEFAULT_RATELIMIT_SLOWER) +@auth_required +def unset_new_sort(post_id:int, v:User): + post = get_post(post_id) + if not v.can_edit(post): abort(403, "Only the post author can do that!") + post.new = None + g.db.add(post) + + if v.id != post.author_id: + ma = ModAction( + kind = "set_hot", + user_id = v.id, + target_submission_id = post.id, + ) + g.db.add(ma) + send_repeatable_notification(post.author_id, f"@{v.username} (Admin) has changed the the default sorting of comments on [{post.title}](/post/{post.id}) to `hot`") + + return {"message": f"Changed the the default sorting of comments on this post to 'hot'"} extensions = IMAGE_FORMATS + VIDEO_FORMATS + AUDIO_FORMATS diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index 5b4e13099..b8f56602b 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -43,7 +43,7 @@ {% endif %} {% if v.can_edit(p) %} - + {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %} diff --git a/files/templates/post_admin_actions_mobile.html b/files/templates/post_admin_actions_mobile.html index a6f6a72cc..35f7f4924 100644 --- a/files/templates/post_admin_actions_mobile.html +++ b/files/templates/post_admin_actions_mobile.html @@ -19,7 +19,7 @@ {% if v.can_edit(p) %} - + {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] and (v.id == p.author.id or v.admin_level >= PERMS['POST_COMMENT_MODERATION']) %}