FIX: Do not show self edits in Post Edits report. (#7510)

FIX: Do not show self edits in Post Edits report. (#7510)

diff --git a/app/models/reports/post_edits.rb b/app/models/reports/post_edits.rb
index 43c039c..4d24f78 100644
--- a/app/models/reports/post_edits.rb
+++ b/app/models/reports/post_edits.rb
@@ -56,7 +56,7 @@ Report.add_report('post_edits') do |report|
   AND pr.created_at >= '#{report.start_date}'
   AND pr.created_at <= '#{report.end_date}'
   ORDER BY pr.created_at DESC
-  LIMIT 20
+  LIMIT #{report.limit || 20}
   )
   SELECT pr.editor_id,
   pr.editor_username,
@@ -83,9 +83,12 @@ Report.add_report('post_edits') do |report|
     sql += <<~SQL
     JOIN topics t
     ON t.id = p.topic_id
-    WHERE t.category_id = ? OR t.category_id IN (SELECT id FROM categories WHERE categories.parent_category_id = ?)
+    WHERE p.user_id != editor_id AND t.category_id = ? OR t.category_id IN (SELECT id FROM categories WHERE categories.parent_category_id = ?)
     SQL
+  else
+    sql += "WHERE p.user_id != editor_id"
   end
+
   result = category_filter ? DB.query(sql, category_filter, category_filter) : DB.query(sql)
 
   result.each do |r|
diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb
index 21418af..f2e78a2 100644
--- a/spec/models/report_spec.rb
+++ b/spec/models/report_spec.rb
@@ -544,6 +544,7 @@ describe Report do
       before do
         freeze_time
 
+        post.revise(post.user, { raw: 'updated body by author', edit_reason: 'not cool' }, force_new_version: true)
         post.revise(editor, raw: 'updated body', edit_reason: 'not cool')
       end

GitHub sha: 8dfb15a2

1 Like