From 892137f23bd41fada5f36a83bc08484e89106df0 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 16 Feb 2024 14:49:26 +0200 Subject: [PATCH] do this https://rdrama.net/h/countryclub/post/79285/-/4426657#context --- files/routes/admin.py | 60 ------------------- files/routes/comments.py | 33 ++++++++++ files/routes/posts.py | 33 ++++++++++ files/templates/comments.html | 4 +- files/templates/post_actions.html | 2 +- .../templates/post_admin_actions_mobile.html | 2 +- 6 files changed, 70 insertions(+), 64 deletions(-) diff --git a/files/routes/admin.py b/files/routes/admin.py index 2766195e7..8a2ec0bdf 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1442,36 +1442,6 @@ def approve_post(post_id, v): return {"message": "Post approved!"} -@app.post("/distinguish/") -@limiter.limit('1/second', scope=rpath) -@limiter.limit('1/second', scope=rpath, key_func=get_ID) -@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) -@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) -@admin_level_required(PERMS['POST_COMMENT_DISTINGUISH']) -def distinguish_post(post_id, v): - post = get_post(post_id) - - if post.distinguished: - post.distinguished = False - kind = 'undistinguish_post' - else: - post.distinguished = True - kind = 'distinguish_post' - - g.db.add(post) - - ma = ModAction( - kind=kind, - user_id=v.id, - target_post_id=post.id - ) - g.db.add(ma) - - - if post.distinguished: return {"message": "Post distinguished!"} - else: return {"message": "Post undistinguished!"} - - @app.post("/sticky/") @feature_required('PINS') @limiter.limit('1/second', scope=rpath) @@ -1676,36 +1646,6 @@ def approve_comment(c_id, v): return {"message": "Comment approved!"} - -@app.post("/distinguish_comment/") -@limiter.limit('1/second', scope=rpath) -@limiter.limit('1/second', scope=rpath, key_func=get_ID) -@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) -@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) -@admin_level_required(PERMS['POST_COMMENT_DISTINGUISH']) -def admin_distinguish_comment(c_id, v): - comment = get_comment(c_id, v=v) - - if comment.distinguished: - comment.distinguished = False - kind = 'undistinguish_comment' - else: - comment.distinguished = True - kind = 'distinguish_comment' - - g.db.add(comment) - - ma = ModAction( - kind=kind, - user_id=v.id, - target_comment_id=comment.id - ) - g.db.add(ma) - - - if comment.distinguished: return {"message": "Comment distinguished!"} - else: return {"message": "Comment undistinguished!"} - @app.get("/admin/banned_domains/") @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) diff --git a/files/routes/comments.py b/files/routes/comments.py index 7e53c0f96..fdc4ef8c2 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -782,3 +782,36 @@ def postprocess_comment(comment_body, comment_body_html, cid): g.db.close() stdout.flush() + + +@app.post("/distinguish_comment/") +@limiter.limit('1/second', scope=rpath) +@limiter.limit('1/second', scope=rpath, key_func=get_ID) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) +@auth_required +def admin_distinguish_comment(c_id, v): + comment = get_comment(c_id, v=v) + + if v.admin_level < PERMS['POST_COMMENT_DISTINGUISH'] and not (comment.parent_post and v.mods_hole(comment.post.hole)): + abort(403, "You can't distinguish this comment") + + if comment.distinguished: + comment.distinguished = False + kind = 'undistinguish_comment' + else: + comment.distinguished = True + kind = 'distinguish_comment' + + g.db.add(comment) + + ma = ModAction( + kind=kind, + user_id=v.id, + target_comment_id=comment.id + ) + g.db.add(ma) + + + if comment.distinguished: return {"message": "Comment distinguished!"} + else: return {"message": "Comment undistinguished!"} diff --git a/files/routes/posts.py b/files/routes/posts.py index bbf6b674a..c66d88aed 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1148,3 +1148,36 @@ if SITE_NAME == 'WPD': send_repeatable_notification(p.author_id, f"@{v.username} (a site admin) has removed the child warning from [{p.title}](/post/{p.id})") return {"message": "The child warning has been removed from the post!"} + + +@app.post("/distinguish/") +@limiter.limit('1/second', scope=rpath) +@limiter.limit('1/second', scope=rpath, key_func=get_ID) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) +@auth_required +def distinguish_post(post_id, v): + post = get_post(post_id) + + if v.admin_level < PERMS['POST_COMMENT_DISTINGUISH'] and not v.mods_hole(post.hole): + abort(403, "You can't distinguish this post") + + if post.distinguished: + post.distinguished = False + kind = 'undistinguish_post' + else: + post.distinguished = True + kind = 'distinguish_post' + + g.db.add(post) + + ma = ModAction( + kind=kind, + user_id=v.id, + target_post_id=post.id + ) + g.db.add(ma) + + + if post.distinguished: return {"message": "Post distinguished!"} + else: return {"message": "Post undistinguished!"} diff --git a/files/templates/comments.html b/files/templates/comments.html index c47b330d6..2497f87a6 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -421,7 +421,7 @@ API App {% endif %} - {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %} + {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] or (c.parent_post and v.mods_hole(c.post.hole)) %} @@ -687,7 +687,7 @@ {% endif %} - {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %} + {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] or (c.parent_post and v.mods_hole(c.post.hole)) %} {% endif %} diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index 8ef355fa7..eaa8b8ce4 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -58,7 +58,7 @@ {% endif %} - {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %} + {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] or v.mods_hole(p.hole) %} {% endif %} diff --git a/files/templates/post_admin_actions_mobile.html b/files/templates/post_admin_actions_mobile.html index 121dd8fce..d76c54425 100644 --- a/files/templates/post_admin_actions_mobile.html +++ b/files/templates/post_admin_actions_mobile.html @@ -22,7 +22,7 @@ {% endif %} - {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %} + {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] or v.mods_hole(p.hole) %}