From 04cce6ec9d79cc66aa32b1ef7dc102230f9c9a9c Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:03:16 +1300 Subject: [PATCH] ban posts or comments - ui --- app/admin/forms.py | 2 ++ app/admin/routes.py | 4 ++++ app/community/routes.py | 2 +- app/models.py | 3 +++ app/post/routes.py | 2 +- app/templates/admin/edit_user.html | 2 ++ app/templates/admin/users.html | 4 +++- 7 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/admin/forms.py b/app/admin/forms.py index 34ca898c..d23943a8 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -208,6 +208,8 @@ class EditUserForm(FlaskForm): bot = BooleanField(_l('This profile is a bot')) verified = BooleanField(_l('Email address is verified')) banned = BooleanField(_l('Banned')) + ban_posts = BooleanField(_l('Ban posts')) + ban_comments = BooleanField(_l('Ban comments')) hide_type_choices = [(0, _l('Show')), (1, _l('Hide completely')), (2, _l('Blur')), diff --git a/app/admin/routes.py b/app/admin/routes.py index 17026c8c..36497d22 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -1097,6 +1097,8 @@ def admin_user_edit(user_id): if form.validate_on_submit(): user.bot = form.bot.data user.banned = form.banned.data + user.ban_posts = form.ban_posts.data + user.ban_comments = form.ban_comments.data user.hide_nsfw = form.hide_nsfw.data user.hide_nsfl = form.hide_nsfl.data if form.verified.data and not user.verified: @@ -1130,6 +1132,8 @@ def admin_user_edit(user_id): form.bot.data = user.bot form.verified.data = user.verified form.banned.data = user.banned + form.ban_posts.data = user.ban_posts + form.ban_comments.data = user.ban_comments form.hide_nsfw.data = user.hide_nsfw form.hide_nsfl.data = user.hide_nsfl if user.roles and user.roles.count() > 0: diff --git a/app/community/routes.py b/app/community/routes.py index 3de5b0d0..3ff18311 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -587,7 +587,7 @@ def join_then_add(actor): @login_required @validation_required def add_post(actor, type): - if current_user.banned: + if current_user.banned or current_user.ban_posts: return show_ban_message() community = actor_to_community(actor) diff --git a/app/models.py b/app/models.py index 6f0c5ada..2e903196 100644 --- a/app/models.py +++ b/app/models.py @@ -1668,6 +1668,9 @@ class PostReply(db.Model): if not post.comments_enabled: raise Exception('Comments are disabled on this post') + if user.ban_comments: + raise Exception('Banned from commenting') + if in_reply_to is not None: parent_id = in_reply_to.id depth = in_reply_to.depth + 1 diff --git a/app/post/routes.py b/app/post/routes.py index 2410938a..2609c5de 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -501,7 +501,7 @@ def continue_discussion(post_id, comment_id): @bp.route('/post//comment//reply', methods=['GET', 'POST']) @login_required def add_reply(post_id: int, comment_id: int): - if current_user.banned: + if current_user.banned or current_user.ban_comments: return show_ban_message() post = Post.query.get_or_404(post_id) diff --git a/app/templates/admin/edit_user.html b/app/templates/admin/edit_user.html index 57be9a11..7fa6044d 100644 --- a/app/templates/admin/edit_user.html +++ b/app/templates/admin/edit_user.html @@ -26,6 +26,8 @@ {{ render_field(form.bot) }} {{ render_field(form.verified) }} {{ render_field(form.banned) }} + {{ render_field(form.ban_posts) }} + {{ render_field(form.ban_comments) }}

receive newsletter: {{ user.newsletter }}

{{ render_field(form.hide_nsfw) }} {{ render_field(form.hide_nsfl) }} diff --git a/app/templates/admin/users.html b/app/templates/admin/users.html index 2c793861..2428cda0 100644 --- a/app/templates/admin/users.html +++ b/app/templates/admin/users.html @@ -41,7 +41,9 @@ {% if user.attitude != 1 %}{{ (user.attitude * 100) | round | int }}%{% endif %} {% if user.reputation %}R {{ user.reputation | round | int }}{% endif %} - {{ 'Banned'|safe if user.banned }} + {{ 'Banned'|safe if user.banned }} + {{ 'Banned posts'|safe if user.ban_posts }} + {{ 'Banned comments'|safe if user.ban_comments }} {{ user.reports if user.reports > 0 }} {{ user.ip_address if user.ip_address }}
{{ user.ip_address_country if user.ip_address_country }} {{ user.referrer if user.referrer }}