Skip to content

Instantly share code, notes, and snippets.

@ares
Created August 15, 2023 13:34
Show Gist options
  • Save ares/de9def4cff02eae9cbe04b84b47e7d11 to your computer and use it in GitHub Desktop.
Save ares/de9def4cff02eae9cbe04b84b47e7d11 to your computer and use it in GitHub Desktop.
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 84ba764..0369356 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -57,6 +57,15 @@ class Setting < ApplicationRecord
scoped_search :on => :id, :complete_enabled => false, :only_explicit => true, :validator => ScopedSearch::Validators::INTEGER
scoped_search on: :name, complete_value: :true, operators: ['=', '~']
+ scoped_search on: :description, ext_method: :find_by_description, operators: ['~'], :only_explicit => false, :rename => 'description'
+
+ def self.find_by_description(key, operator, value)
+ value
+ names = Foreman.settings.map { |s| [s.id, s.description] }.select { |i,v| v =~ /#{value}/ }.map { |s| s.first }
+ conditions = sanitize_sql_for_conditions(['settings.name IN (?)', names])
+ { :conditions => conditions }
+ end
+
delegate :settings_type, :encrypted, :encrypted?, :default, to: :setting_definition, allow_nil: true
def self.config_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment