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

This commit is contained in:
Bianca Nenciu 2019-01-17 04:24:32 +02:00 committed by Sam
parent e7d2a0d42f
commit 7d84648d11
5 changed files with 25 additions and 10 deletions

View File

@ -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

View File

@ -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?

View File

@ -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

View File

@ -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

View File

@ -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