mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
FIX: nofollow
was being added during post processing when it shouldn't
This commit is contained in:
parent
7427209f21
commit
aef954784a
|
@ -188,6 +188,14 @@ class Post < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def add_nofollow?
|
||||
return user.blank? || SiteSetting.tl3_links_no_follow? || !user.has_trust_level?(TrustLevel[3])
|
||||
end
|
||||
|
||||
def omit_nofollow?
|
||||
return !add_nofollow?
|
||||
end
|
||||
|
||||
def cook(*args)
|
||||
# For some posts, for example those imported via RSS, we support raw HTML. In that
|
||||
# case we can skip the rendering pipeline.
|
||||
|
@ -203,7 +211,7 @@ class Post < ActiveRecord::Base
|
|||
post_user = self.user
|
||||
cloned[1][:user_id] = post_user.id if post_user
|
||||
|
||||
cooked = if !post_user || SiteSetting.tl3_links_no_follow || !post_user.has_trust_level?(TrustLevel[3])
|
||||
cooked = if add_nofollow?
|
||||
post_analyzer.cook(*args)
|
||||
else
|
||||
# At trust level 3, we don't apply nofollow to links
|
||||
|
|
|
@ -7,6 +7,8 @@ require_dependency 'pretty_text'
|
|||
class CookedPostProcessor
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
attr_reader :cooking_options
|
||||
|
||||
def initialize(post, opts={})
|
||||
@dirty = false
|
||||
@opts = opts
|
||||
|
@ -17,6 +19,7 @@ class CookedPostProcessor
|
|||
@cooking_options = post.cooking_options || opts[:cooking_options] || {}
|
||||
@cooking_options[:topic_id] = post.topic_id
|
||||
@cooking_options = @cooking_options.symbolize_keys
|
||||
@cooking_options[:omit_nofollow] = true if post.omit_nofollow?
|
||||
|
||||
analyzer = post.post_analyzer
|
||||
@doc = Nokogiri::HTML::fragment(analyzer.cook(post.raw, @cooking_options))
|
||||
|
|
|
@ -20,6 +20,26 @@ describe CookedPostProcessor do
|
|||
|
||||
end
|
||||
|
||||
context "cooking options" do
|
||||
context "regular user" do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
it "doesn't omit nofollow" do
|
||||
cpp = CookedPostProcessor.new(post)
|
||||
expect(cpp.cooking_options[:omit_nofollow]).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "admin user" do
|
||||
let(:post) { Fabricate(:post, user: Fabricate(:admin) ) }
|
||||
|
||||
it "omits nofollow" do
|
||||
cpp = CookedPostProcessor.new(post)
|
||||
expect(cpp.cooking_options[:omit_nofollow]).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".keep_reverse_index_up_to_date" do
|
||||
|
||||
let(:post) { build(:post_with_uploads, id: 123) }
|
||||
|
|
Loading…
Reference in New Issue
Block a user