mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:09:00 +08:00
FEATURE: split out max diff to 2 settings
We trust staff + tl2 and up to perform edits in grace period. Allow them significantly more edit room in grace period prior to storing a revision. editing_grace_period_max_diff_high_trust applies to users with tl2 and up. So tl0 / 1 : we store an extra revision if more than 100 chars change tl2 and up : we store an extra revision if more than 400 chars change We may tweak these numbers as we go.
This commit is contained in:
parent
9a4a7422f5
commit
5b6e49ae1d
|
@ -1023,7 +1023,8 @@ en:
|
|||
download_remote_images_max_days_old: "Don't download remote images for posts that are more than n days old."
|
||||
disabled_image_download_domains: "Remote images will never be downloaded from these domains. Pipe-delimited list."
|
||||
editing_grace_period: "For (n) seconds after posting, editing will not create a new version in the post history."
|
||||
editing_grace_period_max_diff: "Maximum number of character changes allowed in editing grace period, if more changed store another post revision"
|
||||
editing_grace_period_max_diff: "Maximum number of character changes allowed in editing grace period, if more changed store another post revision (trust level 0 and 1)"
|
||||
editing_grace_period_max_diff_high_trust: "Maximum number of character changes allowed in editing grace period, if more changed store another post revision (trust level 2 and up)"
|
||||
staff_edit_locks_post: "Posts will be locked from editing if they are edited by staff members"
|
||||
post_edit_time_limit: "The author can edit or delete their post for (n) minutes after posting. Set to 0 for forever."
|
||||
edit_history_visible_to_public: "Allow everyone to see previous versions of an edited post. When disabled, only staff members can view."
|
||||
|
|
|
@ -535,6 +535,7 @@ posting:
|
|||
validator: "EnablePrivateEmailMessagesValidator"
|
||||
editing_grace_period: 300
|
||||
editing_grace_period_max_diff: 100
|
||||
editing_grace_period_max_diff_high_trust: 400
|
||||
staff_edit_locks_post: false
|
||||
post_edit_time_limit:
|
||||
default: 86400
|
||||
|
|
|
@ -278,8 +278,14 @@ class PostRevisor
|
|||
return false if (@revised_at - @last_version_at) > SiteSetting.editing_grace_period.to_i
|
||||
|
||||
if new_raw = @fields[:raw]
|
||||
if (original_raw.length - new_raw.length).abs > SiteSetting.editing_grace_period_max_diff.to_i ||
|
||||
diff_size(original_raw, new_raw) > SiteSetting.editing_grace_period_max_diff.to_i
|
||||
|
||||
max_diff = SiteSetting.editing_grace_period_max_diff.to_i
|
||||
if @editor.staff? || (@editor.trust_level > 1)
|
||||
max_diff = SiteSetting.editing_grace_period_max_diff_high_trust.to_i
|
||||
end
|
||||
|
||||
if (original_raw.length - new_raw.length).abs > max_diff ||
|
||||
diff_size(original_raw, new_raw) > max_diff
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -130,6 +130,18 @@ describe PostRevisor do
|
|||
|
||||
expect(post.revisions.first.modifications["raw"][0]).to eq("hello world")
|
||||
expect(post.revisions.first.modifications["cooked"][0]).to eq("<p>hello world</p>")
|
||||
|
||||
SiteSetting.editing_grace_period_max_diff_high_trust = 100
|
||||
|
||||
post.user.update_columns(trust_level: 2)
|
||||
|
||||
revisor = PostRevisor.new(post)
|
||||
revisor.revise!(post.user, { raw: 'hello world12345678901 123456789012' }, revised_at: post.updated_at + 1.second)
|
||||
|
||||
post.reload
|
||||
expect(post.version).to eq(2)
|
||||
expect(post.revisions.count).to eq(1)
|
||||
|
||||
end
|
||||
|
||||
it "doesn't create a new version" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user