FIX: Group mentions missing after post processing.

FIX: Group mentions missing after post processing.

From 482013a1d4060e69cf78773892f13ef2d8220742 Mon Sep 17 00:00:00 2001
From: Guo Xiang Tan <tgx_world@hotmail.com>
Date: Mon, 26 Nov 2018 12:57:07 +0800
Subject: [PATCH] FIX: Group mentions missing after post processing.


diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index 6a604a3..df346bb 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -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
diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index 6ad6b48..fe0fcb4 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -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
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index 532781d..dce8391 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -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>|

GitHub

I see we are removing topic_id from cooking_options, is it no longer needed?

Also found_onboxes? is no longer going to work cause after that post.cook you no longer have access to the original analyzer used. Ahh … I see … post_analyzer is cached on post …

we should amend this code so its less confusing…

@doc = Nokogiri::HTML::fragment(post.cook(post.raw, @cooking_options))
@has_oneboxes = post.post_analyzer.found_oneboxes?

At least that is a bit less magical…

Also does this mean we are triggering after_post_cooked an extra time in the post processor … so many questions.

Nope in fact it was a bug that we were not triggering after_post_cooked.

Saw the followup, looks good, but I still want you to change it so we don’t hold a local ref to post_analyzer, cause it is pretty confusing the way the code looks now.