FIX: don't onebox hidden posts

This commit is contained in:
Neil Lalonde 2014-04-28 11:03:19 -04:00
parent 340fd303c8
commit 9fba385172
2 changed files with 7 additions and 0 deletions

View file

@ -25,6 +25,7 @@ module Onebox
# Post Link
post = Post.where(topic_id: route[:topic_id], post_number: route[:post_number].to_i).first
return linked unless post
return linked if post.hidden
return linked unless Guardian.new.can_see?(post)
topic = post.topic

View file

@ -28,6 +28,12 @@ describe Onebox::Engine::DiscourseLocalOnebox do
Onebox.preview(url).to_s.should == "<a href='#{url}'>#{url}</a>"
end
it "returns a link if post is hidden" do
hidden_post = Fabricate(:post, topic: post.topic, post_number: 2, hidden: true, hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached])
url = "#{Discourse.base_url}#{hidden_post.url}"
Onebox.preview(url).to_s.should == "<a href='#{url}'>#{url}</a>"
end
it "returns some onebox goodness if post exists and can be seen" do
url = "#{Discourse.base_url}#{post2.url}"
Guardian.any_instance.stubs(:can_see?).returns(true)