Migrate score settings to use sensitivities

Migrate score settings to use sensitivities

We hide scores so these settings no longer made sense.

diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index da0837e..7c43284 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -41,7 +41,7 @@ class Reviewable < ActiveRecord::Base
     Jobs.enqueue(:notify_reviewable, reviewable_id: self.id) if pending?
   end
 
-  # The gaps are in case we want more accuracy in the future
+  # The gaps are in case we want more precision in the future
   def self.priorities
     @priorities ||= Enum.new(
       low: 0,
@@ -50,6 +50,16 @@ class Reviewable < ActiveRecord::Base
     )
   end
 
+  # The gaps are in case we want more precision in the future
+  def self.sensitivity
+    @sensitivity ||= Enum.new(
+      disabled: 0,
+      low: 9,
+      medium: 6,
+      high: 3
+    )
+  end
+
   def self.statuses
     @statuses ||= Enum.new(
       pending: 0,
@@ -173,6 +183,29 @@ class Reviewable < ActiveRecord::Base
     end
   end
 
+  def self.sensitivity_score(sensitivity, scale: 1.0)
+    return Float::MAX if sensitivity == 0
+
+    ratio = sensitivity / Reviewable.sensitivity[:low].to_f
+    high = PluginStore.get('reviewables', "priority_#{Reviewable.priorities[:high]}")
+    return (10.0 * scale) if high.nil?
+
+    # We want this to be hard to reach
+    (high.to_f * ratio) * scale
+  end
+
+  def self.score_to_auto_close_topic
+    sensitivity_score(SiteSetting.auto_close_topic_sensitivity, scale: 2.5)
+  end
+
+  def self.spam_score_to_silence_new_user
+    sensitivity_score(SiteSetting.silence_new_user_sensitivity, scale: 0.6)
+  end
+
+  def self.score_required_to_hide_post
+    sensitivity_score(SiteSetting.hide_post_sensitivity)
+  end
+
   def self.min_score_for_priority(priority = nil)
     priority ||= SiteSetting.reviewable_default_visibility
     id = Reviewable.priorities[priority.to_sym]
diff --git a/app/models/reviewable_sensitivity_setting.rb b/app/models/reviewable_sensitivity_setting.rb
new file mode 100644
index 0000000..1d83c46
--- /dev/null
+++ b/app/models/reviewable_sensitivity_setting.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+require_dependency 'enum_site_setting'
+
+class ReviewableSensitivitySetting < EnumSiteSetting
+
+  def self.valid_value?(val)
+    values.any? { |v| v[:value].to_s == val.to_s }
+  end
+
+  def self.values
+    Reviewable.sensitivity.map do |p|
+      { name: I18n.t("reviewables.sensitivity.#{p[0]}"), value: p[1] }
+    end
+  end
+
+  def self.translate_names?
+    false
+  end
+
+end
+
diff --git a/app/models/topic.rb b/app/models/topic.rb
index 9a45a32..c239c87 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -1373,7 +1373,7 @@ class Topic < ActiveRecord::Base
       .pluck("COUNT(DISTINCT reviewable_scores.user_id), COALESCE(SUM(reviewable_scores.score), 0.0)")
       .first
 
-    scores[0] >= SiteSetting.num_flaggers_to_close_topic && scores[1] >= SiteSetting.score_to_auto_close_topic
+    scores[0] >= SiteSetting.num_flaggers_to_close_topic && scores[1] >= Reviewable.score_to_auto_close_topic
   end
 
   def update_category_topic_count_by(num)
diff --git a/app/services/spam_rule/auto_silence.rb b/app/services/spam_rule/auto_silence.rb
index accebe1..81acb86 100644
--- a/app/services/spam_rule/auto_silence.rb
+++ b/app/services/spam_rule/auto_silence.rb
@@ -24,14 +24,9 @@ class SpamRule::AutoSilence
     return false if @user.staged?
     return false if @user.has_trust_level?(TrustLevel[1])
 
-    if SiteSetting.spam_score_to_silence_new_user > 0 &&
-        SiteSetting.num_users_to_silence_new_user > 0 &&
-        user_spam_stats.total_spam_score >= SiteSetting.spam_score_to_silence_new_user &&
-        user_spam_stats.spam_user_count >= SiteSetting.num_users_to_silence_new_user
-      return true
-    end
-
-    false
+    SiteSetting.num_users_to_silence_new_user > 0 &&
+      user_spam_stats.total_spam_score >= Reviewable.spam_score_to_silence_new_user &&
+      user_spam_stats.spam_user_count >= SiteSetting.num_users_to_silence_new_user
   end
 
   def user_spam_stats
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 905c77a..fbcd61e 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1388,7 +1388,10 @@ en:
     anon_polling_interval: "How often should anonymous clients poll in milliseconds"
     background_polling_interval: "How often should the clients poll in milliseconds (when the window is in the background)"
 
-    score_required_to_hide_post: "Score threshold that causes a post to be automatically hidden and message sent to the user (0 to disable)"
+    hide_post_sensitivity: "The likelyhood that a flagged post will be hidden"
+    silence_new_user_sensitivity: "The likelyhood that a new user will be silenced based on spam flags"
+    auto_close_topic_sensitivity: "The likelyhood that a flagged topic will be automatically closed"
+
     cooldown_minutes_after_hiding_posts: "Number of minutes a user must wait before they can edit a post hidden via community flagging"
 
     max_topics_in_first_day: "The maximum number of topics a user is allowed to create in the 24 hour period after creating their first post"
@@ -1397,8 +1400,6 @@ en:
     tl2_additional_likes_per_day_multiplier: "Increase limit of likes per day for tl2 (member) by multiplying with this number"
     tl3_additional_likes_per_day_multiplier: "Increase limit of likes per day for tl3 (regular) by multiplying with this number"
     tl4_additional_likes_per_day_multiplier: "Increase limit of likes per day for tl4 (leader) by multiplying with this number"
-
-    spam_score_to_silence_new_user: "If a new user's posts receive this score from num_users_to_silence_new_user different users, hide all their posts and prevent future posting. 0 to disable."
     num_users_to_silence_new_user: "If a new user's posts get num_spam_flags_to_silence_new_user spam flags from this many different users, hide all their posts and prevent future posting. 0 to disable."
     num_tl3_flags_to_silence_new_user: "If a new user's posts get this many flags from num_tl3_users_to_silence_new_user different trust level 3 users, hide all their posts and prevent future posting. 0 to disable."
     num_tl3_users_to_silence_new_user: "If a new user's posts get num_tl3_flags_to_silence_new_user flags from this many different trust level 3 users, hide all their posts and prevent future posting. 0 to disable."
@@ -1745,7 +1746,6 @@ en:
     max_age_unmatched_ips: "Delete unmatched screened IP entries after (N) days."
 
     num_flaggers_to_close_topic: "Minimum number of unique flaggers that is required to automatically pause a topic for intervention"
-    score_to_auto_close_topic: "The total flag score of that is required to automatically pause a topic for intervention"
     num_hours_to_close_topic: "Number of hours to pause a topic for intervention."
 
     auto_respond_to_flag_actions: "Enable automatic reply when disposing a flag."
@@ -4418,7 +4418,11 @@ en:
       low: "Low"
       medium: "Medium"
       high: "High"
-
+    sensitivity:
+      disabled: "Disabled"
+      low: "Low"
+      medium: "Medium"
+      high: "High"
     must_claim: "You must claim items before acting on them."
     user_claimed: "This item has been claimed by another user."
     missing_version: "You must supply a version parameter"
diff --git a/config/site_settings.yml b/config/site_settings.yml
index ac2fcf1..21f570b 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -1366,9 +1366,15 @@ onebox:
 
 spam:
   add_rel_nofollow_to_user_content: true
-  score_required_to_hide_post: 10
+  hide_post_sensitivity:
+    type: enum
+    enum: "ReviewableSensitivitySetting"
+    default: 6
   cooldown_minutes_after_hiding_posts: 10
-  spam_score_to_silence_new_user: 6.0
+  silence_new_user_sensitivity:
+    type: enum
+    enum: "ReviewableSensitivitySetting"
+    default: 9
   num_users_to_silence_new_user: 3
   notify_mods_when_user_silenced: false
   flag_sockpuppets: false
@@ -1384,7 +1390,10 @@ spam:
   max_age_unmatched_emails: 365

[... diff too long, it was truncated ...]

GitHub sha: 89b84651

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: