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:
@@ -134,6 +134,7 @@ class Post(models.Model):
|
|||||||
("set_sticky", "Can sticky post"),
|
("set_sticky", "Can sticky post"),
|
||||||
("set_bump", "Can bumplock post"),
|
("set_bump", "Can bumplock post"),
|
||||||
("set_lock", "Can lock post"),
|
("set_lock", "Can lock post"),
|
||||||
|
("wipe_user", "Can wipe all posts by a user"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
if (typeof window.banWindowName === "undefined") {
|
if (typeof window.banWindowName === "undefined") {
|
||||||
window.banWindowName = "ban-window";
|
window.banWindowName = "ban-window";
|
||||||
window.modifyWindowName = "modify-window";
|
window.modifyWindowName = "modify-window";
|
||||||
|
window.wipeWindowName = "wipe-window";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof window.menuItemFactories !== "undefined") {
|
if (typeof window.menuItemFactories !== "undefined") {
|
||||||
@@ -28,6 +29,15 @@ if (typeof window.menuItemFactories !== "undefined") {
|
|||||||
openModifyWindow($(postElement).attr("data-modify-url"));
|
openModifyWindow($(postElement).attr("data-modify-url"));
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
window.menuItemFactories.push(
|
||||||
|
(postElement) => $("<a>")
|
||||||
|
.text("Wipe user posts")
|
||||||
|
.attr("href", "#")
|
||||||
|
.on("click", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
openWipeWindow($(postElement).attr("data-wipe-url"));
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -89,3 +99,29 @@ function openModifyWindow(modifyUrl) {
|
|||||||
});
|
});
|
||||||
modifyWindow.show();
|
modifyWindow.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Wipe window
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
function getWipeWindow() {
|
||||||
|
return window.top.jsFrame.getWindowByName(wipeWindowName);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openWipeWindow(wipeUrl) {
|
||||||
|
if (window.top.jsFrame.containsWindowName(wipeWindowName)) {
|
||||||
|
getWipeWindow().closeFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
let wipeWindow = window.top.jsFrame.create({
|
||||||
|
title: "Wipe post",
|
||||||
|
name: wipeWindowName,
|
||||||
|
width: 475,
|
||||||
|
url: wipeUrl,
|
||||||
|
});
|
||||||
|
$(wipeWindow.iframe, "iframe").on("load", () => {
|
||||||
|
fitWindowToContent(wipeWindow);
|
||||||
|
wipeWindow.setResizable(false);
|
||||||
|
wipeWindow.iframe.contentWindow.thisWindow = wipeWindow;
|
||||||
|
});
|
||||||
|
wipeWindow.show();
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
{% if user.is_staff %}
|
{% if user.is_staff %}
|
||||||
data-ban-url="{% url 'board:ban_create' board.url post.id %}"
|
data-ban-url="{% url 'board:ban_create' board.url post.id %}"
|
||||||
data-modify-url="{% url 'board:post_modify' post.id %}"
|
data-modify-url="{% url 'board:post_modify' post.id %}"
|
||||||
|
data-wipe-url="{% url 'board:post_wipe' post.id %}"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
|||||||
10
board/templates/board/post_wipe.html
Normal file
10
board/templates/board/post_wipe.html
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{% extends "board/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% blocktranslate %}This will delete {{all_posts_count}} posts.{% endblocktranslate %}
|
||||||
|
<form method="post" {# action="{% url 'board:post_wipe_success' %}" #}>
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="submit" value="Wipe all posts by this user" />
|
||||||
|
</form>
|
||||||
|
{% endblock content %}
|
||||||
@@ -42,6 +42,14 @@ urlpatterns = [
|
|||||||
ActionSuccessView.as_view(window_timeout=settings.ACTION_SUCCESS_CLOSE_TIMEOUT),
|
ActionSuccessView.as_view(window_timeout=settings.ACTION_SUCCESS_CLOSE_TIMEOUT),
|
||||||
name="post_delete_success",
|
name="post_delete_success",
|
||||||
),
|
),
|
||||||
|
path("post/wipe/<int:pk>/", PostWipeView.as_view(), name="post_wipe"),
|
||||||
|
path(
|
||||||
|
"post/wipe/success/",
|
||||||
|
ActionSuccessView.as_view(
|
||||||
|
window_timeout=settings.ACTION_SUCCESS_CLOSE_TIMEOUT, message="Posts wiped."
|
||||||
|
),
|
||||||
|
name="post_wipe_success",
|
||||||
|
),
|
||||||
# Board views
|
# Board views
|
||||||
path("post/success/", PostSuccessView.as_view(), name="post_success"),
|
path("post/success/", PostSuccessView.as_view(), name="post_success"),
|
||||||
path("<slug:url>/page/<int:page>/", BoardView.as_view(), name="board_detail"),
|
path("<slug:url>/page/<int:page>/", BoardView.as_view(), name="board_detail"),
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from django.http import Http404, HttpResponseRedirect
|
|||||||
from django.http.request import QueryDict
|
from django.http.request import QueryDict
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.views.generic.base import TemplateView
|
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.urls import reverse, reverse_lazy
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@ __all__ = (
|
|||||||
"PostView",
|
"PostView",
|
||||||
"PostSuccessView",
|
"PostSuccessView",
|
||||||
"PostDeleteView",
|
"PostDeleteView",
|
||||||
|
"PostWipeView",
|
||||||
"ReplyCreateView",
|
"ReplyCreateView",
|
||||||
"ReportView",
|
"ReportView",
|
||||||
)
|
)
|
||||||
@@ -279,6 +280,38 @@ class PostDeleteView(PermissionRequiredMixin, edit.DeleteView):
|
|||||||
return HttpResponseRedirect(success_url)
|
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):
|
class ReportView(CreateView):
|
||||||
model = Report
|
model = Report
|
||||||
form_class = ReportForm
|
form_class = ReportForm
|
||||||
|
|||||||
Reference in New Issue
Block a user