mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-03-26 06:41:22 -04:00
If an auto-closing topic is manually closed, remove the auto-close countdown
This commit is contained in:
parent
44cd5505d3
commit
2c8ed8414c
3 changed files with 20 additions and 6 deletions
|
@ -138,7 +138,7 @@ class Topic < ActiveRecord::Base
|
||||||
|
|
||||||
before_save do
|
before_save do
|
||||||
if (auto_close_at_changed? and !auto_close_at_was.nil?) or (auto_close_user_id_changed? and auto_close_at)
|
if (auto_close_at_changed? and !auto_close_at_was.nil?) or (auto_close_user_id_changed? and auto_close_at)
|
||||||
self.auto_close_started_at ||= Time.zone.now
|
self.auto_close_started_at ||= Time.zone.now if auto_close_at
|
||||||
Jobs.cancel_scheduled_job(:close_topic, {topic_id: id})
|
Jobs.cancel_scheduled_job(:close_topic, {topic_id: id})
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,10 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
|
||||||
else
|
else
|
||||||
topic.update_column status.name, status.enabled?
|
topic.update_column status.name, status.enabled?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if status.manually_closing_topic? && topic.auto_close_at
|
||||||
|
topic.reload.set_auto_close(nil).save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_moderator_post_for(status)
|
def create_moderator_post_for(status)
|
||||||
|
@ -57,5 +61,9 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
|
||||||
def reopening_topic?
|
def reopening_topic?
|
||||||
(closed? || autoclosed?) && disabled?
|
(closed? || autoclosed?) && disabled?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def manually_closing_topic?
|
||||||
|
closed? && enabled?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,6 +60,12 @@ describe Topic do
|
||||||
Given(:admin) { Fabricate(:admin) }
|
Given(:admin) { Fabricate(:admin) }
|
||||||
Given(:staff_topic) { Fabricate(:topic, user: admin, category: category) }
|
Given(:staff_topic) { Fabricate(:topic, user: admin, category: category) }
|
||||||
Then { scheduled_jobs_for(:close_topic, {topic_id: staff_topic.id, user_id: admin.id}).should have(1).job }
|
Then { scheduled_jobs_for(:close_topic, {topic_id: staff_topic.id, user_id: admin.id}).should have(1).job }
|
||||||
|
|
||||||
|
context 'topic is closed manually' do
|
||||||
|
When { staff_topic.update_status('closed', true, admin) }
|
||||||
|
Then { staff_topic.reload.auto_close_at.should be_nil }
|
||||||
|
And { staff_topic.auto_close_started_at.should be_nil }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'topic was created by a non-staff user' do
|
context 'topic was created by a non-staff user' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue