FEATURE: Introduce skip_auto_delete_reply_likes site setting (#11562)

osts from topics with 'auto delete replies timer' with more than
skip_auto_delete_reply_likes likes will no longer be deleted. If 0,
all posts will be deleted.
This commit is contained in:
Bianca Nenciu 2020-12-23 07:30:10 +02:00 committed by GitHub
parent edf4e8b788
commit 755627caa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 0 deletions

View File

@ -18,6 +18,8 @@ module Jobs
end end
replies = topic.posts.where("posts.post_number > 1") replies = topic.posts.where("posts.post_number > 1")
replies = replies.where("like_count < ?", SiteSetting.skip_auto_delete_reply_likes) if SiteSetting.skip_auto_delete_reply_likes > 0
replies.where('posts.created_at < ?', topic_timer.duration.days.ago).each do |post| replies.where('posts.created_at < ?', topic_timer.duration.days.ago).each do |post|
PostDestroyer.new(topic_timer.user, post, context: I18n.t("topic_statuses.auto_deleted_by_timer")).destroy PostDestroyer.new(topic_timer.user, post, context: I18n.t("topic_statuses.auto_deleted_by_timer")).destroy
end end

View File

@ -2182,6 +2182,7 @@ en:
blur_tl0_flagged_posts_media: "Blur flagged posts images to hide potentially NSFW content." blur_tl0_flagged_posts_media: "Blur flagged posts images to hide potentially NSFW content."
enable_page_publishing: "Allow staff members to publish topics to new URLs with their own styling." enable_page_publishing: "Allow staff members to publish topics to new URLs with their own styling."
show_published_pages_login_required: "Anonymous users can see published pages, even when login is required." show_published_pages_login_required: "Anonymous users can see published pages, even when login is required."
skip_auto_delete_reply_likes: "When automatically deleting old replies, skip deleting posts with this number of likes or more."
default_email_digest_frequency: "How often users receive summary emails by default." default_email_digest_frequency: "How often users receive summary emails by default."
default_include_tl0_in_digests: "Include posts from new users in summary emails by default. Users can change this in their preferences." default_include_tl0_in_digests: "Include posts from new users in summary emails by default. Users can change this in their preferences."

View File

@ -996,6 +996,7 @@ posting:
default: false default: false
show_published_pages_login_required: show_published_pages_login_required:
default: false default: false
skip_auto_delete_reply_likes: 5
email: email:
email_time_window_mins: email_time_window_mins:

View File

@ -15,6 +15,8 @@ describe Jobs::DeleteReplies do
end end
it "can delete replies of a topic" do it "can delete replies of a topic" do
SiteSetting.skip_auto_delete_reply_likes = 0
freeze_time (2.days.from_now) freeze_time (2.days.from_now)
expect { expect {
@ -24,4 +26,16 @@ describe Jobs::DeleteReplies do
topic_timer.reload topic_timer.reload
expect(topic_timer.execute_at).to eq_time(2.day.from_now) expect(topic_timer.execute_at).to eq_time(2.day.from_now)
end end
it "does not delete posts with likes over the threshold" do
SiteSetting.skip_auto_delete_reply_likes = 3
freeze_time (2.days.from_now)
topic.posts.last.update!(like_count: SiteSetting.skip_auto_delete_reply_likes + 1)
expect {
described_class.new.execute(topic_timer_id: topic_timer.id)
}.to change { topic.posts.count }.by(-1)
end
end end