A platform for community discussion. Free, open, simple.
FIX: Sensitivity did not work by default
Robin Ward3c6a5836c204
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rbindex dd7be14eb37..6fa2eccb6c2 100644--- a/app/models/reviewable.rb+++ b/app/models/reviewable.rb@@ -78,6 +78,12 @@ class Reviewable < ActiveRecord::Base)end+ # This number comes from looking at forums in the wild and what numbers work.+ # As the site accumulates real data it'll be based on the site activity instead.+ def self.typical_sensitivity+ 12.5+ end+# Generate `pending?`, `rejected?`, etc helper methodsstatuses.each do |name, id|define_method("#{name}?") { status == id }@@ -195,11 +201,13 @@ class Reviewable < ActiveRecord::Basereturn Float::MAX if sensitivity == 0ratio = sensitivity / Reviewable.sensitivity[:low].to_f- high = PluginStore.get('reviewables', "priority_#{Reviewable.priorities[:high]}")- return (10.0 * scale) if high.nil?+ high = (+ PluginStore.get('reviewables', "priority_#{Reviewable.priorities[:high]}") ||+ typical_sensitivity+ ).to_f# We want this to be hard to reach- (high.to_f * ratio) * scale+ ((high.to_f * ratio) * scale).truncate(2)enddef self.sensitivity_score(sensitivity, scale: 1.0)diff --git a/lib/post_action_creator.rb b/lib/post_action_creator.rbindex eacf1d312c6..fa2b87ab095 100644--- a/lib/post_action_creator.rb+++ b/lib/post_action_creator.rb@@ -155,6 +155,7 @@ privatedef auto_hide_if_neededreturn if @post.hidden?return if !@created_by.staff? && @post.user&.staff?+ return unless PostActionType.auto_action_flag_types.include?(@post_action_name)# Special case: If you have TL3 and the user is TL0, and the flag is spam,# hide it immediately.@@ -163,11 +164,11 @@ private@post.user&.trust_level == TrustLevel[0]@post.hide!(@post_action_type_id, Post.hidden_reasons[:flagged_by_tl3_user])return- elsif PostActionType.auto_action_flag_types.include?(@post_action_name)- score = ReviewableFlaggedPost.find_by(target: @post)&.score || 0- if score >= Reviewable.score_required_to_hide_post- @post.hide!(@post_action_type_id)- end+ end++ score = ReviewableFlaggedPost.find_by(target: @post)&.score || 0+ if score >= Reviewable.score_required_to_hide_post+ @post.hide!(@post_action_type_id)endenddiff --git a/spec/models/reviewable_spec.rb b/spec/models/reviewable_spec.rbindex 08d36bf1a56..6e8cfa32ce5 100644--- a/spec/models/reviewable_spec.rb+++ b/spec/models/reviewable_spec.rb@@ -339,11 +339,13 @@ RSpec.describe Reviewable, type: :model doexpect(Reviewable.score_required_to_hide_post).to eq(40.0)end- it "returns 10 if we can't calculated any percentiles" do+ it "returns a default if we can't calculated any percentiles" doSiteSetting.hide_post_sensitivity = Reviewable.sensitivity[:low]- expect(Reviewable.score_required_to_hide_post).to eq(10.0)+ expect(Reviewable.score_required_to_hide_post).to eq(12.5)SiteSetting.hide_post_sensitivity = Reviewable.sensitivity[:medium]- expect(Reviewable.score_required_to_hide_post).to eq(10.0)+ expect(Reviewable.score_required_to_hide_post).to eq(8.33)+ SiteSetting.hide_post_sensitivity = Reviewable.sensitivity[:high]+ expect(Reviewable.score_required_to_hide_post).to eq(4.16)endit "returns a fraction of the high percentile" do@@ -360,37 +362,37 @@ RSpec.describe Reviewable, type: :model doendcontext ".spam_score_to_silence_new_user" do- it "returns 6 if we can't calculated any percentiles" do+ it "returns a default value if we can't calculated any percentiles" doSiteSetting.silence_new_user_sensitivity = Reviewable.sensitivity[:low]- expect(Reviewable.spam_score_to_silence_new_user).to eq(6.0)+ expect(Reviewable.spam_score_to_silence_new_user).to eq(7.5)SiteSetting.silence_new_user_sensitivity = Reviewable.sensitivity[:medium]- expect(Reviewable.spam_score_to_silence_new_user).to eq(6.0)+ expect(Reviewable.spam_score_to_silence_new_user).to eq(4.99)SiteSetting.silence_new_user_sensitivity = Reviewable.sensitivity[:high]- expect(Reviewable.spam_score_to_silence_new_user).to eq(6.0)+ expect(Reviewable.spam_score_to_silence_new_user).to eq(2.49)endit "returns a fraction of the high percentile" doReviewable.set_priorities(high: 100.0)SiteSetting.silence_new_user_sensitivity = Reviewable.sensitivity[:disabled]- expect(Reviewable.spam_score_to_silence_new_user.to_f.truncate(2)).to eq(Float::MAX)+ expect(Reviewable.spam_score_to_silence_new_user.to_f).to eq(Float::MAX)SiteSetting.silence_new_user_sensitivity = Reviewable.sensitivity[:low]- expect(Reviewable.spam_score_to_silence_new_user.to_f.truncate(2)).to eq(60.0)+ expect(Reviewable.spam_score_to_silence_new_user.to_f).to eq(60.0)SiteSetting.silence_new_user_sensitivity = Reviewable.sensitivity[:medium]- expect(Reviewable.spam_score_to_silence_new_user.to_f.truncate(2)).to eq(39.99)+ expect(Reviewable.spam_score_to_silence_new_user.to_f).to eq(39.99)SiteSetting.silence_new_user_sensitivity = Reviewable.sensitivity[:high]- expect(Reviewable.spam_score_to_silence_new_user.to_f.truncate(2)).to eq(19.99)+ expect(Reviewable.spam_score_to_silence_new_user.to_f).to eq(19.99)endendcontext ".score_to_auto_close_topic" do- it "returns 25 if we can't calculated any percentiles" do+ it "returns the default if we can't calculated any percentiles" doSiteSetting.auto_close_topic_sensitivity = Reviewable.sensitivity[:low]- expect(Reviewable.score_to_auto_close_topic).to eq(25.0)+ expect(Reviewable.score_to_auto_close_topic).to eq(31.25)SiteSetting.auto_close_topic_sensitivity = Reviewable.sensitivity[:medium]- expect(Reviewable.score_to_auto_close_topic).to eq(25.0)+ expect(Reviewable.score_to_auto_close_topic).to eq(20.83)SiteSetting.auto_close_topic_sensitivity = Reviewable.sensitivity[:high]- expect(Reviewable.score_to_auto_close_topic).to eq(25.0)+ expect(Reviewable.score_to_auto_close_topic).to eq(10.41)endit "returns a fraction of the high percentile" do