Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Reset bump date when deleting a post (#33747)

Lincaebc5703b42bd
diff --git a/app/models/post.rb b/app/models/post.rb
index edad7bb2331..76fca38a52e 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -554,6 +554,10 @@ class Post < ActiveRecord::Base
post_number.blank? ? topic.try(:highest_post_number) == 0 : post_number == 1
end
+ def is_last_reply?
+ topic.try(:highest_post_number) == post_number && post_number != 1
+ end
+
def is_category_description?
topic.present? && topic.is_category_topic? && is_first_post?
end
diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb
index ffe7654e469..81c15e1bf0d 100644
--- a/lib/post_destroyer.rb
+++ b/lib/post_destroyer.rb
@@ -75,6 +75,8 @@ class PostDestroyer
delete_removed_posts_after =
@opts[:delete_removed_posts_after] || SiteSetting.delete_removed_posts_after
+ should_reset_bumped_at = @post.is_last_reply? && [email protected]?
+
if delete_removed_posts_after < 1 || post_is_reviewable? ||
Guardian.new(@user).can_moderate_topic?(@topic) || permanent?
perform_delete
@@ -105,6 +107,8 @@ class PostDestroyer
Discourse.clear_urls!
end
end
+
+ @topic.reset_bumped_at if should_reset_bumped_at
end
def recover
diff --git a/spec/lib/post_destroyer_spec.rb b/spec/lib/post_destroyer_spec.rb
index 862f880a15a..8c3546ded4e 100644
--- a/spec/lib/post_destroyer_spec.rb
+++ b/spec/lib/post_destroyer_spec.rb
@@ -1278,4 +1278,46 @@ RSpec.describe PostDestroyer do
end
end
end
+
+ describe "deleting a last reply" do
+ let!(:topic) { post.topic }
+ let!(:second_last_reply) do
+ freeze_time 1.day.from_now
+ create_post(topic:, user: coding_horror)
+ end
+ fab!(:user)
+ let!(:last_reply) do
+ freeze_time 2.days.from_now
+ create_post(topic:, user:)
+ end
+
+ context "when deleting by the creator" do
+ before { PostDestroyer.new(user, last_reply).destroy }
+
+ it "will reset the topic's bumped_at" do
+ topic.reload
+
+ expect(topic.bumped_at).to eq_time(second_last_reply.created_at)
+ end
+
+ it "still can see the post" do
+ last_reply.reload
+
+ expect(last_reply.deleted_at).to be_blank
+ expect(last_reply.deleted_by).to be_blank
+ expect(last_reply.user_deleted).to eq(true)
+ expect(last_reply.raw).to eq(I18n.t("js.post.deleted_by_author_simple"))
+ end
+ end
+
+ context "when deleting by a staff user" do
+ before { PostDestroyer.new(moderator, last_reply).destroy }
+
+ it "will reset the topic's bumped_at" do
+ topic.reload
+
+ expect(topic.bumped_at).to eq_time(second_last_reply.created_at)
+ end
+ end
+ end
end