diff --git a/app/assets/javascripts/discourse/components/topic-status-info.js.es6 b/app/assets/javascripts/discourse/components/topic-status-info.js.es6 index 9545a022a0c..86bf0800696 100644 --- a/app/assets/javascripts/discourse/components/topic-status-info.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-status-info.js.es6 @@ -4,13 +4,14 @@ export default Ember.Component.extend(bufferedRender({ elementId: 'topic-status-info', delayedRerender: null, - rerenderTriggers: ['topic.closed', - 'topic.topic_status_update.execute_at', - 'topic.topic_status_update.based_on_last_post', - 'topic.topic_status_update.duration'], + rerenderTriggers: [ + 'topic.topic_status_update', + 'topic.topic_status_update.execute_at', + 'topic.topic_status_update.based_on_last_post', + 'topic.topic_status_update.duration' + ], buildBuffer(buffer) { - if (Ember.isEmpty(this.get('topic.topic_status_update.execute_at'))) return; if (!this.get('topic.topic_status_update')) return; let statusUpdateAt = moment(this.get('topic.topic_status_update.execute_at')); diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index a774cb8ad08..28c929189d4 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -588,7 +588,11 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { }, toggleClosed() { - this.get('content').toggleStatus('closed'); + const topic = this.get('content'); + + this.get('content').toggleStatus('closed').then(result => { + topic.set('topic_status_update', result.topic_status_update); + }); }, recoverTopic() { diff --git a/app/assets/javascripts/discourse/models/topic.js.es6 b/app/assets/javascripts/discourse/models/topic.js.es6 index a40aecc3f72..67c6a9b40bd 100644 --- a/app/assets/javascripts/discourse/models/topic.js.es6 +++ b/app/assets/javascripts/discourse/models/topic.js.es6 @@ -223,7 +223,7 @@ const Topic = RestModel.extend({ toggleStatus(property) { this.toggleProperty(property); - this.saveStatus(property, !!this.get(property)); + return this.saveStatus(property, !!this.get(property)); }, saveStatus(property, value, until) { diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 42d76310f33..e7ca1a34c11 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -273,7 +273,12 @@ class TopicsController < ApplicationController @topic = Topic.find_by(id: topic_id) guardian.ensure_can_moderate!(@topic) @topic.update_status(status, enabled, current_user, until: params[:until]) - render nothing: true + + render json: success_json.merge!( + topic_status_update: TopicStatusUpdateSerializer.new( + TopicStatusUpdate.find_by(topic: @topic), root: false + ) + ) end def mute diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 6377403e32b..4aad6443d73 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -412,14 +412,19 @@ describe TopicsController do expect { xhr :put, :status, topic_id: @topic.id, status: 'title', enabled: 'true' }.to raise_error(Discourse::InvalidParameters) end - it 'calls update_status on the forum topic with false' do - Topic.any_instance.expects(:update_status).with('closed', false, @user, until: nil) - xhr :put, :status, topic_id: @topic.id, status: 'closed', enabled: 'false' - end + it 'should update the status of the topic correctly' do + @topic = Fabricate(:topic, user: @user, closed: true, topic_status_updates: [ + Fabricate(:topic_status_update, status_type: TopicStatusUpdate.types[:open]) + ]) - it 'calls update_status on the forum topic with true' do - Topic.any_instance.expects(:update_status).with('closed', true, @user, until: nil) - xhr :put, :status, topic_id: @topic.id, status: 'closed', enabled: 'true' + xhr :put, :status, topic_id: @topic.id, status: 'closed', enabled: 'false' + + expect(response).to be_success + expect(@topic.reload.closed).to eq(false) + + body = JSON.parse(response.body) + + expect(body['topic_status_update']).to eq(nil) end end