FEATURE: Remove full quotes only from new posts. (#6862)

FEATURE: Remove full quotes only from new posts. (#6862)

diff --git a/app/jobs/regular/process_post.rb b/app/jobs/regular/process_post.rb
index 6c8b4e7..ef06ea5 100644
--- a/app/jobs/regular/process_post.rb
+++ b/app/jobs/regular/process_post.rb
@@ -21,7 +21,7 @@ module Jobs
       end
 
       cp = CookedPostProcessor.new(post, args)
-      cp.post_process(args[:bypass_bump])
+      cp.post_process(bypass_bump: args[:bypass_bump], new_post: args[:new_post])
 
       # If we changed the document, save it
       cooked = cp.html
diff --git a/app/models/post.rb b/app/models/post.rb
index 19d093d..329ed66 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -690,10 +690,11 @@ class Post < ActiveRecord::Base
   end
 
   # Enqueue post processing for this post
-  def trigger_post_process(bypass_bump: false, priority: :normal)
+  def trigger_post_process(bypass_bump: false, priority: :normal, new_post: false)
     args = {
       post_id: id,
       bypass_bump: bypass_bump,
+      new_post: new_post,
     }
     args[:image_sizes] = image_sizes if image_sizes.present?
     args[:invalidate_oneboxes] = true if invalidate_oneboxes.present?
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index 9ab9ca6..01c639b 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -33,10 +33,10 @@ class CookedPostProcessor
     @disable_loading_image = !!opts[:disable_loading_image]
   end
 
-  def post_process(bypass_bump = false)
+  def post_process(bypass_bump: false, new_post: false)
     DistributedMutex.synchronize("post_process_#{@post.id}") do
       DiscourseEvent.trigger(:before_post_process_cooked, @doc, @post)
-      removed_direct_reply_full_quotes
+      removed_direct_reply_full_quotes if new_post
       post_process_oneboxes
       post_process_images
       post_process_quotes
diff --git a/lib/post_jobs_enqueuer.rb b/lib/post_jobs_enqueuer.rb
index 4dde3b7..cbcd686 100644
--- a/lib/post_jobs_enqueuer.rb
+++ b/lib/post_jobs_enqueuer.rb
@@ -38,7 +38,7 @@ class PostJobsEnqueuer
   end
 
   def trigger_post_post_process
-    @post.trigger_post_process
+    @post.trigger_post_process(new_post: true)
   end
 
   def after_post_create
diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index 9e2628a..ebca1f0 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -1170,7 +1170,7 @@ describe CookedPostProcessor do
     let!(:post) { Fabricate(:post, topic: topic, raw: "this is the first post") }
 
     let(:raw) do
-      <<~RAW
+      <<~RAW.strip
       [quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
       this is the first post
       [/quote]
@@ -1180,7 +1180,7 @@ describe CookedPostProcessor do
     end
 
     let(:raw2) do
-      <<~RAW
+      <<~RAW.strip
       and this is the third reply
 
       [quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
@@ -1189,9 +1189,11 @@ describe CookedPostProcessor do
       RAW
     end
 
-    it 'works' do
+    before do
       SiteSetting.remove_full_quote = true
+    end
 
+    it 'works' do
       hidden = Fabricate(:post, topic: topic, hidden: true, raw: "this is the second post after")
       small_action = Fabricate(:post, topic: topic, post_type: Post.types[:small_action])
       reply = Fabricate(:post, topic: topic, raw: raw)
@@ -1210,8 +1212,6 @@ describe CookedPostProcessor do
     end
 
     it 'does not delete quote if not first paragraph' do
-      SiteSetting.remove_full_quote = true
-
       reply = Fabricate(:post, topic: topic, raw: raw2)
       CookedPostProcessor.new(reply).removed_direct_reply_full_quotes
       expect(topic.posts).to eq([post, reply])
@@ -1227,6 +1227,20 @@ describe CookedPostProcessor do
       expect(reply.raw).to eq(raw)
     end
 
+    it "works only on new posts" do
+      hidden = Fabricate(:post, topic: topic, hidden: true, raw: "this is the second post after")
+      small_action = Fabricate(:post, topic: topic, post_type: Post.types[:small_action])
+      Jobs.stubs(:enqueue) { |job, args| CookedPostProcessor.new(reply).post_process(new_post: args[:new_post]) if job == :process_post }
+
+      reply = PostCreator.create!(topic.user, topic_id: topic.id, raw: raw)
+      CookedPostProcessor.new(reply).post_process
+      expect(reply.raw).to eq(raw)
+
+      PostRevisor.new(reply).revise!(Discourse.system_user, raw: raw, edit_reason: "put back full quote")
+      CookedPostProcessor.new(reply).post_process(new_post: true)
+      expect(reply.raw).to eq("and this is the third reply")
+    end
+
   end
 
 end

GitHub sha: 7d84648d

Hmm do we need to use a stub here instead of just setting SiteSetting.queue_jobs = false?

Nope, we should simply stop job queueing. That stub is fragile.

Removed the job stub in b1b8c37.

4 Likes