Setting to automatically lock posts when edited by staff

This commit is contained in:
Robin Ward 2018-01-26 13:45:52 -05:00
parent 6b04967e2f
commit 44e2038b53
4 changed files with 70 additions and 0 deletions

View File

@ -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."

View File

@ -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

View File

@ -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? &&
!@post.user.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

View File

@ -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