Skip to content

A platform for community discussion. Free, open, simple.

Setting to automatically lock posts when edited by staff

Robin Ward44e2038b5343
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 88260a1b8f0..d698d82fbab 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -995,6 +995,7 @@ 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."
+ 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."
delete_removed_posts_after: "Posts removed by the author will be automatically deleted after (n) hours. If set to 0, posts will be deleted immediately."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index d238ebbea01..e02399e1515 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -514,6 +514,7 @@ posting:
client: true
validator: "EnablePrivateEmailMessagesValidator"
editing_grace_period: 300
+ staff_edit_locks_post: false
post_edit_time_limit:
default: 86400
max: 525600
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index a6b1623e8d1..6e0c35c6ba9 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -1,4 +1,5 @@
require "edit_rate_limiter"
+require 'post_locker'
class PostRevisor
@@ -163,6 +164,13 @@ class PostRevisor
advance_draft_sequence
end
+ # Lock the post by default if the appropriate setting is true
+ if SiteSetting.staff_edit_locks_post? &&
+ @editor.staff? &&
+ PostLocker.new(@post, @editor).lock
+ end
+
# WARNING: do not pull this into the transaction
# it can fire events in sidekiq before the post is done saving
# leading to corrupt state
diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb
index 7f0f950add2..44d26f91076 100644
--- a/spec/components/post_revisor_spec.rb
+++ b/spec/components/post_revisor_spec.rb
@@ -391,6 +391,66 @@ describe PostRevisor do
end
end
+ context "staff_edit_locks_post" do
+
+ context "disabled" do
+ before do
+ SiteSetting.staff_edit_locks_post = false
+ end
+
+ it "does not lock the post when revised" do
+ result = subject.revise!(
+ Fabricate(:moderator),
+ raw: "lets totally update the body"
+ )
+ expect(result).to eq(true)
+ post.reload
+ expect(post).not_to be_locked
+ end
+ end
+
+ context "enabled" do
+ let(:moderator) { Fabricate(:moderator) }
+
+ before do
+ SiteSetting.staff_edit_locks_post = true
+ end
+
+ it "locks the post when revised by staff" do
+ result = subject.revise!(
+ moderator,
+ raw: "lets totally update the body"
+ )
+ expect(result).to eq(true)
+ post.reload
+ expect(post).to be_locked
+ end
+
+ it "doesn't lock the post when revised by a regular user" do
+ result = subject.revise!(
+ Fabricate(:user),
+ raw: "lets totally update the body"
+ )
+ expect(result).to eq(true)
+ post.reload
+ expect(post).not_to be_locked
+ end
+
+ it "doesn't lock a staff member's post" do
+ staff_post = Fabricate(:post, user: moderator)
+ revisor = PostRevisor.new(staff_post)
+
+ result = revisor.revise!(
+ moderator,
+ raw: "lets totally update the body"
+ )
+ expect(result).to eq(true)
+ staff_post.reload
+ expect(staff_post).not_to be_locked
+ end
+ end
+ end
+
context "tagging" do
context "tagging disabled" do
before do