FEATURE: Automatically timed delete stub topics after entire topic is merged into another topic (#13187)

When a topic is fully merged into another topic we close it. Now we want also to set a timer for deleting this topic. By default, stub topics will be deleted in 7 days. Users can change this period or disable auto-deleting by setting the period to 0.
This commit is contained in:
Andrei Prigorshnev 2021-05-28 17:33:10 +04:00 committed by GitHub
parent 47e09700fe
commit 74f7150324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 3 deletions

View File

@ -79,7 +79,7 @@ class PostMover
update_bookmarks
if moving_all_posts
@original_topic.update_status('closed', true, @user)
close_topic_and_schedule_deletion
end
destination_topic.reload
@ -546,4 +546,17 @@ class PostMover
topic_id: topic.id
)
end
def close_topic_and_schedule_deletion
@original_topic.update_status('closed', true, @user)
days_to_deleting = SiteSetting.delete_merged_stub_topics_after_days
if days_to_deleting > 0
@original_topic.set_or_create_timer(
TopicTimer.types[:delete],
days_to_deleting * 24,
by_user: @user
)
end
end
end

View File

@ -2185,6 +2185,7 @@ en:
show_create_topics_notice: "If the site has fewer than 5 public topics, show a notice asking admins to create some topics."
delete_drafts_older_than_n_days: "Delete drafts older than (n) days."
delete_merged_stub_topics_after_days: "Number of days to wait before automatically deleting fully merged stub topics. Set to 0 to never delete stub topics."
bootstrap_mode_min_users: "Minimum number of users required to disable bootstrap mode (set to 0 to disable)"

View File

@ -2146,6 +2146,10 @@ uncategorized:
default: 180
max: 36500
delete_merged_stub_topics_after_days:
default: 7
min: 0
backup_drafts_to_pm_length:
default: 0
hidden: true

View File

@ -608,11 +608,60 @@ describe PostMover do
it "moving all posts will close the topic" do
topic.expects(:add_moderator_post).twice
moved_to = topic.move_posts(user, [p1.id, p2.id, p3.id, p4.id], destination_topic_id: destination_topic.id)
posts_to_move = [p1.id, p2.id, p3.id, p4.id]
moved_to = topic.move_posts(user, posts_to_move, destination_topic_id: destination_topic.id)
expect(moved_to).to be_present
topic.reload
expect(topic.closed).to eq(true)
expect(topic).to be_closed
end
it "doesn't close the topic when not all posts were moved" do
topic.expects(:add_moderator_post).once
posts_to_move = [p1.id, p2.id, p3.id]
moved_to = topic.move_posts(user, posts_to_move, destination_topic_id: destination_topic.id)
expect(moved_to).to be_present
topic.reload
expect(topic).to_not be_closed
end
it "schedules topic deleting when all posts were moved" do
SiteSetting.delete_merged_stub_topics_after_days = 7
freeze_time
topic.expects(:add_moderator_post).twice
posts_to_move = [p1.id, p2.id, p3.id, p4.id]
moved_to = topic.move_posts(user, posts_to_move, destination_topic_id: destination_topic.id)
expect(moved_to).to be_present
timer = topic.topic_timers.find_by(status_type: TopicTimer.types[:delete])
expect(timer).to be_present
expect(timer.execute_at).to eq_time(7.days.from_now)
end
it "doesn't schedule topic deleting when not all posts were moved" do
SiteSetting.delete_merged_stub_topics_after_days = 7
topic.expects(:add_moderator_post).once
posts_to_move = [p1.id, p2.id, p3.id]
moved_to = topic.move_posts(user, posts_to_move, destination_topic_id: destination_topic.id)
expect(moved_to).to be_present
timer = topic.topic_timers.find_by(status_type: TopicTimer.types[:delete])
expect(timer).to be_nil
end
it "doesn't schedule topic deleting when all posts were moved if it's disabled in settings" do
SiteSetting.delete_merged_stub_topics_after_days = 0
topic.expects(:add_moderator_post).twice
posts_to_move = [p1.id, p2.id, p3.id, p4.id]
moved_to = topic.move_posts(user, posts_to_move, destination_topic_id: destination_topic.id)
expect(moved_to).to be_present
timer = topic.topic_timers.find_by(status_type: TopicTimer.types[:delete])
expect(timer).to be_nil
end
it "does not try to move small action posts" do