Add a DiscourseEvent for when a topic is closed

This commit is contained in:
Robin Ward 2017-09-27 14:00:53 -04:00
parent 3e13becf33
commit 7578d8fc44
2 changed files with 18 additions and 0 deletions

View File

@ -36,6 +36,10 @@ TopicStatusUpdater = Struct.new(:topic, :user) do
result = false if rc == 0
end
if status.manually_closing_topic?
DiscourseEvent.trigger(:topic_closed, topic)
end
if @topic_status_update
if status.manually_closing_topic? || status.closing_topic?
topic.delete_topic_timer(TopicTimer.types[:close])

View File

@ -40,6 +40,20 @@ describe TopicStatusUpdater do
expect(last_post.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_minutes", count: 0))
end
it "triggers a DiscourseEvent on close" do
topic = create_topic
called = false
updater = -> (topic) { called = true }
DiscourseEvent.on(:topic_closed, &updater)
TopicStatusUpdater.new(topic, admin).update!("closed", true)
DiscourseEvent.off(:topic_closed, &updater)
expect(topic).to be_closed
expect(called).to eq(true)
end
it "adds an autoclosed message based on last post" do
topic = create_topic
Fabricate(:post, topic: topic)