From 2525db6b078fb2b6d1104fbc94ec9f70d0085093 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 10 Dec 2022 16:47:20 +0200 Subject: [PATCH] give ppl a notif when janny toggles nsfw on their posts --- files/routes/posts.py | 48 ++++++++++++++++--- files/templates/post_actions.html | 4 +- files/templates/post_actions_mobile.html | 4 +- .../templates/post_admin_actions_mobile.html | 4 +- 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 0fe1a55cb..c67107e59 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -876,9 +876,9 @@ def undelete_post_pid(pid, v): return {"message": "Post undeleted!"} -@app.post("/toggle_post_nsfw/") +@app.post("/mark_post_nsfw/") @auth_required -def toggle_post_nsfw(pid, v): +def mark_post_nsfw(pid, v): post = get_post(pid) if post.author_id != v.id and not v.admin_level >= PERMS['POST_COMMENT_MODERATION'] and not (post.sub and v.mods(post.sub)): @@ -887,13 +887,13 @@ def toggle_post_nsfw(pid, v): if post.over_18 and v.is_suspended_permanently: abort(403) - post.over_18 = not post.over_18 + post.over_18 = True g.db.add(post) if post.author_id != v.id: if v.admin_level >= PERMS['POST_COMMENT_MODERATION']: ma = ModAction( - kind = "set_nsfw" if post.over_18 else "unset_nsfw", + kind = "set_nsfw", user_id = v.id, target_submission_id = post.id, ) @@ -901,14 +901,48 @@ def toggle_post_nsfw(pid, v): else: ma = SubAction( sub = post.sub, - kind = "set_nsfw" if post.over_18 else "unset_nsfw", + kind = "set_nsfw", user_id = v.id, target_submission_id = post.id, ) g.db.add(ma) + send_repeatable_notification(post.author_id, f"@{v.username} (Admin) has marked [{post.title}](/post/{post.id}) as +18") - if post.over_18: return {"message": "Post has been marked as +18!"} - else: return {"message": "Post has been unmarked as +18!"} + return {"message": "Post has been marked as +18!"} + +@app.post("/unmark_post_nsfw/") +@auth_required +def unmark_post_nsfw(pid, v): + post = get_post(pid) + + if post.author_id != v.id and not v.admin_level >= PERMS['POST_COMMENT_MODERATION'] and not (post.sub and v.mods(post.sub)): + abort(403) + + if post.over_18 and v.is_suspended_permanently: + abort(403) + + post.over_18 = False + g.db.add(post) + + if post.author_id != v.id: + if v.admin_level >= PERMS['POST_COMMENT_MODERATION']: + ma = ModAction( + kind = "unset_nsfw", + user_id = v.id, + target_submission_id = post.id, + ) + g.db.add(ma) + else: + ma = SubAction( + sub = post.sub, + kind = "unset_nsfw", + user_id = v.id, + target_submission_id = post.id, + ) + g.db.add(ma) + send_repeatable_notification(post.author_id, f"@{v.username} (Admin) has unmarked [{post.title}](/post/{post.id}) as +18") + + return {"message": "Post has been unmarked as +18!"} @app.post("/save_post/") @limiter.limit(DEFAULT_RATELIMIT_SLOWER) diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index 80647b9d3..5b4e13099 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -73,8 +73,8 @@ {% endif %} {% endif %} {% if v.id==p.author_id or v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (p.sub and v.mods(p.sub)) %} - - + + {% endif %} {% if v.admin_level >= PERMS['USER_BAN'] and v.id != p.author_id %} diff --git a/files/templates/post_actions_mobile.html b/files/templates/post_actions_mobile.html index 8fa7f8edd..467ae22c7 100644 --- a/files/templates/post_actions_mobile.html +++ b/files/templates/post_actions_mobile.html @@ -50,8 +50,8 @@ {% endif %} {% if v.id==p.author_id or (p.sub and v.mods(p.sub)) %} - - + + {% endif %} {% if p.sub and v.mods(p.sub) %} diff --git a/files/templates/post_admin_actions_mobile.html b/files/templates/post_admin_actions_mobile.html index b78eca81e..a6f6a72cc 100644 --- a/files/templates/post_admin_actions_mobile.html +++ b/files/templates/post_admin_actions_mobile.html @@ -33,8 +33,8 @@ {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} - - + + {% endif %} {% if v.id != p.author_id and v.admin_level >= PERMS['USER_BAN'] %}