A platform for community discussion. Free, open, simple.
FIX: oneboxing to private messages
Sam57e140dc0732
diff --git a/lib/oneboxer.rb b/lib/oneboxer.rbindex 533a5f08c00..6c3027f17d7 100644--- a/lib/oneboxer.rb+++ b/lib/oneboxer.rb@@ -173,8 +173,11 @@ module Oneboxerif route[:post_number].to_i > 1post = Post.find_by(topic_id: route[:topic_id], post_number: route[:post_number])- return unless post.present? && !post.hidden- return unless current_category&.id == post.topic.category_id || Guardian.new.can_see_post?(post)+ return if !post || post.hidden || post.topic.private_message?++ if current_category&.id != post.topic.category_id+ return if !Guardian.new.can_see_post?(post)+ endtopic = post.topicexcerpt = post.excerpt(SiteSetting.post_onebox_maxlength)@@ -185,8 +188,13 @@ module OneboxerPrettyText.cook(quote)else- return unless topic = Topic.find_by(id: route[:topic_id])- return unless current_category&.id == topic.category_id || Guardian.new.can_see_topic?(topic)+ topic = Topic.find_by(id: route[:topic_id])++ return if !topic || topic.private_message?++ if current_category&.id != topic.category_id+ return if !Guardian.new.can_see_topic?(topic)+ endfirst_post = topic.ordered_posts.firstdiff --git a/spec/controllers/onebox_controller_spec.rb b/spec/controllers/onebox_controller_spec.rbindex def998a6acc..b53090ec28a 100644--- a/spec/controllers/onebox_controller_spec.rb+++ b/spec/controllers/onebox_controller_spec.rb@@ -129,6 +129,16 @@ describe OneboxController doexpect(response.body).not_to include('blockquote')end+ it 'does not allow onebox of PMs' do+ user = log_in++ post = create_post(archetype: 'private_message', target_usernames: [user.username])+ url = Discourse.base_url + post.url++ get :show, params: { url: url }, format: :json+ expect(response.body).not_to include('blockquote')+ end+it 'allows onebox to public topics/posts in PM' dolog_in