Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: unconditionally omit no-follow for staff

Sam33541c409627
diff --git a/app/models/post.rb b/app/models/post.rb
index 92ed3773125..51d83227276 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -239,6 +239,7 @@ class Post < ActiveRecord::Base
end
def add_nofollow?
+ return false if user&.staff?
user.blank? || SiteSetting.tl3_links_no_follow? || !user.has_trust_level?(TrustLevel[3])
end
@@ -256,14 +257,9 @@ class Post < ActiveRecord::Base
post_user = self.user
options[:user_id] = post_user.id if post_user
+ options[:omit_nofollow] = true if omit_nofollow?
- if add_nofollow?
- cooked = post_analyzer.cook(raw, options)
- else
- # At trust level 3, we don't apply nofollow to links
- options[:omit_nofollow] = true
- cooked = post_analyzer.cook(raw, options)
- end
+ cooked = post_analyzer.cook(raw, options)
new_cooked = Plugin::Filter.apply(:after_post_cook, self, cooked)
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index 0467843dd76..6ac88dff443 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -940,6 +940,16 @@ describe Post do
describe "cooking" do
let(:post) { Fabricate.build(:post, post_args.merge(raw: "please read my blog http://blog.example.com")) }
+ it "should unconditionally follow links for staff" do
+
+ SiteSetting.tl3_links_no_follow = true
+ post.user.trust_level = 1
+ post.user.moderator = true
+ post.save
+
+ expect(post.cooked).not_to match(/nofollow/)
+ end
+
it "should add nofollow to links in the post for trust levels below 3" do
post.user.trust_level = 2
post.save