FIX: Don't trigger a spam check when a post is edited by a staff member. (#35)

FIX: Don’t trigger a spam check when a post is edited by a staff member. (#35)

diff --git a/plugin.rb b/plugin.rb
index a7e6401..cd2383b 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -80,7 +80,10 @@ after_initialize do
 
   on(:post_edited) do |post, _, _|
     bouncer = DiscourseAkismet::PostsBouncer.new
-    check_post(bouncer, post) if bouncer.should_check?(post)
+
+    if post.last_editor.regular? && bouncer.should_check?(post)
+      check_post(bouncer, post)
+    end
   end
 
   on(:post_recovered) do |post, _, _|
diff --git a/spec/plugin_spec.rb b/spec/plugin_spec.rb
index 4c0d9ff..784e5e8 100644
--- a/spec/plugin_spec.rb
+++ b/spec/plugin_spec.rb
@@ -44,6 +44,24 @@ describe 'plugin' do
     expect(post.reload.custom_fields[DiscourseAkismet::Bouncer::AKISMET_STATE]).to eq('confirmed_spam')
   end
 
+  it 'skips posts edited by a staff member' do
+    Jobs.run_immediately!
+
+    post_creator = PostCreator.new(user_tl0, raw: 'this is the new content for my topic', title: 'this is my new topic title')
+
+    stub_request(:post, 'https://akismetkey.rest.akismet.com/1.1/comment-check')
+      .to_return({ status: 200, body: 'false' }, { status: 200, body: 'true' })
+
+    # Check original raw
+    post = post_creator.create
+    expect(post.custom_fields[DiscourseAkismet::Bouncer::AKISMET_STATE]).to eq('pending')
+    expect(post.reload.custom_fields[DiscourseAkismet::Bouncer::AKISMET_STATE]).to eq('confirmed_ham')
+
+    # Check edited raw
+    PostRevisor.new(post).revise!(admin, raw: post.raw + 'more text by staff member')
+    expect(post.reload.custom_fields[DiscourseAkismet::Bouncer::AKISMET_STATE]).to eq('confirmed_ham')
+  end
+
   it 'queues recovered posts that were skipped' do
     post_creator = PostCreator.new(user_tl0, raw: 'this is the new content for my topic', title: 'this is my new topic title')
 

GitHub sha: 4d83f8a52806dea10b7c8be14ca22a60181e7e27

This commit appears in #35 which was approved by ZogStriP. It was merged by romanrizzi.