A platform for community discussion. Free, open, simple.
FIX: Delete other posts in a topic shouldn't unanswer the answer post (#36800)
small-lovely-cat2a1e96d326ff
diff --git a/plugins/discourse-solved/plugin.rb b/plugins/discourse-solved/plugin.rbindex 4afa70724a2..f7ca97cf7b9 100644--- a/plugins/discourse-solved/plugin.rb+++ b/plugins/discourse-solved/plugin.rb@@ -133,6 +133,7 @@ after_initialize dotopic ||= Topic.unscoped.find_by(id: post.topic_id)return if topic.nil?return if topic.solved.nil?+ return if topic.solved.answer_post_id != post.idDistributedMutex.synchronize("discourse_solved_toggle_answer_#{topic.id}") dosolved = topic.solveddiff --git a/plugins/discourse-solved/spec/integration/solved_spec.rb b/plugins/discourse-solved/spec/integration/solved_spec.rbindex cde46c129bc..4ae69db0d91 100644--- a/plugins/discourse-solved/spec/integration/solved_spec.rb+++ b/plugins/discourse-solved/spec/integration/solved_spec.rb@@ -357,6 +357,29 @@ RSpec.describe "Managing Posts solved status" doexpect(topic.solved).to be(nil)end+ it "does not remove the solution when an unrelated post is deleted" do+ reply1 = Fabricate(:post, post_number: 2, topic: topic)+ reply2 = Fabricate(:post, post_number: 3, topic: topic)+ reply3 = Fabricate(:post, post_number: 4, topic: topic)++ post "/solution/accept.json", params: { id: reply2.id }+ expect(response.status).to eq(200)++ expect(topic.solved.answer_post_id).to eq(reply2.id)++ PostDestroyer.new(Discourse.system_user, reply1, context: "spec").destroy+ topic.reload++ expect(topic.solved).to be_present+ expect(topic.solved.answer_post_id).to eq(reply2.id)++ PostDestroyer.new(Discourse.system_user, reply3, context: "spec").destroy+ topic.reload++ expect(topic.solved).to be_present+ expect(topic.solved.answer_post_id).to eq(reply2.id)+ end+it "does not allow you to accept a whisper" dowhisper = Fabricate(:post, topic: topic, post_type: Post.types[:whisper])sign_in(Fabricate(:admin))