Add user post wiping

If a user has spammed a lot of posts and made a mess of the board, this
will allow us to delete all posts by the offending user from the same
IP.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-07-17 16:59:23 -07:00
parent 8ea95a927c
commit 1856adaf3b
6 changed files with 90 additions and 1 deletions

View File

@@ -8,7 +8,7 @@ from django.http import Http404, HttpResponseRedirect
from django.http.request import QueryDict
from django.shortcuts import get_object_or_404
from django.views.generic.base import TemplateView
from django.views.generic import edit, list
from django.views.generic import detail, edit, list
from django.urls import reverse, reverse_lazy
from django.utils import timezone
@@ -31,6 +31,7 @@ __all__ = (
"PostView",
"PostSuccessView",
"PostDeleteView",
"PostWipeView",
"ReplyCreateView",
"ReportView",
)
@@ -279,6 +280,38 @@ class PostDeleteView(PermissionRequiredMixin, edit.DeleteView):
return HttpResponseRedirect(success_url)
class PostWipeView(PermissionRequiredMixin, detail.SingleObjectMixin, TemplateView):
model = Post
permission_required = ("wipe_user",)
template_name = "board/post_wipe.html"
success_url = reverse_lazy("board:post_wipe_success")
@property
def all_posts(self):
return Post.objects.filter(ip=self.object.ip)
def dispatch(self, request, *args, **kwargs):
self.object = self.get_object()
return super(PostWipeView, self).dispatch(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
# Wipe user's posts
self.all_posts.delete()
# Success redirect
success_url = self.get_success_url()
return HttpResponseRedirect(success_url)
def get_context_data(self, **kwargs):
context = super(PostWipeView, self).get_context_data(**kwargs)
# context["all_posts"] = self.all_posts
# for some reason, {{all_posts.count}} does not seem to work in the template.
context["all_posts_count"] = self.all_posts.count()
return context
def get_success_url(self):
return self.success_url
class ReportView(CreateView):
model = Report
form_class = ReportForm