From 658e12eb86daf237cd210bfc28ea42a25daf4bbd Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 8 Sep 2021 16:47:12 -0700 Subject: [PATCH] Allow admins to suspend pending users --- .../migrations/0090_auto_20210908_2346.py | 45 +++++++++++++++++++ bookwyrm/models/base_model.py | 1 + .../user_admin/user_moderation_actions.html | 19 ++++++-- bookwyrm/urls.py | 5 +++ bookwyrm/views/__init__.py | 9 +++- bookwyrm/views/reports.py | 15 ++++++- 6 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 bookwyrm/migrations/0090_auto_20210908_2346.py diff --git a/bookwyrm/migrations/0090_auto_20210908_2346.py b/bookwyrm/migrations/0090_auto_20210908_2346.py new file mode 100644 index 000000000..7c8708573 --- /dev/null +++ b/bookwyrm/migrations/0090_auto_20210908_2346.py @@ -0,0 +1,45 @@ +# Generated by Django 3.2.4 on 2021-09-08 23:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0089_user_show_suggested_users"), + ] + + operations = [ + migrations.AlterField( + model_name="connector", + name="deactivation_reason", + field=models.CharField( + blank=True, + choices=[ + ("pending", "Pending"), + ("self_deletion", "Self Deletion"), + ("moderator_suspension", "Moderator Suspension"), + ("moderator_deletion", "Moderator Deletion"), + ("domain_block", "Domain Block"), + ], + max_length=255, + null=True, + ), + ), + migrations.AlterField( + model_name="user", + name="deactivation_reason", + field=models.CharField( + blank=True, + choices=[ + ("pending", "Pending"), + ("self_deletion", "Self Deletion"), + ("moderator_suspension", "Moderator Suspension"), + ("moderator_deletion", "Moderator Deletion"), + ("domain_block", "Domain Block"), + ], + max_length=255, + null=True, + ), + ), + ] diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index 5b55ea50f..f19ebfd9b 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -13,6 +13,7 @@ DeactivationReason = models.TextChoices( [ "pending", "self_deletion", + "moderator_suspension", "moderator_deletion", "domain_block", ], diff --git a/bookwyrm/templates/user_admin/user_moderation_actions.html b/bookwyrm/templates/user_admin/user_moderation_actions.html index e4460a687..3a82d92c3 100644 --- a/bookwyrm/templates/user_admin/user_moderation_actions.html +++ b/bookwyrm/templates/user_admin/user_moderation_actions.html @@ -8,17 +8,28 @@

{% trans "Actions" %}

+ {% if user.is_active %}

{% trans "Send direct message" %}

+ {% endif %} + + {% if user.is_active or user.deactivation_reason == "pending" %} +
{% csrf_token %} - {% if user.is_active %} - {% else %} - - {% endif %}
+ + {% else %} + +
+ {% csrf_token %} + +
+ + {% endif %} +
{% if user.local %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 9ae1b8228..b2b7723b0 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -153,6 +153,11 @@ urlpatterns = [ views.suspend_user, name="settings-report-suspend", ), + re_path( + r"^settings/reports/(?P\d+)/unsuspend/?$", + views.unsuspend_user, + name="settings-report-unsuspend", + ), re_path( r"^settings/reports/(?P\d+)/resolve/?$", views.resolve_report, diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 5142d532d..6d283b94e 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -33,7 +33,14 @@ from .reading import edit_readthrough, create_readthrough from .reading import delete_readthrough, delete_progressupdate from .reading import ReadingStatus from .register import Register, ConfirmEmail, ConfirmEmailCode, resend_link -from .reports import Report, Reports, make_report, resolve_report, suspend_user +from .reports import ( + Report, + Reports, + make_report, + resolve_report, + suspend_user, + unsuspend_user, +) from .rss_feed import RssFeed from .password import PasswordResetRequest, PasswordReset, ChangePassword from .search import Search diff --git a/bookwyrm/views/reports.py b/bookwyrm/views/reports.py index 46c238844..08330fa93 100644 --- a/bookwyrm/views/reports.py +++ b/bookwyrm/views/reports.py @@ -77,7 +77,20 @@ class Report(View): def suspend_user(_, user_id): """mark an account as inactive""" user = get_object_or_404(models.User, id=user_id) - user.is_active = not user.is_active + user.is_active = False + user.deactivation_reason = "moderator_suspension" + # this isn't a full deletion, so we don't want to tell the world + user.save(broadcast=False) + return redirect("settings-user", user.id) + + +@login_required +@permission_required("bookwyrm_moderate_user") +def unsuspend_user(_, user_id): + """mark an account as inactive""" + user = get_object_or_404(models.User, id=user_id) + user.is_active = True + user.deactivation_reason = None # this isn't a full deletion, so we don't want to tell the world user.save(broadcast=False) return redirect("settings-user", user.id)