forum: delete posts when topic is deleted.

Fix it so that when a forum topic is deleted, all posts in the topic are
deleted too. Also make it so that when a forum topic is undeleted, all
posts in it are undeleted too.

Before when a topic was deleted, only the topic itself was marked as
deleted, not the posts inside the topic. This meant that when a spam
topic was deleted, the OP wouldn't be marked as deleted, so any
modreports against it wouldn't be marked as handled.

Also change it so that it's not possible to undelete a post in a deleted
topic, or to delete the OP of a topic without deleting the topic itself.

Finally, add a fix script to delete all active posts in deleted topics,
and to undelete all deleted OPs in active topics.
This commit is contained in:
evazion
2022-01-21 20:16:32 -06:00
parent befdb87bd5
commit 56722df753
9 changed files with 104 additions and 39 deletions

View File

@@ -219,24 +219,36 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
context "destroy action" do
should "allow mods to delete posts" do
delete_auth forum_post_path(@forum_post), @mod
assert_redirected_to(forum_post_path(@forum_post))
assert_equal(true, @forum_post.reload.is_deleted?)
@forum_reply = as(@user) { create(:forum_post, topic: @forum_topic, creator: @user) }
delete_auth forum_post_path(@forum_reply), @mod
assert_redirected_to(@forum_reply)
assert_equal(true, @forum_reply.reload.is_deleted?)
end
should "not allow users to delete their own posts" do
delete_auth forum_post_path(@forum_post), @user
@forum_reply = as(@user) { create(:forum_post, topic: @forum_topic, creator: @user) }
delete_auth forum_post_path(@forum_reply), @user
assert_response 403
assert_equal(false, @forum_post.reload.is_deleted?)
assert_equal(false, @forum_reply.reload.is_deleted?)
end
should "not allow deleting the OP of an active topic" do
delete_auth forum_post_path(@forum_topic.original_post), @mod
assert_redirected_to(@forum_topic.original_post)
assert_equal(false, @forum_topic.original_post.is_deleted?)
end
should "mark all pending moderation reports against the post as handled" do
report1 = create(:moderation_report, model: @forum_post, status: :pending)
report2 = create(:moderation_report, model: @forum_post, status: :rejected)
delete_auth forum_post_path(@forum_post), @mod
forum_reply = as(@user) { create(:forum_post, topic: @forum_topic, creator: @user) }
report1 = create(:moderation_report, model: forum_reply, status: :pending)
report2 = create(:moderation_report, model: forum_reply, status: :rejected)
delete_auth forum_post_path(forum_reply), @mod
assert_redirected_to(forum_post_path(@forum_post))
assert_equal(true, @forum_post.reload.is_deleted?)
assert_redirected_to(forum_post_path(forum_reply))
assert_equal(true, forum_reply.reload.is_deleted?)
assert_equal(true, report1.reload.handled?)
assert_equal(true, report2.reload.rejected?)
assert_equal(1, ModAction.moderation_report_handled.where(creator: @mod).count)
@@ -245,17 +257,30 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
context "undelete action" do
should "allow mods to undelete posts" do
as(@mod) { @forum_post.update!(is_deleted: true) }
post_auth undelete_forum_post_path(@forum_post), @mod
assert_redirected_to(forum_post_path(@forum_post))
assert_equal(false, @forum_post.reload.is_deleted?)
@forum_reply = as(@user) { create(:forum_post, topic: @forum_topic, creator: @user, is_deleted: true) }
post_auth undelete_forum_post_path(@forum_reply), @mod
assert_redirected_to(@forum_reply)
assert_equal(false, @forum_reply.reload.is_deleted?)
end
should "not allow users to undelete their own posts" do
as(@mod) { @forum_post.update!(is_deleted: true) }
post_auth undelete_forum_post_path(@forum_post), @user
@forum_reply = as(@user) { create(:forum_post, topic: @forum_topic, creator: @user, is_deleted: true) }
post_auth undelete_forum_post_path(@forum_reply), @user
assert_response 403
assert_equal(true, @forum_post.reload.is_deleted?)
assert_equal(true, @forum_reply.reload.is_deleted?)
end
should "not allow undeleting posts in deleted topics" do
@forum_reply = as(@user) { create(:forum_post, topic: @forum_topic, creator: @user) }
as(@user) { @forum_topic.update!(is_deleted: true) }
assert_equal(true, @forum_reply.reload.is_deleted?)
post_auth undelete_forum_post_path(@forum_reply), @mod
assert_response 403
assert_equal(true, @forum_reply.reload.is_deleted?)
end
end
end