Use an Enum class for the Reviewable Priority Site Setting

Use an Enum class for the Reviewable Priority Site Setting

diff --git a/app/models/reviewable_priority_setting.rb b/app/models/reviewable_priority_setting.rb
new file mode 100644
index 0000000..eb89b18
--- /dev/null
+++ b/app/models/reviewable_priority_setting.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require_dependency 'enum_site_setting'
+
+class ReviewablePrioritySetting < EnumSiteSetting
+
+  def self.valid_value?(val)
+    values.any? { |v| v[:value].to_s == val.to_s }
+  end
+
+  def self.values
+    Reviewable.priorities.map do |p|
+      { name: I18n.t("reviewables.priorities.#{p[0]}"), value: p[0] }
+    end
+  end
+
+  def self.translate_names?
+    false
+  end
+
+end
diff --git a/config/site_settings.yml b/config/site_settings.yml
index b82d9fb..ac2fcf1 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -1410,10 +1410,7 @@ spam:
     client: true
     type: enum
     default: low
-    choices:
-      - low
-      - medium
-      - high
+    enum: "ReviewablePrioritySetting"
 
 rate_limits:
   unique_posts_mins: 5

GitHub sha: fad5d9c4

1 Like