FIX: Do not log 'pull_hotlinked_images' edits in the staff action log

This commit is contained in:
David Taylor 2019-09-12 15:55:45 +01:00
parent e4b813df4c
commit 67a98946b8
4 changed files with 18 additions and 3 deletions

View File

@ -148,7 +148,7 @@ module Jobs
if start_raw == post.raw && raw != post.raw
changes = { raw: raw, edit_reason: I18n.t("upload.edit_reason") }
post.revise(Discourse.system_user, changes, bypass_bump: true)
post.revise(Discourse.system_user, changes, bypass_bump: true, skip_staff_log: true)
elsif has_downloaded_image || has_new_large_image || has_new_broken_image
post.trigger_post_process(bypass_bump: true)
end

View File

@ -116,6 +116,7 @@ class PostRevisor
# - bypass_bump: do not bump the topic, even if last post
# - skip_validations: ask ActiveRecord to skip validations
# - skip_revision: do not create a new PostRevision record
# - skip_staff_log: skip creating an entry in the staff action log
def revise!(editor, fields, opts = {})
@editor = editor
@fields = fields.with_indifferent_access
@ -183,7 +184,7 @@ class PostRevisor
end
# We log staff edits to posts
if @editor.staff? && @editor.id != @post.user.id && @fields.has_key?('raw')
if @editor.staff? && @editor.id != @post.user.id && @fields.has_key?('raw') && !@opts[:skip_staff_log]
StaffActionLogger.new(@editor).log_post_edit(
@post,
old_raw: old_raw

View File

@ -494,6 +494,19 @@ describe PostRevisor do
expect(log.details).to eq("Hello world\n\n---\n\nlets totally update the body")
end
it "doesn't log an edit when skip_staff_log is true" do
subject.revise!(
moderator,
{ raw: "lets totally update the body" },
skip_staff_log: true
)
log = UserHistory.where(
acting_user_id: moderator.id,
action: UserHistory.actions[:post_edit]
).first
expect(log).to be_blank
end
it "doesn't log an edit when a staff member edits their own post" do
revisor = PostRevisor.new(
Fabricate(:post, user: moderator)

View File

@ -51,7 +51,8 @@ describe Jobs::PullHotlinkedImages do
expect do
Jobs::PullHotlinkedImages.new.execute(post_id: post.id)
end.to change { Upload.count }.by(1)
end.to change { Upload.count }.by(1) &
change { UserHistory.count }.by(0) # Should not add to the staff log
expect(post.reload.raw).to eq("![](#{Upload.last.short_url})")
end