diff --git a/files/classes/sub_logs.py b/files/classes/sub_logs.py index 30858d3dd..0b3ddc8a4 100644 --- a/files/classes/sub_logs.py +++ b/files/classes/sub_logs.py @@ -184,5 +184,25 @@ ACTIONTYPES = { "str": 'disabled stealth mode', "icon": 'fa-user-ninja', "color": 'bg-muted' - } -} \ No newline at end of file + }, + 'set_nsfw': { + "str": 'set nsfw on post {self.target_link}', + "icon": 'fa-eye-evil', + "color": 'bg-danger' + }, + 'unset_nsfw': { + "str": 'un-set nsfw on post {self.target_link}', + "icon": 'fa-eye-evil', + "color": 'bg-success' + }, + 'set_nsfw_comment': { + "str": 'set nsfw on a {self.target_link}', + "icon": 'fa-eye-evil', + "color": 'bg-danger' + }, + 'unset_nsfw_comment': { + "str": 'un-set nsfw on a {self.target_link}', + "icon": 'fa-eye-evil', + "color": 'bg-success' + }, +} diff --git a/files/routes/comments.py b/files/routes/comments.py index a1197f7b7..666059d5f 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -907,3 +907,38 @@ def handle_wordle_action(cid, v): g.db.add(comment) return {"response" : comment.wordle_html(v)} + + +@app.post("/toggle_comment_nsfw/") +@auth_required +def toggle_comment_nsfw(cid, v): + comment = get_comment(cid) + + if comment.author_id != v.id and not v.admin_level > 1 and not (comment.post.sub and v.mods(comment.post.sub)): + abort(403) + + if comment.over_18 and v.is_suspended_permanently: + abort(403) + + comment.over_18 = not comment.over_18 + g.db.add(comment) + + if comment.author_id != v.id: + if v.admin_level > 2: + ma = ModAction( + kind = "set_nsfw_comment" if comment.over_18 else "unset_nsfw_comment", + user_id = v.id, + target_comment_id = comment.id, + ) + g.db.add(ma) + else: + ma = SubAction( + sub = comment.post.sub, + kind = "set_nsfw_comment" if comment.over_18 else "unset_nsfw_comment", + user_id = v.id, + target_comment_id = comment.id, + ) + g.db.add(ma) + + if comment.over_18: return {"message": "Comment has been marked as +18!"} + else: return {"message": "Comment has been unmarked as +18!"} diff --git a/files/routes/posts.py b/files/routes/posts.py index 02427f9a3..7a296d17b 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1104,31 +1104,6 @@ def undelete_post_pid(pid, v): return {"message": "Post undeleted!"} -@app.post("/toggle_comment_nsfw/") -@auth_required -def toggle_comment_nsfw(cid, v): - comment = get_comment(cid) - - if comment.author_id != v.id and not v.admin_level > 1 and not (comment.post.sub and v.mods(comment.post.sub)): - abort(403) - - if comment.over_18 and v.is_suspended_permanently: - abort(403) - - comment.over_18 = not comment.over_18 - g.db.add(comment) - - if comment.author_id != v.id: - ma = ModAction( - kind = "set_nsfw_comment" if comment.over_18 else "unset_nsfw_comment", - user_id = v.id, - target_comment_id = comment.id, - ) - g.db.add(ma) - - if comment.over_18: return {"message": "Comment has been marked as +18!"} - else: return {"message": "Comment has been unmarked as +18!"} - @app.post("/toggle_post_nsfw/") @auth_required def toggle_post_nsfw(pid, v): @@ -1144,12 +1119,21 @@ def toggle_post_nsfw(pid, v): g.db.add(post) if post.author_id != v.id: - ma = ModAction( - kind = "set_nsfw" if post.over_18 else "unset_nsfw", - user_id = v.id, - target_submission_id = post.id, + if v.admin_level > 2: + ma = ModAction( + kind = "set_nsfw" if post.over_18 else "unset_nsfw", + user_id = v.id, + target_submission_id = post.id, ) - g.db.add(ma) + g.db.add(ma) + else: + ma = SubAction( + sub = post.sub, + kind = "set_nsfw" if post.over_18 else "unset_nsfw", + user_id = v.id, + target_submission_id = post.id, + ) + g.db.add(ma) if post.over_18: return {"message": "Post has been marked as +18!"} else: return {"message": "Post has been unmarked as +18!"}