A platform for community discussion. Free, open, simple.
FEATURE: split out max diff to 2 settings
Sam5b6e49ae1dee
diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 13b8fe4f6bf..ab0e4d714bd 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -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."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex e70c723bbf3..05662ce6ce9 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -535,6 +535,7 @@ posting:validator: "EnablePrivateEmailMessagesValidator"editing_grace_period: 300editing_grace_period_max_diff: 100+ editing_grace_period_max_diff_high_trust: 400staff_edit_locks_post: falsepost_edit_time_limit:default: 86400diff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex 7346fca6679..bed0f684fe6 100644--- a/lib/post_revisor.rb+++ b/lib/post_revisor.rb@@ -278,8 +278,14 @@ class PostRevisorreturn false if (@revised_at - @last_version_at) > SiteSetting.editing_grace_period.to_iif 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_diffreturn falseendenddiff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rbindex cf04958ff3a..4a001a9ddf0 100644--- a/spec/components/post_revisor_spec.rb+++ b/spec/components/post_revisor_spec.rb@@ -130,6 +130,18 @@ describe PostRevisor doexpect(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)+endit "doesn't create a new version" do