Let moderators delete users

This commit is contained in:
Mouse Reeve 2021-09-08 17:21:45 -07:00
parent 916be2552d
commit 15344b6a8e
4 changed files with 27 additions and 7 deletions

View file

@ -1,6 +1,6 @@
{% load i18n %} {% load i18n %}
<div class="block content"> <div class="block content">
{% 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" %}
<div class="notification is-danger"> <div class="notification is-danger">
{% trans "Permanently deleted" %} {% trans "Permanently deleted" %}
</div> </div>
@ -15,23 +15,31 @@
{% endif %} {% endif %}
{% if user.is_active or user.deactivation_reason == "pending" %} {% if user.is_active or user.deactivation_reason == "pending" %}
<form name="suspend" method="post" action="{% url 'settings-report-suspend' user.id %}" class="mr-1">
<form name="suspend" method="post" action="{% url 'settings-report-suspend' user.id %}">
{% csrf_token %} {% csrf_token %}
<button type="submit" class="button is-danger is-light">{% trans "Suspend user" %}</button> <button type="submit" class="button is-danger is-light">{% trans "Suspend user" %}</button>
</form> </form>
{% else %} {% else %}
<form name="unsuspend" method="post" action="{% url 'settings-report-unsuspend' user.id %}" class="mr-1">
<form name="unsuspend" method="post" action="{% url 'settings-report-unsuspend' user.id %}">
{% csrf_token %} {% csrf_token %}
<button class="button">{% trans "Un-suspend user" %}</button> <button class="button">{% trans "Un-suspend user" %}</button>
</form> </form>
{% endif %} {% endif %}
{% if user.local %}
<div>
{% 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" %}
</div>
{% endif %}
</div> </div>
{% if user.local %}
<div>
{% include "user_admin/delete_user_form.html" with controls_text="delete_user" class="mt-2 mb-2" %}
</div>
{% endif %}
{% if user.local %} {% if user.local %}
<div> <div>
<form name="permission" method="post" action="{% url 'settings-user' user.id %}"> <form name="permission" method="post" action="{% url 'settings-user' user.id %}">

View file

@ -158,6 +158,11 @@ urlpatterns = [
views.unsuspend_user, views.unsuspend_user,
name="settings-report-unsuspend", name="settings-report-unsuspend",
), ),
re_path(
r"^settings/reports/(?P<user_id>\d+)/delete/?$",
views.moderator_delete_user,
name="settings-delete-user",
),
re_path( re_path(
r"^settings/reports/(?P<report_id>\d+)/resolve/?$", r"^settings/reports/(?P<report_id>\d+)/resolve/?$",
views.resolve_report, views.resolve_report,

View file

@ -40,6 +40,7 @@ from .reports import (
resolve_report, resolve_report,
suspend_user, suspend_user,
unsuspend_user, unsuspend_user,
moderator_delete_user,
) )
from .rss_feed import RssFeed from .rss_feed import RssFeed
from .password import PasswordResetRequest, PasswordReset, ChangePassword from .password import PasswordResetRequest, PasswordReset, ChangePassword

View file

@ -1,5 +1,6 @@
""" moderation via flagged posts and users """ """ moderation via flagged posts and users """
from django.contrib.auth.decorators import login_required, permission_required 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.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
@ -101,6 +102,11 @@ def unsuspend_user(_, user_id):
def moderator_delete_user(request, user_id): def moderator_delete_user(request, user_id):
"""permanently delete a user""" """permanently delete a user"""
user = get_object_or_404(models.User, id=user_id) 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) form = forms.DeleteUserForm(request.POST, instance=user)
moderator = models.User.objects.get(id=request.user.id) moderator = models.User.objects.get(id=request.user.id)