Skip to content

Commit

Permalink
FIX: Perform a toxicity check after a post gets edited.
Browse files Browse the repository at this point in the history
We need to check for toxicity after editing to prevent users from posting toxic content after the original post gets created.
  • Loading branch information
romanrizzi committed Sep 24, 2020
1 parent 1885cae commit fcaf0f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugin.rb
Expand Up @@ -24,6 +24,12 @@
end
end

on(:post_edited) do |post|
if SiteSetting.perspective_flag_post_min_toxicity_enable? && DiscoursePerspective.should_check_post?(post)
Jobs.enqueue(:flag_toxic_post, post_id: post.id)
end
end

register_post_custom_field_type(DiscoursePerspective.post_score_field_name, :float)

require_dependency "application_controller"
Expand Down
23 changes: 23 additions & 0 deletions spec/plugin_spec.rb
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'rails_helper'

describe 'scanning posts using the porspective API' do

before do
SiteSetting.perspective_enabled = true
end

describe 'when a post is edited' do
let(:post) { Fabricate(:post) }

it 'queues the post for a toxicity check' do
expect {
PostRevisor.new(post).revise!(
post.user,
{ raw: 'updated body' }
)
}.to change(Jobs::FlagToxicPost.jobs, :size).by(1)
end
end
end

0 comments on commit fcaf0f5

Please sign in to comment.