Skip to content

Instantly share code, notes, and snippets.

@ares
Created August 15, 2023 13:34
Show Gist options
  • Select an option

  • Save ares/de9def4cff02eae9cbe04b84b47e7d11 to your computer and use it in GitHub Desktop.

Select an option

Save ares/de9def4cff02eae9cbe04b84b47e7d11 to your computer and use it in GitHub Desktop.

Revisions

  1. ares created this gist Aug 15, 2023.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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