FEATURE: Add option to immediately delete stub topics upon merge (#28228)

Currently to handle stub topics after merging, there are only options to (1) never delete a stub topic and (2) delete a stub topic after X amount of days. This adds the option to immediately delete a stub topic upon merge.

---------

Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>
Co-authored-by: Renato Atilio <renato@discourse.org>
This commit is contained in:
carson chang 2024-08-07 06:05:40 -07:00 committed by GitHub
parent 2c8d703b48
commit 854b8b7093
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 5 deletions

View File

@ -701,7 +701,19 @@ class PostMover
@original_topic.update_status("closed", true, @user) @original_topic.update_status("closed", true, @user)
days_to_deleting = SiteSetting.delete_merged_stub_topics_after_days days_to_deleting = SiteSetting.delete_merged_stub_topics_after_days
if days_to_deleting > 0 if days_to_deleting == 0
if Guardian.new(@user).can_delete?(@original_topic)
first_post = @original_topic.ordered_posts.first
PostDestroyer.new(
@user,
first_post,
context: I18n.t("topic_statuses.auto_deleted_by_merge"),
).destroy
@original_topic.trash!(Discourse.system_user)
end
elsif days_to_deleting > 0
@original_topic.set_or_create_timer( @original_topic.set_or_create_timer(
TopicTimer.types[:delete], TopicTimer.types[:delete],
days_to_deleting * 24, days_to_deleting * 24,

View File

@ -2486,7 +2486,7 @@ en:
notify_about_reviewable_item_after: "If there are reviewable items that havent been handled after this many hours, send a personal message to moderators. Set to 0 to disable." notify_about_reviewable_item_after: "If there are reviewable items that havent been handled after this many hours, send a personal message to moderators. Set to 0 to disable."
delete_drafts_older_than_n_days: "Delete drafts that have not been changed in more than (n) days." delete_drafts_older_than_n_days: "Delete drafts that have not been changed in more 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." delete_merged_stub_topics_after_days: "Number of days to wait before automatically deleting fully merged stub topics. Set to -1 to never delete. Set to 0 to immediately delete."
bootstrap_mode_min_users: "Minimum number of users required to disable bootstrap mode and remove Getting Started button (set to 0 to disable, can take up to 24 hours)" bootstrap_mode_min_users: "Minimum number of users required to disable bootstrap mode and remove Getting Started button (set to 0 to disable, can take up to 24 hours)"
@ -2910,6 +2910,7 @@ en:
autoclosed_disabled: "This topic is now opened. New replies are allowed." autoclosed_disabled: "This topic is now opened. New replies are allowed."
autoclosed_disabled_lastpost: "This topic is now opened. New replies are allowed." autoclosed_disabled_lastpost: "This topic is now opened. New replies are allowed."
auto_deleted_by_timer: "Automatically deleted by timer." auto_deleted_by_timer: "Automatically deleted by timer."
auto_deleted_by_merge: "Automatically deleted by merge."
login: login:
invalid_second_factor_method: "The selected two-factor method is invalid." invalid_second_factor_method: "The selected two-factor method is invalid."

View File

@ -2828,7 +2828,7 @@ uncategorized:
delete_merged_stub_topics_after_days: delete_merged_stub_topics_after_days:
default: 7 default: 7
min: 0 min: -1
backup_drafts_to_pm_length: backup_drafts_to_pm_length:
default: 0 default: 0

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
class UpdateDeleteMergedStubTopicsAfterDaysSetting < ActiveRecord::Migration[7.1]
def up
execute "UPDATE site_settings SET value = '-1' WHERE name = 'delete_merged_stub_topics_after_days' AND value = '0'"
end
def down
execute "UPDATE site_settings SET value = '0' WHERE name = 'delete_merged_stub_topics_after_days' AND value = '-1'"
end
end

View File

@ -733,8 +733,8 @@ RSpec.describe PostMover do
expect(timer).to be_nil expect(timer).to be_nil
end end
it "doesn't schedule topic deleting when all posts were moved if it's disabled in settings" do it "doesn't schedule topic deleting when all posts were moved if it's disabled (-1)" do
SiteSetting.delete_merged_stub_topics_after_days = 0 SiteSetting.delete_merged_stub_topics_after_days = -1
topic.expects(:add_moderator_post).twice topic.expects(:add_moderator_post).twice
posts_to_move = [p1.id, p2.id, p3.id, p4.id] posts_to_move = [p1.id, p2.id, p3.id, p4.id]
@ -742,10 +742,25 @@ RSpec.describe PostMover do
topic.move_posts(user, posts_to_move, destination_topic_id: destination_topic.id) topic.move_posts(user, posts_to_move, destination_topic_id: destination_topic.id)
expect(moved_to).to be_present expect(moved_to).to be_present
expect(Topic.with_deleted.find(topic.id).deleted_at).to be_nil
timer = topic.topic_timers.find_by(status_type: TopicTimer.types[:delete]) timer = topic.topic_timers.find_by(status_type: TopicTimer.types[:delete])
expect(timer).to be_nil expect(timer).to be_nil
end end
it "immediately deletes topic when delete_merged_stub_topics_after_days is 0" do
SiteSetting.delete_merged_stub_topics_after_days = 0
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
expect(Topic.with_deleted.find(topic.id).deleted_at).to be_present
end
it "ignores moderator posts and closes the topic if all regular posts were moved" do it "ignores moderator posts and closes the topic if all regular posts were moved" do
add_moderator_post_to topic, Post.types[:moderator_action] add_moderator_post_to topic, Post.types[:moderator_action]
add_moderator_post_to topic, Post.types[:small_action] add_moderator_post_to topic, Post.types[:small_action]