diff --git a/files/classes/mod_logs.py b/files/classes/mod_logs.py index ee18fe9030..b5e3403fb3 100644 --- a/files/classes/mod_logs.py +++ b/files/classes/mod_logs.py @@ -339,6 +339,11 @@ ACTIONTYPES = { "icon": 'fa-eye-evil', "color": 'bg-danger' }, + 'set_nsfw_comment': { + "str": 'set nsfw on a {self.target_link}', + "icon": 'fa-eye-evil', + "color": 'bg-danger' + }, 'shadowban': { "str": 'shadowbanned {self.target_link}', "icon": 'fa-eye-slash', @@ -404,6 +409,11 @@ ACTIONTYPES = { "icon": 'fa-eye-evil', "color": 'bg-success' }, + 'unset_nsfw_comment': { + "str": 'un-set nsfw on a {self.target_link}', + "icon": 'fa-eye-evil', + "color": 'bg-success' + }, 'unshadowban': { "str": 'unshadowbanned {self.target_link}', "icon": 'fa-eye', diff --git a/files/routes/posts.py b/files/routes/posts.py index 3daacbaa55..2600135fd8 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1434,12 +1434,21 @@ def undelete_post_pid(pid, v): @app.post("/toggle_comment_nsfw/") @auth_required def toggle_comment_nsfw(cid, v): - comment = g.db.query(Comment).filter_by(id=cid).one_or_none() - if comment.author_id != v.id and not v.admin_level > 1: abort(403) + + if comment.author_id != v.id and not v.admin_level > 1: + 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) g.db.commit() if comment.over_18: return {"message": "Comment has been marked as +18!"} @@ -1448,7 +1457,6 @@ def toggle_comment_nsfw(cid, v): @app.post("/toggle_post_nsfw/") @auth_required def toggle_post_nsfw(pid, v): - post = get_post(pid) if post.author_id != v.id and not v.admin_level > 1: @@ -1457,14 +1465,13 @@ def toggle_post_nsfw(pid, v): post.over_18 = not post.over_18 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 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, + ) g.db.add(ma) - g.db.commit() if post.over_18: return {"message": "Post has been marked as +18!"}