mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
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:
parent
2c8d703b48
commit
854b8b7093
|
@ -701,7 +701,19 @@ class PostMover
|
|||
@original_topic.update_status("closed", true, @user)
|
||||
|
||||
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(
|
||||
TopicTimer.types[:delete],
|
||||
days_to_deleting * 24,
|
||||
|
|
|
@ -2486,7 +2486,7 @@ en:
|
|||
notify_about_reviewable_item_after: "If there are reviewable items that haven’t 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_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)"
|
||||
|
||||
|
@ -2910,6 +2910,7 @@ en:
|
|||
autoclosed_disabled: "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_merge: "Automatically deleted by merge."
|
||||
|
||||
login:
|
||||
invalid_second_factor_method: "The selected two-factor method is invalid."
|
||||
|
|
|
@ -2828,7 +2828,7 @@ uncategorized:
|
|||
|
||||
delete_merged_stub_topics_after_days:
|
||||
default: 7
|
||||
min: 0
|
||||
min: -1
|
||||
|
||||
backup_drafts_to_pm_length:
|
||||
default: 0
|
||||
|
|
|
@ -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
|
|
@ -733,8 +733,8 @@ RSpec.describe PostMover do
|
|||
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
|
||||
it "doesn't schedule topic deleting when all posts were moved if it's disabled (-1)" do
|
||||
SiteSetting.delete_merged_stub_topics_after_days = -1
|
||||
|
||||
topic.expects(:add_moderator_post).twice
|
||||
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)
|
||||
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])
|
||||
expect(timer).to be_nil
|
||||
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
|
||||
add_moderator_post_to topic, Post.types[:moderator_action]
|
||||
add_moderator_post_to topic, Post.types[:small_action]
|
||||
|
|
Loading…
Reference in New Issue
Block a user