From 4a14e50c9f04cdfceabd36c20739a5b9e0435f57 Mon Sep 17 00:00:00 2001 From: Aevann Date: Mon, 12 Feb 2024 21:34:15 +0200 Subject: [PATCH] add buttons to add and remove child warning --- files/helpers/config/modaction_types.py | 10 ++++ files/routes/posts.py | 53 +++++++++++++++++++ files/templates/post_actions.html | 25 +++++++-- files/templates/post_actions_mobile.html | 13 +++-- .../templates/post_admin_actions_mobile.html | 20 +++++-- 5 files changed, 112 insertions(+), 9 deletions(-) diff --git a/files/helpers/config/modaction_types.py b/files/helpers/config/modaction_types.py index 0ecfd18e0..9bdf0f7eb 100644 --- a/files/helpers/config/modaction_types.py +++ b/files/helpers/config/modaction_types.py @@ -281,6 +281,16 @@ MODACTION_TYPES = { "icon": 'fa-robot', "color": 'bg-muted' }, + 'set_cw': { + "str": 'added child warning to {self.target_link}', + "icon": 'fa-eye-evil', + "color": 'bg-danger' + }, + 'unset_cw': { + "str": 'removed child warning from {self.target_link}', + "icon": 'fa-eye-evil', + "color": 'bg-success' + }, 'set_flair_locked': { "str": "set {self.target_link}'s flair (locked)", "icon": 'fa-award', diff --git a/files/routes/posts.py b/files/routes/posts.py index 6fdfe3c76..120e4dfbd 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1075,3 +1075,56 @@ def edit_post(pid, v): g.db.add(ma) return {"message": "Post edited successfully!"} + +if SITE_NAME == 'WPD': + @app.post("/mark_post_cw/") + @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 mark_post_cw(pid, v): + p = get_post(pid) + + if p.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION']: + abort(403) + + p.cw = True + g.db.add(p) + + if p.author_id != v.id: + ma = ModAction( + kind = "set_cw", + user_id = v.id, + target_post_id = p.id, + ) + g.db.add(ma) + send_repeatable_notification(p.author_id, f"@{v.username} (a site admin) has add a child warning to [{p.title}](/post/{p.id})") + + return {"message": "A child warning has been added to the post!"} + + @app.post("/unmark_post_cw/") + @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 unmark_post_cw(pid, v): + p = get_post(pid) + + if p.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION']: + abort(403) + + p.cw = False + g.db.add(p) + + if p.author_id != v.id: + ma = ModAction( + kind = "unset_cw", + user_id = v.id, + target_post_id = p.id, + ) + g.db.add(ma) + 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!"} diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index 6d150ecee..e9a8019e5 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -48,30 +48,37 @@ {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] and p.oauth_app %} API App {% endif %} + {% if v.can_edit(p) %} {% endif %} + {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %} {% endif %} + {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} {% endif %} + {% if p.hole and v.mods_hole(p.hole) %} {% endif %} + {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} {% endif %} + {% if v.id != p.author_id and not p.ghost %} {% endif %} + {% if p.hole and v.mods_hole(p.hole) %} {% if not p.author.mods_hole(p.hole) %} @@ -79,23 +86,35 @@ {% endif %} {% endif %} - {% if FEATURES['NSFW_MARKING'] and (v.id == p.author_id or v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (p.hole and v.mods_hole(p.hole))) %} - - + + {% if (v.id == p.author_id or v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (p.hole and v.mods_hole(p.hole))) %} + {% if FEATURES['NSFW_MARKING'] %} + + + {% endif %} + + {% if SITE_NAME == 'WPD' %} + + + {% endif %} {% endif %} + {% if v.admin_level >= PERMS['MARK_EFFORTPOST'] %} {% endif %} + {% if v.admin_level >= PERMS['PROGSTACK'] %} {% endif %} + {% if v.admin_level >= PERMS['USER_BAN'] and v.id != p.author_id %} {% endif %} + {% if v.admin_level >= PERMS['USER_CHUD'] and v.id != p.author_id %} diff --git a/files/templates/post_actions_mobile.html b/files/templates/post_actions_mobile.html index c363da43c..0ddcb83a3 100644 --- a/files/templates/post_actions_mobile.html +++ b/files/templates/post_actions_mobile.html @@ -50,9 +50,16 @@ {% endif %} {% endif %} -{% if FEATURES['NSFW_MARKING'] and (v.id == p.author_id or (p.hole and v.mods_hole(p.hole))) %} - - +{% if v.id == p.author_id or (p.hole and v.mods_hole(p.hole)) %} + {% if FEATURES['NSFW_MARKING'] %} + + + {% endif %} + + {% if SITE_NAME == 'WPD' %} + + + {% endif %} {% endif %} {% if p.hole and v.mods_hole(p.hole) %} diff --git a/files/templates/post_admin_actions_mobile.html b/files/templates/post_admin_actions_mobile.html index fcf2b3783..d7ba70842 100644 --- a/files/templates/post_admin_actions_mobile.html +++ b/files/templates/post_admin_actions_mobile.html @@ -21,11 +21,13 @@ {% endif %} + {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %} {% endif %} + {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} @@ -33,23 +35,35 @@ {% endif %} - {% if FEATURES['NSFW_MARKING'] and v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} - - + + {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} + {% if FEATURES['NSFW_MARKING'] %} + + + {% endif %} + + {% if SITE_NAME == 'WPD' %} + + + {% endif %} {% endif %} + {% if v.admin_level >= PERMS['MARK_EFFORTPOST'] %} {% endif %} + {% if v.admin_level >= PERMS['PROGSTACK'] %} {% endif %} + {% if v.id != p.author_id and v.admin_level >= PERMS['USER_BAN'] %} {% endif %} + {% if v.id != p.author_id and v.admin_level >= PERMS['USER_CHUD'] %}