Skip to content

Commit

Permalink
FEATURE: split out max diff to 2 settings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SamSaffron committed Mar 9, 2018
1 parent 9a4a742 commit 5b6e49a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config/locales/server.en.yml
Expand Up @@ -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."
Expand Down
1 change: 1 addition & 0 deletions config/site_settings.yml
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions lib/post_revisor.rb
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/components/post_revisor_spec.rb
Expand Up @@ -130,6 +130,18 @@

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
Expand Down

1 comment on commit 5b6e49a

@discoursebot
Copy link

Choose a reason for hiding this comment

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

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/store-a-real-revision-for-large-grace-period-edits/81614/27

Please sign in to comment.