FIX: Don't set topic timer for close topics when changing category.

https://meta.discourse.org/t/moving-a-topic-after-closure-reopens-topic/67659/4
This commit is contained in:
Guo Xiang Tan 2017-08-22 12:54:11 +09:00
parent 2d4d76472d
commit 87994a86ce
2 changed files with 18 additions and 2 deletions

View File

@ -216,7 +216,8 @@ class Topic < ActiveRecord::Base
end
def inherit_auto_close_from_category
if !@ignore_category_auto_close &&
if !self.closed &&
!@ignore_category_auto_close &&
self.category &&
self.category.auto_close_hours &&
!public_topic_timer&.execute_at
@ -1010,7 +1011,7 @@ SQL
topic_timer.status_type = status_type
if time.blank?
topic_timer.trash!(trashed_by: by_user || Discourse.system_user)
topic_timer.trash!(by_user || Discourse.system_user)
return
end

View File

@ -1066,6 +1066,21 @@ describe Topic do
expect(topic_timer.execute_at).to be_within(1.second).of(Time.zone.now + 5.hours)
end
describe 'when topic is already closed' do
before do
SiteSetting.queue_jobs = true
topic.update_status('closed', true, Discourse.system_user)
end
it 'should not set a topic timer' do
expect { topic.change_category_to_id(new_category.id) }
.to change { TopicTimer.with_deleted.count }.by(0)
expect(topic.closed).to eq(true)
expect(topic.reload.category).to eq(new_category)
end
end
describe 'when topic has an existing topic timer' do
let(:topic_timer) { Fabricate(:topic_timer, topic: topic) }