FIX: Group mentions missing after post processing.

This commit is contained in:
Guo Xiang Tan 2018-11-26 12:57:07 +08:00
parent 0972516abe
commit 482013a1d4
3 changed files with 9 additions and 25 deletions

View File

@ -18,13 +18,10 @@ class CookedPostProcessor
# NOTE: we re-cook the post here in order to prevent timing issues with edits
# cf. https://meta.discourse.org/t/edit-of-rebaked-post-doesnt-show-in-html-only-in-raw/33815/6
@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?
@cooking_options[:cook_method] = post.cook_method
analyzer = post.post_analyzer
@doc = Nokogiri::HTML::fragment(analyzer.cook(post.raw, @cooking_options))
@doc = Nokogiri::HTML::fragment(post.cook(post.raw, @cooking_options))
@has_oneboxes = analyzer.found_oneboxes?
@size_cache = {}
end

View File

@ -2,7 +2,6 @@ require "rails_helper"
require "cooked_post_processor"
describe CookedPostProcessor do
context "#post_process" do
let(:upload) do
Fabricate(:upload,
@ -163,26 +162,6 @@ 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 "#post_process_images" do
before do

View File

@ -977,9 +977,15 @@ describe Post do
)
end
before do
SiteSetting.queue_jobs = false
end
describe 'when user can not mention a group' do
it "should not create the mention" do
post = Fabricate(:post, raw: "hello @#{group.name}")
post.trigger_post_process
post.reload
expect(post.cooked).to eq(
%Q|<p>hello <span class="mention">@#{group.name}</span></p>|
@ -994,6 +1000,8 @@ describe Post do
it 'should create the mention' do
post.update!(raw: "hello @#{group.name}")
post.trigger_post_process
post.reload
expect(post.cooked).to eq(
%Q|<p>hello <a class="mention-group" href="/groups/#{group.name}">@#{group.name}</a></p>|