* FEATURE: Adds site setting to let quotes on direct replies.

* DEV: Added test.
* FIX: Do not bump topic when removing full quotes.
This commit is contained in:
Bianca Nenciu 2018-12-12 16:42:53 +02:00 committed by Régis Hanol
parent dbbadb5c35
commit 7cac04e1a8
4 changed files with 38 additions and 18 deletions

View File

@ -1308,6 +1308,7 @@ en:
send_tl1_welcome_message: "Send new trust level 1 users a welcome message." send_tl1_welcome_message: "Send new trust level 1 users a welcome message."
suppress_reply_directly_below: "Don't show the expandable reply count on a post when there is only a single reply directly below this post." suppress_reply_directly_below: "Don't show the expandable reply count on a post when there is only a single reply directly below this post."
suppress_reply_directly_above: "Don't show the expandable in-reply-to on a post when there is only a single reply directly above this post." suppress_reply_directly_above: "Don't show the expandable in-reply-to on a post when there is only a single reply directly above this post."
remove_full_quote: "Automatically remove full quotes on direct replies."
suppress_reply_when_quoting: "Don't show the expandable in-reply-to on a post when post quotes reply." suppress_reply_when_quoting: "Don't show the expandable in-reply-to on a post when post quotes reply."
max_reply_history: "Maximum number of replies to expand when expanding in-reply-to" max_reply_history: "Maximum number of replies to expand when expanding in-reply-to"
topics_per_period_in_top_summary: "Number of top topics shown in the default top topics summary." topics_per_period_in_top_summary: "Number of top topics shown in the default top topics summary."

View File

@ -675,6 +675,8 @@ posting:
default: true default: true
suppress_reply_when_quoting: suppress_reply_when_quoting:
default: true default: true
remove_full_quote:
default: true
max_reply_history: max_reply_history:
default: 1 default: 1
client: true client: true

View File

@ -87,7 +87,7 @@ class CookedPostProcessor
end end
def removed_direct_reply_full_quotes def removed_direct_reply_full_quotes
return if @post.post_number == 1 return if !SiteSetting.remove_full_quote || @post.post_number == 1
num_quotes = @doc.css("aside.quote").size num_quotes = @doc.css("aside.quote").size
return if num_quotes != 1 return if num_quotes != 1
@ -104,7 +104,8 @@ class CookedPostProcessor
raw: new_raw.strip, raw: new_raw.strip,
edit_reason: I18n.t(:removed_direct_reply_full_quotes) edit_reason: I18n.t(:removed_direct_reply_full_quotes)
}, },
skip_validations: true skip_validations: true,
bypass_bump: true
) )
end end

View File

@ -1146,29 +1146,45 @@ describe CookedPostProcessor do
context "remove direct reply full quote" do context "remove direct reply full quote" do
let(:topic) { Fabricate(:topic) } let(:topic) { Fabricate(:topic) }
let!(:post) { Fabricate(:post, topic: topic, raw: "this is the first post") }
it 'works' do let(:raw) do
post = Fabricate(:post, topic: topic, raw: "this is the first post") <<~RAW
hidden = Fabricate(:post, topic: topic, hidden: true, raw: "this is the second post")
small_action = Fabricate(:post, topic: topic, post_type: Post.types[:small_action])
raw = <<~RAW
[quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"] [quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
this is the first post this is the first post
[/quote] [/quote]
and this is the third reply and this is the third reply
RAW RAW
end
it 'works' do
SiteSetting.remove_full_quote = true
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) reply = Fabricate(:post, topic: topic, raw: raw)
cpp = CookedPostProcessor.new(reply) freeze_time Time.zone.now do
cpp.removed_direct_reply_full_quotes topic.bumped_at = 1.day.ago
CookedPostProcessor.new(reply).removed_direct_reply_full_quotes
expect(topic.posts).to eq([post, hidden, small_action, reply]) expect(topic.posts).to eq([post, hidden, small_action, reply])
expect(topic.bumped_at).to eq(1.day.ago)
expect(reply.raw).to eq("and this is the third reply") expect(reply.raw).to eq("and this is the third reply")
expect(reply.revisions.count).to eq(1) expect(reply.revisions.count).to eq(1)
expect(reply.revisions.first.modifications["raw"]).to eq([raw, reply.raw]) expect(reply.revisions.first.modifications["raw"]).to eq([raw, reply.raw])
expect(reply.revisions.first.modifications["edit_reason"][1]).to eq(I18n.t(:removed_direct_reply_full_quotes)) expect(reply.revisions.first.modifications["edit_reason"][1]).to eq(I18n.t(:removed_direct_reply_full_quotes))
end end
end
it "does nothing when 'remove_full_quote' is disabled" do
SiteSetting.remove_full_quote = false
reply = Fabricate(:post, topic: topic, raw: raw)
CookedPostProcessor.new(reply).removed_direct_reply_full_quotes
expect(reply.raw).to eq(raw)
end
end end