mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Revert "FIX: Topic Timer auto opening closed topics (#10524)"
This reverts commit 7cfd5f87ff16d3010274851b7442aa92c2d494d6.
This commit is contained in:
@ -463,15 +463,6 @@ class TopicsController < ApplicationController
|
|||||||
options.merge!(category_id: params[:category_id]) if !params[:category_id].blank?
|
options.merge!(category_id: params[:category_id]) if !params[:category_id].blank?
|
||||||
options.merge!(duration: params[:duration].to_i) if params[:duration].present?
|
options.merge!(duration: params[:duration].to_i) if params[:duration].present?
|
||||||
|
|
||||||
# Be sure to close/open the topic when setting an auto-open/auto-close timer
|
|
||||||
if status_type == TopicTimer.types[:open]
|
|
||||||
topic.update_status('closed', true, current_user) if !topic.closed
|
|
||||||
end
|
|
||||||
|
|
||||||
if status_type == TopicTimer.types[:close]
|
|
||||||
topic.update_status('closed', false, current_user) if topic.closed
|
|
||||||
end
|
|
||||||
|
|
||||||
topic_status_update = topic.set_or_create_timer(
|
topic_status_update = topic.set_or_create_timer(
|
||||||
status_type,
|
status_type,
|
||||||
params[:time],
|
params[:time],
|
||||||
|
@ -127,6 +127,7 @@ class TopicTimer < ActiveRecord::Base
|
|||||||
|
|
||||||
def schedule_auto_open_job(time)
|
def schedule_auto_open_job(time)
|
||||||
return unless topic
|
return unless topic
|
||||||
|
topic.update_status('closed', true, user) if !topic.closed
|
||||||
|
|
||||||
Jobs.enqueue_at(time, :toggle_topic_closed,
|
Jobs.enqueue_at(time, :toggle_topic_closed,
|
||||||
topic_timer_id: id,
|
topic_timer_id: id,
|
||||||
@ -136,6 +137,7 @@ class TopicTimer < ActiveRecord::Base
|
|||||||
|
|
||||||
def schedule_auto_close_job(time)
|
def schedule_auto_close_job(time)
|
||||||
return unless topic
|
return unless topic
|
||||||
|
topic.update_status('closed', false, user) if topic.closed
|
||||||
|
|
||||||
Jobs.enqueue_at(time, :toggle_topic_closed,
|
Jobs.enqueue_at(time, :toggle_topic_closed,
|
||||||
topic_timer_id: id,
|
topic_timer_id: id,
|
||||||
|
@ -138,7 +138,7 @@ RSpec.describe TopicTimer, type: :model do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when a topic has been deleted' do
|
describe 'when a open topic status update is created for an open topic' do
|
||||||
fab!(:topic) { Fabricate(:topic, closed: false) }
|
fab!(:topic) { Fabricate(:topic, closed: false) }
|
||||||
fab!(:topic_timer) do
|
fab!(:topic_timer) do
|
||||||
Fabricate(:topic_timer,
|
Fabricate(:topic_timer,
|
||||||
@ -151,11 +151,46 @@ RSpec.describe TopicTimer, type: :model do
|
|||||||
Jobs.run_immediately!
|
Jobs.run_immediately!
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not queue the job' do
|
it 'should close the topic' do
|
||||||
topic.trash!
|
|
||||||
topic_timer
|
topic_timer
|
||||||
|
expect(topic.reload.closed).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
expect(Jobs::ToggleTopicClosed.jobs).to eq([])
|
describe 'when topic has been deleted' do
|
||||||
|
it 'should not queue the job' do
|
||||||
|
topic.trash!
|
||||||
|
topic_timer
|
||||||
|
|
||||||
|
expect(Jobs::ToggleTopicClosed.jobs).to eq([])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'when a close topic status update is created for a closed topic' do
|
||||||
|
fab!(:topic) { Fabricate(:topic, closed: true) }
|
||||||
|
fab!(:topic_timer) do
|
||||||
|
Fabricate(:topic_timer,
|
||||||
|
status_type: described_class.types[:close],
|
||||||
|
topic: topic
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
Jobs.run_immediately!
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should open the topic' do
|
||||||
|
topic_timer
|
||||||
|
expect(topic.reload.closed).to eq(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'when topic has been deleted' do
|
||||||
|
it 'should not queue the job' do
|
||||||
|
topic.trash!
|
||||||
|
topic_timer
|
||||||
|
|
||||||
|
expect(Jobs::ToggleTopicClosed.jobs).to eq([])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2925,29 +2925,6 @@ RSpec.describe TopicsController do
|
|||||||
expect(response.body).to include('status_type')
|
expect(response.body).to include('status_type')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should close the topic when setting an auto-open timer' do
|
|
||||||
post "/t/#{topic.id}/timer.json", params: {
|
|
||||||
time: 24,
|
|
||||||
status_type: "open"
|
|
||||||
}
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
topic_status_update = TopicTimer.last
|
|
||||||
topic = topic_status_update.topic
|
|
||||||
expect(topic.closed).to eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should open the topic when setting an auto-close timer' do
|
|
||||||
topic = Fabricate(:topic, user: user, closed: true)
|
|
||||||
post "/t/#{topic.id}/timer.json", params: {
|
|
||||||
time: 24,
|
|
||||||
status_type: "close"
|
|
||||||
}
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
topic_status_update = TopicTimer.last
|
|
||||||
topic = topic_status_update.topic
|
|
||||||
expect(topic.closed).to eq(false)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user