From fcaf0f5b3b251a97b34226af57899335ea1146b4 Mon Sep 17 00:00:00 2001 From: romanrizzi Date: Thu, 24 Sep 2020 14:41:35 -0300 Subject: [PATCH] FIX: Perform a toxicity check after a post gets edited. We need to check for toxicity after editing to prevent users from posting toxic content after the original post gets created. --- plugin.rb | 6 ++++++ spec/plugin_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 spec/plugin_spec.rb diff --git a/plugin.rb b/plugin.rb index 25db4da..78bf9b4 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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" diff --git a/spec/plugin_spec.rb b/spec/plugin_spec.rb new file mode 100644 index 0000000..9a01499 --- /dev/null +++ b/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