FIX: `topic_destroyed` web hook couldn't find topic.
This commit is contained in:
parent
ed2ae3cb0a
commit
81b5d61fa7
|
@ -37,15 +37,16 @@ class TopicView
|
|||
wpcf.flatten.uniq
|
||||
end
|
||||
|
||||
def initialize(topic_id, user = nil, options = {})
|
||||
@message_bus_last_id = MessageBus.last_id("/topic/#{topic_id}")
|
||||
def initialize(topic_or_topic_id, user = nil, options = {})
|
||||
@topic = find_topic(topic_or_topic_id)
|
||||
@user = user
|
||||
@guardian = Guardian.new(@user)
|
||||
@topic = find_topic(topic_id)
|
||||
@print = options[:print].present?
|
||||
|
||||
check_and_raise_exceptions
|
||||
|
||||
@message_bus_last_id = MessageBus.last_id("/topic/#{@topic.id}")
|
||||
@print = options[:print].present?
|
||||
|
||||
options.each do |key, value|
|
||||
self.instance_variable_set("@#{key}".to_sym, value)
|
||||
end
|
||||
|
@ -435,11 +436,15 @@ class TopicView
|
|||
@posts
|
||||
end
|
||||
|
||||
def find_topic(topic_id)
|
||||
def find_topic(topic_or_topic_id)
|
||||
if topic_or_topic_id.is_a?(Topic)
|
||||
topic_or_topic_id
|
||||
else
|
||||
# with_deleted covered in #check_and_raise_exceptions
|
||||
finder = Topic.with_deleted.where(id: topic_id).includes(:category)
|
||||
finder = Topic.with_deleted.where(id: topic_or_topic_id).includes(:category)
|
||||
finder.first
|
||||
end
|
||||
end
|
||||
|
||||
def unfiltered_posts
|
||||
result = filter_post_types(@topic.posts)
|
||||
|
|
|
@ -13,6 +13,11 @@ describe TopicView do
|
|||
expect { TopicView.new(1231232, evil_trout) }.to raise_error(Discourse::NotFound)
|
||||
end
|
||||
|
||||
it "accepts a topic or a topic id" do
|
||||
expect(TopicView.new(topic, evil_trout).topic).to eq(topic)
|
||||
expect(TopicView.new(topic.id, evil_trout).topic).to eq(topic)
|
||||
end
|
||||
|
||||
# see also spec/controllers/topics_controller_spec.rb TopicsController::show::permission errors
|
||||
it "raises an error if the user can't see the topic" do
|
||||
Guardian.any_instance.expects(:can_see?).with(topic).returns(false)
|
||||
|
|
Loading…
Reference in New Issue