Skip to content

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

FIX: Not logging old post contents properly

Robin Ward135195363b37
diff --git a/app/services/staff_action_logger.rb b/app/services/staff_action_logger.rb
index 57ee6c20be9..4fd88f3b587 100644
--- a/app/services/staff_action_logger.rb
+++ b/app/services/staff_action_logger.rb
@@ -108,7 +108,7 @@ class StaffActionLogger
UserHistory.create!(params(opts).merge(
action: UserHistory.actions[:post_edit],
post_id: post.id,
- details: "#{post.raw}\n\n---\n\n#{opts[:new_raw]}"
+ details: "#{opts[:old_raw]}\n\n---\n\n#{post.raw}"
))
end
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index 38b5c56a452..5a5af07376a 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -150,6 +150,8 @@ class PostRevisor
@skip_revision = false
@skip_revision = @opts[:skip_revision] if @opts.has_key?(:skip_revision)
+ old_raw = @post.raw
+
Post.transaction do
revise_post
@@ -181,7 +183,7 @@ class PostRevisor
if @editor.staff? && @editor.id != @post.user.id && @fields.has_key?('raw')
StaffActionLogger.new(@editor).log_post_edit(
@post,
- new_raw: @fields['raw']
+ old_raw: old_raw
)
end
diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb
index 0beddbe6c87..77837631329 100644
--- a/spec/components/post_revisor_spec.rb
+++ b/spec/components/post_revisor_spec.rb
@@ -460,8 +460,9 @@ describe PostRevisor do
log = UserHistory.where(
acting_user_id: moderator.id,
action: UserHistory.actions[:post_edit]
- )
+ ).first
expect(log).to be_present
+ expect(log.details).to eq("Hello world\n\n---\n\nlets totally update the body")
end
it "doesn't log an edit when a staff member edits their own post" do