mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: nofollow
was being added during post processing when it shouldn't
This commit is contained in:
parent
7427209f21
commit
aef954784a
3 changed files with 32 additions and 1 deletions
|
@ -188,6 +188,14 @@ class Post < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
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)
|
def cook(*args)
|
||||||
# For some posts, for example those imported via RSS, we support raw HTML. In that
|
# For some posts, for example those imported via RSS, we support raw HTML. In that
|
||||||
# case we can skip the rendering pipeline.
|
# case we can skip the rendering pipeline.
|
||||||
|
@ -203,7 +211,7 @@ class Post < ActiveRecord::Base
|
||||||
post_user = self.user
|
post_user = self.user
|
||||||
cloned[1][:user_id] = post_user.id if post_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)
|
post_analyzer.cook(*args)
|
||||||
else
|
else
|
||||||
# At trust level 3, we don't apply nofollow to links
|
# At trust level 3, we don't apply nofollow to links
|
||||||
|
|
|
@ -7,6 +7,8 @@ require_dependency 'pretty_text'
|
||||||
class CookedPostProcessor
|
class CookedPostProcessor
|
||||||
include ActionView::Helpers::NumberHelper
|
include ActionView::Helpers::NumberHelper
|
||||||
|
|
||||||
|
attr_reader :cooking_options
|
||||||
|
|
||||||
def initialize(post, opts={})
|
def initialize(post, opts={})
|
||||||
@dirty = false
|
@dirty = false
|
||||||
@opts = opts
|
@opts = opts
|
||||||
|
@ -17,6 +19,7 @@ class CookedPostProcessor
|
||||||
@cooking_options = post.cooking_options || opts[:cooking_options] || {}
|
@cooking_options = post.cooking_options || opts[:cooking_options] || {}
|
||||||
@cooking_options[:topic_id] = post.topic_id
|
@cooking_options[:topic_id] = post.topic_id
|
||||||
@cooking_options = @cooking_options.symbolize_keys
|
@cooking_options = @cooking_options.symbolize_keys
|
||||||
|
@cooking_options[:omit_nofollow] = true if post.omit_nofollow?
|
||||||
|
|
||||||
analyzer = post.post_analyzer
|
analyzer = post.post_analyzer
|
||||||
@doc = Nokogiri::HTML::fragment(analyzer.cook(post.raw, @cooking_options))
|
@doc = Nokogiri::HTML::fragment(analyzer.cook(post.raw, @cooking_options))
|
||||||
|
|
|
@ -20,6 +20,26 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
end
|
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
|
context ".keep_reverse_index_up_to_date" do
|
||||||
|
|
||||||
let(:post) { build(:post_with_uploads, id: 123) }
|
let(:post) { build(:post_with_uploads, id: 123) }
|
||||||
|
|
Loading…
Reference in a new issue