diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb index 46457fe8fc6..c741b659d47 100644 --- a/app/jobs/regular/pull_hotlinked_images.rb +++ b/app/jobs/regular/pull_hotlinked_images.rb @@ -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 diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index 4b167976264..02b88d11738 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -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 diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb index 0f15c4b720b..a47596fe38f 100644 --- a/spec/components/post_revisor_spec.rb +++ b/spec/components/post_revisor_spec.rb @@ -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) diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb index cf3b2b4c6ee..a96e476ce73 100644 --- a/spec/jobs/pull_hotlinked_images_spec.rb +++ b/spec/jobs/pull_hotlinked_images_spec.rb @@ -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