View for moderators deleting users

This commit is contained in:
Mouse Reeve 2021-09-08 16:58:16 -07:00
parent 31e6e59047
commit 916be2552d
2 changed files with 20 additions and 1 deletions

View file

@ -55,7 +55,6 @@ class DeleteUser(View):
def post(self, request):
"""les get fancy with images"""
form = forms.DeleteUserForm(request.POST, instance=request.user)
form.is_valid()
# idk why but I couldn't get check_password to work on request.user
user = models.User.objects.get(id=request.user.id)
if form.is_valid() and user.check_password(form.cleaned_data["password"]):

View file

@ -96,6 +96,26 @@ def unsuspend_user(_, user_id):
return redirect("settings-user", user.id)
@login_required
@permission_required("bookwyrm_moderate_user")
def moderator_delete_user(request, user_id):
"""permanently delete a user"""
user = get_object_or_404(models.User, id=user_id)
form = forms.DeleteUserForm(request.POST, instance=user)
moderator = models.User.objects.get(id=request.user.id)
# check the moderator's password
if form.is_valid() and moderator.check_password(form.cleaned_data["password"]):
user.deactivation_reason = "moderator_deletion"
user.delete()
return redirect("settings-user", user.id)
form.errors["password"] = ["Invalid password"]
data = {"user": user, "group_form": forms.UserGroupForm(), "form": form}
return TemplateResponse(request, "user_admin/user.html", data)
@login_required
@permission_required("bookwyrm_moderate_post")
def resolve_report(_, report_id):