Skip to content

Commit

Permalink
FEATURE: Remove full quotes only from new posts. (#6862)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbianca authored and SamSaffron committed Jan 17, 2019
1 parent e7d2a0d commit 7d84648
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/jobs/regular/process_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def execute(args)
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
Expand Down
3 changes: 2 additions & 1 deletion app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,11 @@ def save_reply_relationships
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?
Expand Down
4 changes: 2 additions & 2 deletions lib/cooked_post_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def initialize(post, opts = {})
@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
Expand Down
2 changes: 1 addition & 1 deletion lib/post_jobs_enqueuer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def feature_topic_users
end

def trigger_post_post_process
@post.trigger_post_process
@post.trigger_post_process(new_post: true)
end

def after_post_create
Expand Down
24 changes: 19 additions & 5 deletions spec/components/cooked_post_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@
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]
Expand All @@ -1180,7 +1180,7 @@
end

let(:raw2) do
<<~RAW
<<~RAW.strip
and this is the third reply
[quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
Expand All @@ -1189,9 +1189,11 @@
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)
Expand All @@ -1210,8 +1212,6 @@
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])
Expand All @@ -1227,6 +1227,20 @@
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 }

This comment has been minimized.

Copy link
@tgxworld

tgxworld Jan 17, 2019

Contributor

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

This comment has been minimized.

Copy link
@SamSaffron

SamSaffron Jan 17, 2019

Member

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


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

1 comment on commit 7d84648

@nbianca
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the job stub in b1b8c37.

Please sign in to comment.