A platform for community discussion. Free, open, simple.
FIX: Do not log 'pull_hotlinked_images' edits in the staff action log
David Taylor67a98946b8b1
diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rbindex 46457fe8fc6..c741b659d47 100644--- a/app/jobs/regular/pull_hotlinked_images.rb+++ b/app/jobs/regular/pull_hotlinked_images.rb@@ -148,7 +148,7 @@ module Jobsif start_raw == post.raw && raw != post.rawchanges = { 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_imagepost.trigger_post_process(bypass_bump: true)enddiff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex 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 logdef revise!(editor, fields, opts = {})@editor = editor@fields = fields.with_indifferent_access@@ -183,7 +184,7 @@ class PostRevisorend# 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_rawdiff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rbindex 0f15c4b720b..a47596fe38f 100644--- a/spec/components/post_revisor_spec.rb+++ b/spec/components/post_revisor_spec.rb@@ -494,6 +494,19 @@ describe PostRevisor doexpect(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" dorevisor = PostRevisor.new(Fabricate(:post, user: moderator)diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rbindex 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 doexpect doJobs::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 logexpect(post.reload.raw).to eq("")end