diff --git a/bookwyrm/templates/user_admin/user_moderation_actions.html b/bookwyrm/templates/user_admin/user_moderation_actions.html index 3a82d92c..12b70d3c 100644 --- a/bookwyrm/templates/user_admin/user_moderation_actions.html +++ b/bookwyrm/templates/user_admin/user_moderation_actions.html @@ -1,6 +1,6 @@ {% load i18n %}
- {% if not user.is_active and user.deactivation_reason == "self_deletion" %} + {% if not user.is_active and user.deactivation_reason == "self_deletion" or user.deactivation_reason == "moderator_deletion" %}
{% trans "Permanently deleted" %}
@@ -15,23 +15,31 @@ {% endif %} {% if user.is_active or user.deactivation_reason == "pending" %} - -
+ {% csrf_token %}
- {% else %} - -
+ {% csrf_token %}
- {% endif %} + {% if user.local %} +
+ {% trans "Permanently delete user" as button_text %} + {% include "snippets/toggle/open_button.html" with controls_text="delete_user" text=button_text class="is-danger is-light" %} +
+ {% endif %}
+ {% if user.local %} +
+ {% include "user_admin/delete_user_form.html" with controls_text="delete_user" class="mt-2 mb-2" %} +
+ {% endif %} + {% if user.local %}
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index b2b7723b..460f5df9 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -158,6 +158,11 @@ urlpatterns = [ views.unsuspend_user, name="settings-report-unsuspend", ), + re_path( + r"^settings/reports/(?P\d+)/delete/?$", + views.moderator_delete_user, + name="settings-delete-user", + ), re_path( r"^settings/reports/(?P\d+)/resolve/?$", views.resolve_report, diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 6d283b94..6c88bd9e 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -40,6 +40,7 @@ from .reports import ( resolve_report, suspend_user, unsuspend_user, + moderator_delete_user, ) from .rss_feed import RssFeed from .password import PasswordResetRequest, PasswordReset, ChangePassword diff --git a/bookwyrm/views/reports.py b/bookwyrm/views/reports.py index 8246ae15..72b7f4db 100644 --- a/bookwyrm/views/reports.py +++ b/bookwyrm/views/reports.py @@ -1,5 +1,6 @@ """ moderation via flagged posts and users """ from django.contrib.auth.decorators import login_required, permission_required +from django.core.exceptions import PermissionDenied from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator @@ -101,6 +102,11 @@ def unsuspend_user(_, user_id): def moderator_delete_user(request, user_id): """permanently delete a user""" user = get_object_or_404(models.User, id=user_id) + + # we can't delete users on other instances + if not user.local: + raise PermissionDenied + form = forms.DeleteUserForm(request.POST, instance=user) moderator = models.User.objects.get(id=request.user.id)