From 5b6e49ae1dee184b2b26b23426af6295f8d6fe27 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 9 Mar 2018 11:58:50 +1100 Subject: [PATCH] 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. --- config/locales/server.en.yml | 3 ++- config/site_settings.yml | 1 + lib/post_revisor.rb | 10 ++++++++-- spec/components/post_revisor_spec.rb | 12 ++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 13b8fe4f6bf93f..ab0e4d714bd753 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.yml index e70c723bbf30a3..05662ce6ce962d 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -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 diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index 7346fca6679a3a..bed0f684fe6365 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -278,8 +278,14 @@ def ninja_edit? 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 diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb index cf04958ff3aa22..4a001a9ddf0ddf 100644 --- a/spec/components/post_revisor_spec.rb +++ b/spec/components/post_revisor_spec.rb @@ -130,6 +130,18 @@ expect(post.revisions.first.modifications["raw"][0]).to eq("hello world") expect(post.revisions.first.modifications["cooked"][0]).to eq("

hello world

") + + 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