FIX: Do not unassign on topic open

FIX: Do not unassign on topic open

diff --git a/plugin.rb b/plugin.rb
index 08e6775..fcd75ba 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -217,8 +217,8 @@ after_initialize do
     ::TopicAssigner.auto_assign(post, force: true)
   end
 
-  on(:topic_status_updated) do |topic, status|
-    if SiteSetting.unassign_on_close && (status == 'closed' || status == 'autoclosed')
+  on(:topic_status_updated) do |topic, status, enabled|
+    if SiteSetting.unassign_on_close && (status == 'closed' || status == 'autoclosed') && enabled
       assigner = ::TopicAssigner.new(topic, Discourse.system_user)
       assigner.unassign(silent: true)
     end
diff --git a/spec/lib/topic_assigner_spec.rb b/spec/lib/topic_assigner_spec.rb
index 9863bcf..a62e403 100644
--- a/spec/lib/topic_assigner_spec.rb
+++ b/spec/lib/topic_assigner_spec.rb
@@ -142,14 +142,24 @@ RSpec.describe TopicAssigner do
       assigner.assign(moderator)
     end
 
-    it "will unassign on topic closed" do
+    it "unassigns on topic closed" do
       topic.update_status("closed", true, moderator)
       expect(TopicQuery.new(moderator, assigned: moderator.username).list_latest.topics).to be_blank
     end
 
-    it "will unassign on topic autoclosed" do
+    it "unassigns on topic autoclosed" do
       topic.update_status("autoclosed", true, moderator)
       expect(TopicQuery.new(moderator, assigned: moderator.username).list_latest.topics).to be_blank
     end
+
+    it "does not unassign on topic open" do
+      topic.update_status("closed", false, moderator)
+      expect(TopicQuery.new(moderator, assigned: moderator.username).list_latest.topics).to eq([topic])
+    end
+
+    it "does not unassign on automatic topic open" do
+      topic.update_status("autoclosed", false, moderator)
+      expect(TopicQuery.new(moderator, assigned: moderator.username).list_latest.topics).to eq([topic])
+    end
   end
 end

GitHub sha: 5527457c

1 Like