Project

General

Profile

« Previous | Next » 

Revision ed67b8c9

Added by Dominic Cleal over 7 years ago

fixes #17574, #17364 - update scoped_search to 4.x

scoped_search's sort() now accepts a replacement for params which is
filtered in an overridden Foreman sort helper, permitting additional
parameters used in Foreman's index pages.

Replaces :in and :alias in search definitions with preferred keywords.

View differences:

Gemfile
gem 'audited-activerecord', '>= 4.2.2', '< 5'
gem 'will_paginate', '~> 3.0'
gem 'ancestry', '~> 2.0'
gem 'scoped_search', '>= 3.2.2', '< 4'
gem 'scoped_search', '~> 4.0'
gem 'ldap_fluff', '>= 0.3.5', '< 1.0'
gem 'apipie-rails', '~> 0.3.4'
gem 'rabl', '~> 0.11'
app/helpers/application_helper.rb
text_field_tag(name, val, options)
end
def sort(field, permitted: [], **kwargs)
kwargs[:url_options] ||= params.permit(permitted + [:locale, :search])
super(field, kwargs)
end
def help_button
link_to(_("Help"), { :action => "welcome" }, { :class => 'btn btn-default' }) if File.exist?("#{Rails.root}/app/views/#{controller_name}/welcome.html.erb")
end
app/models/concerns/audit_extensions.rb
:puppetclass => 'Puppetclass', :os => 'Operatingsystem', :hostgroup => 'Hostgroup',
:template => "ProvisioningTemplate" }, :rename => :type
scoped_search :in => :search_parameters, :on => :name, :complete_value => true, :rename => :parameter, :only_explicit => true
scoped_search :in => :search_templates, :on => :name, :complete_value => true, :rename => :template, :only_explicit => true
scoped_search :in => :search_os, :on => :name, :complete_value => true, :rename => :os, :only_explicit => true
scoped_search :in => :search_os, :on => :title, :complete_value => true, :rename => :os_title, :only_explicit => true
scoped_search :in => :search_class, :on => :name, :complete_value => true, :rename => :puppetclass, :only_explicit => true
scoped_search :in => :search_hosts, :on => :name, :complete_value => true, :rename => :host, :only_explicit => true
scoped_search :in => :search_hostgroups, :on => :name, :complete_value => true, :rename => :hostgroup, :only_explicit => true
scoped_search :in => :search_hostgroups, :on => :title, :complete_value => true, :rename => :hostgroup_title, :only_explicit => true
scoped_search :in => :search_users, :on => :login, :complete_value => true, :rename => :user, :only_explicit => true
scoped_search :relation => :search_parameters, :on => :name, :complete_value => true, :rename => :parameter, :only_explicit => true
scoped_search :relation => :search_templates, :on => :name, :complete_value => true, :rename => :template, :only_explicit => true
scoped_search :relation => :search_os, :on => :name, :complete_value => true, :rename => :os, :only_explicit => true
scoped_search :relation => :search_os, :on => :title, :complete_value => true, :rename => :os_title, :only_explicit => true
scoped_search :relation => :search_class, :on => :name, :complete_value => true, :rename => :puppetclass, :only_explicit => true
scoped_search :relation => :search_hosts, :on => :name, :complete_value => true, :rename => :host, :only_explicit => true
scoped_search :relation => :search_hostgroups, :on => :name, :complete_value => true, :rename => :hostgroup, :only_explicit => true
scoped_search :relation => :search_hostgroups, :on => :title, :complete_value => true, :rename => :hostgroup_title, :only_explicit => true
scoped_search :relation => :search_users, :on => :login, :complete_value => true, :rename => :user, :only_explicit => true
before_save :ensure_username, :ensure_auditable_and_associated_name
before_save :filter_encrypted, :if => Proc.new {|audit| audit.audited_changes.present?}
app/models/concerns/hostext/search.rb
scoped_search :on => :owner_type, :complete_value => true, :only_explicit => true
scoped_search :on => :owner_id, :complete_enabled => false, :only_explicit => true
scoped_search :in => :configuration_status_object, :on => :status, :offset => 0, :word_size => ConfigReport::BIT_NUM*4, :rename => :'status.interesting', :complete_value => {:true => true, :false => false}
scoped_search_status "applied", :in => :configuration_status_object, :on => :status, :rename => :'status.applied'
scoped_search_status "restarted", :in => :configuration_status_object, :on => :status, :rename => :'status.restarted'
scoped_search_status "failed", :in => :configuration_status_object, :on => :status, :rename => :'status.failed'
scoped_search_status "failed_restarts", :in => :configuration_status_object, :on => :status, :rename => :'status.failed_restarts'
scoped_search_status "skipped", :in => :configuration_status_object, :on => :status, :rename => :'status.skipped'
scoped_search_status "pending", :in => :configuration_status_object, :on => :status, :rename => :'status.pending'
scoped_search :relation => :configuration_status_object, :on => :status, :offset => 0, :word_size => ConfigReport::BIT_NUM*4, :rename => :'status.interesting', :complete_value => {:true => true, :false => false}
scoped_search_status "applied", :relation => :configuration_status_object, :on => :status, :rename => :'status.applied'
scoped_search_status "restarted", :relation => :configuration_status_object, :on => :status, :rename => :'status.restarted'
scoped_search_status "failed", :relation => :configuration_status_object, :on => :status, :rename => :'status.failed'
scoped_search_status "failed_restarts", :relation => :configuration_status_object, :on => :status, :rename => :'status.failed_restarts'
scoped_search_status "skipped", :relation => :configuration_status_object, :on => :status, :rename => :'status.skipped'
scoped_search_status "pending", :relation => :configuration_status_object, :on => :status, :rename => :'status.pending'
scoped_search :on => :global_status, :complete_value => { :ok => HostStatus::Global::OK, :warning => HostStatus::Global::WARN, :error => HostStatus::Global::ERROR }
scoped_search :in => :model, :on => :name, :complete_value => true, :rename => :model
scoped_search :in => :hostgroup, :on => :name, :complete_value => true, :rename => :hostgroup
scoped_search :in => :hostgroup, :on => :name, :complete_enabled => false, :rename => :hostgroup_name, :only_explicit => true
scoped_search :in => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_fullname
scoped_search :in => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_title
scoped_search :in => :hostgroup, :on => :id, :complete_enabled => false, :rename => :hostgroup_id, :only_explicit => true
scoped_search :in => :hostgroup, :on => :title, :complete_value => true, :rename => :parent_hostgroup, :only_explicit => true, :ext_method => :search_by_hostgroup_and_descendants
scoped_search :in => :domain, :on => :name, :complete_value => true, :rename => :domain
scoped_search :in => :domain, :on => :id, :complete_enabled => false, :rename => :domain_id, :only_explicit => true
scoped_search :in => :realm, :on => :name, :complete_value => true, :rename => :realm
scoped_search :in => :realm, :on => :id, :complete_enabled => false, :rename => :realm_id, :only_explicit => true
scoped_search :in => :environment, :on => :name, :complete_value => true, :rename => :environment
scoped_search :in => :architecture, :on => :name, :complete_value => true, :rename => :architecture
scoped_search :in => :puppet_proxy, :on => :name, :complete_value => true, :rename => :puppetmaster, :only_explicit => true
scoped_search :relation => :model, :on => :name, :complete_value => true, :rename => :model
scoped_search :relation => :hostgroup, :on => :name, :complete_value => true, :rename => :hostgroup
scoped_search :relation => :hostgroup, :on => :name, :complete_enabled => false, :rename => :hostgroup_name, :only_explicit => true
scoped_search :relation => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_fullname
scoped_search :relation => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_title
scoped_search :relation => :hostgroup, :on => :id, :complete_enabled => false, :rename => :hostgroup_id, :only_explicit => true
scoped_search :relation => :hostgroup, :on => :title, :complete_value => true, :rename => :parent_hostgroup, :only_explicit => true, :ext_method => :search_by_hostgroup_and_descendants
scoped_search :relation => :domain, :on => :name, :complete_value => true, :rename => :domain
scoped_search :relation => :domain, :on => :id, :complete_enabled => false, :rename => :domain_id, :only_explicit => true
scoped_search :relation => :realm, :on => :name, :complete_value => true, :rename => :realm
scoped_search :relation => :realm, :on => :id, :complete_enabled => false, :rename => :realm_id, :only_explicit => true
scoped_search :relation => :environment, :on => :name, :complete_value => true, :rename => :environment
scoped_search :relation => :architecture, :on => :name, :complete_value => true, :rename => :architecture
scoped_search :relation => :puppet_proxy, :on => :name, :complete_value => true, :rename => :puppetmaster, :only_explicit => true
scoped_search :on => :puppet_proxy_id, :complete_value => false, :only_explicit => true
scoped_search :in => :puppet_ca_proxy, :on => :name, :complete_value => true, :rename => :puppet_ca, :only_explicit => true
scoped_search :in => :puppet_proxy, :on => :name, :complete_value => true, :rename => :smart_proxy, :ext_method => :search_by_proxy, :only_explicit => true
scoped_search :in => :compute_resource, :on => :name, :complete_value => true, :rename => :compute_resource
scoped_search :in => :compute_resource, :on => :id, :complete_enabled => false, :rename => :compute_resource_id, :only_explicit => true
scoped_search :in => :image, :on => :name, :complete_value => true
scoped_search :in => :operatingsystem, :on => :name, :complete_value => true, :rename => :os
scoped_search :in => :operatingsystem, :on => :description, :complete_value => true, :rename => :os_description
scoped_search :in => :operatingsystem, :on => :title, :complete_value => true, :rename => :os_title
scoped_search :in => :operatingsystem, :on => :major, :complete_value => true, :rename => :os_major
scoped_search :in => :operatingsystem, :on => :minor, :complete_value => true, :rename => :os_minor
scoped_search :in => :operatingsystem, :on => :id, :complete_enabled => false,:rename => :os_id, :only_explicit => true
scoped_search :in => :primary_interface, :on => :ip, :complete_value => true
scoped_search :in => :interfaces, :on => :ip, :complete_value => true, :rename => :has_ip
scoped_search :in => :interfaces, :on => :mac, :complete_value => true, :rename => :has_mac
scoped_search :in => :puppetclasses, :on => :name, :complete_value => true, :rename => :class, :only_explicit => true, :operators => ['= ', '~ '], :ext_method => :search_by_puppetclass
scoped_search :in => :fact_values, :on => :value, :in_key=> :fact_names, :on_key=> :name, :rename => :facts, :complete_value => true, :only_explicit => true, :ext_method => :search_cast_facts
scoped_search :in => :search_parameters, :on => :value, :on_key=> :name, :complete_value => true, :rename => :params, :ext_method => :search_by_params, :only_explicit => true
scoped_search :relation => :puppet_ca_proxy, :on => :name, :complete_value => true, :rename => :puppet_ca, :only_explicit => true
scoped_search :relation => :puppet_proxy, :on => :name, :complete_value => true, :rename => :smart_proxy, :ext_method => :search_by_proxy, :only_explicit => true
scoped_search :relation => :compute_resource, :on => :name, :complete_value => true, :rename => :compute_resource
scoped_search :relation => :compute_resource, :on => :id, :complete_enabled => false, :rename => :compute_resource_id, :only_explicit => true
scoped_search :relation => :image, :on => :name, :complete_value => true
scoped_search :relation => :operatingsystem, :on => :name, :complete_value => true, :rename => :os
scoped_search :relation => :operatingsystem, :on => :description, :complete_value => true, :rename => :os_description
scoped_search :relation => :operatingsystem, :on => :title, :complete_value => true, :rename => :os_title
scoped_search :relation => :operatingsystem, :on => :major, :complete_value => true, :rename => :os_major
scoped_search :relation => :operatingsystem, :on => :minor, :complete_value => true, :rename => :os_minor
scoped_search :relation => :operatingsystem, :on => :id, :complete_enabled => false,:rename => :os_id, :only_explicit => true
scoped_search :relation => :primary_interface, :on => :ip, :complete_value => true
scoped_search :relation => :interfaces, :on => :ip, :complete_value => true, :rename => :has_ip
scoped_search :relation => :interfaces, :on => :mac, :complete_value => true, :rename => :has_mac
scoped_search :relation => :puppetclasses, :on => :name, :complete_value => true, :rename => :class, :only_explicit => true, :operators => ['= ', '~ '], :ext_method => :search_by_puppetclass
scoped_search :relation => :fact_values, :on => :value, :in_key=> :fact_names, :on_key=> :name, :rename => :facts, :complete_value => true, :only_explicit => true, :ext_method => :search_cast_facts
scoped_search :relation => :search_parameters, :on => :value, :on_key=> :name, :complete_value => true, :rename => :params, :ext_method => :search_by_params, :only_explicit => true
if SETTINGS[:locations_enabled]
scoped_search :in => :location, :on => :title, :rename => :location, :complete_value => true
scoped_search :relation => :location, :on => :title, :rename => :location, :complete_value => true
scoped_search :on => :location_id, :complete_enabled => false, :only_explicit => true
end
if SETTINGS[:organizations_enabled]
scoped_search :in => :organization, :on => :title, :rename => :organization, :complete_value => true, :only_explicit => true
scoped_search :relation => :organization, :on => :title, :rename => :organization, :complete_value => true, :only_explicit => true
scoped_search :on => :organization_id, :complete_enabled => false, :only_explicit => true
end
scoped_search :in => :config_groups, :on => :name, :complete_value => true, :rename => :config_group, :only_explicit => true, :operators => ['= ', '~ '], :ext_method => :search_by_config_group
scoped_search :relation => :config_groups, :on => :name, :complete_value => true, :rename => :config_group, :only_explicit => true, :operators => ['= ', '~ '], :ext_method => :search_by_config_group
if SETTINGS[:unattended]
scoped_search :in => :subnet, :on => :network, :complete_value => false, :rename => :subnet
scoped_search :in => :subnet, :on => :name, :complete_value => false, :rename => 'subnet.name'
scoped_search :in => :subnet6, :on => :network, :complete_value => false, :rename => :subnet6
scoped_search :in => :subnet6, :on => :name, :complete_value => false, :rename => 'subnet6.name'
scoped_search :on => :uuid, :complete_value => true
scoped_search :on => :build, :complete_value => {:true => true, :false => false}
scoped_search :on => :installed_at, :complete_value => true, :only_explicit => true
scoped_search :in => :provision_interface, :on => :mac, :complete_value => true
scoped_search :in => :operatingsystem, :on => :name, :complete_value => true, :rename => :os
scoped_search :in => :operatingsystem, :on => :description, :complete_value => true, :rename => :os_description
scoped_search :in => :operatingsystem, :on => :title, :complete_value => true, :rename => :os_title
scoped_search :in => :operatingsystem, :on => :major, :complete_value => true, :rename => :os_major
scoped_search :in => :operatingsystem, :on => :minor, :complete_value => true, :rename => :os_minor
scoped_search :in => :operatingsystem, :on => :id, :complete_value => false,:rename => :os_id, :complete_enabled => false
scoped_search :relation => :subnet, :on => :network, :complete_value => false, :rename => :subnet
scoped_search :relation => :subnet, :on => :name, :complete_value => false, :rename => 'subnet.name'
scoped_search :relation => :subnet6, :on => :network, :complete_value => false, :rename => :subnet6
scoped_search :relation => :subnet6, :on => :name, :complete_value => false, :rename => 'subnet6.name'
scoped_search :on => :uuid, :complete_value => true
scoped_search :on => :build, :complete_value => {:true => true, :false => false}
scoped_search :on => :installed_at, :complete_value => true, :only_explicit => true
scoped_search :relation => :provision_interface, :on => :mac, :complete_value => true
scoped_search :relation => :operatingsystem, :on => :name, :complete_value => true, :rename => :os
scoped_search :relation => :operatingsystem, :on => :description, :complete_value => true, :rename => :os_description
scoped_search :relation => :operatingsystem, :on => :title, :complete_value => true, :rename => :os_title
scoped_search :relation => :operatingsystem, :on => :major, :complete_value => true, :rename => :os_major
scoped_search :relation => :operatingsystem, :on => :minor, :complete_value => true, :rename => :os_minor
scoped_search :relation => :operatingsystem, :on => :id, :complete_value => false,:rename => :os_id, :complete_enabled => false
end
if SETTINGS[:login]
scoped_search :in => :search_users, :on => :login, :complete_value => true, :only_explicit => true, :rename => :'user.login', :operators => ['= ', '~ '], :ext_method => :search_by_user, :alias => :owner
scoped_search :in => :search_users, :on => :firstname, :complete_value => true, :only_explicit => true, :rename => :'user.firstname',:operators => ['= ', '~ '], :ext_method => :search_by_user
scoped_search :in => :search_users, :on => :lastname, :complete_value => true, :only_explicit => true, :rename => :'user.lastname', :operators => ['= ', '~ '], :ext_method => :search_by_user
scoped_search :in => :search_users, :on => :mail, :complete_value => true, :only_explicit => true, :rename => :'user.mail', :operators => ['= ', '~ '], :ext_method => :search_by_user
scoped_search :relation => :search_users, :on => :login, :complete_value => true, :only_explicit => true, :rename => :'user.login', :operators => ['= ', '~ '], :ext_method => :search_by_user, :aliases => [:owner]
scoped_search :relation => :search_users, :on => :firstname, :complete_value => true, :only_explicit => true, :rename => :'user.firstname',:operators => ['= ', '~ '], :ext_method => :search_by_user
scoped_search :relation => :search_users, :on => :lastname, :complete_value => true, :only_explicit => true, :rename => :'user.lastname', :operators => ['= ', '~ '], :ext_method => :search_by_user
scoped_search :relation => :search_users, :on => :mail, :complete_value => true, :only_explicit => true, :rename => :'user.mail', :operators => ['= ', '~ '], :ext_method => :search_by_user
end
cattr_accessor :fact_values_table_counter
app/models/concerns/taxonomix.rb
:validate => false
after_initialize :set_current_taxonomy
scoped_search :in => :locations, :on => :name, :rename => :location, :complete_value => true
scoped_search :in => :locations, :on => :id, :rename => :location_id, :complete_enabled => false, :only_explicit => true
scoped_search :in => :organizations, :on => :name, :rename => :organization, :complete_value => true
scoped_search :in => :organizations, :on => :id, :rename => :organization_id, :complete_enabled => false, :only_explicit => true
scoped_search :relation => :locations, :on => :name, :rename => :location, :complete_value => true
scoped_search :relation => :locations, :on => :id, :rename => :location_id, :complete_enabled => false, :only_explicit => true
scoped_search :relation => :organizations, :on => :name, :rename => :organization, :complete_value => true
scoped_search :relation => :organizations, :on => :id, :rename => :organization_id, :complete_enabled => false, :only_explicit => true
dirty_has_many_associations :organizations, :locations
app/models/domain.rb
validates :fullname, :uniqueness => true, :allow_blank => true, :allow_nil => true
scoped_search :on => [:name, :fullname], :complete_value => true
scoped_search :in => :domain_parameters, :on => :value, :on_key=> :name, :complete_value => true, :only_explicit => true, :rename => :params
scoped_search :relation => :domain_parameters, :on => :value, :on_key=> :name, :complete_value => true, :only_explicit => true, :rename => :params
# with proc support, default_scope can no longer be chained
# include all default scoping here
app/models/fact_value.rb
scoped_search :on => :value, :in_key=> :fact_name, :on_key=> :name, :rename => :facts, :complete_value => true, :only_explicit => true, :ext_method => :search_cast_facts
scoped_search :on => :value, :default_order => true, :ext_method => :search_value_cast_facts
scoped_search :in => :fact_name, :on => :name, :complete_value => true, :alias => "fact"
scoped_search :in => :host, :on => :name, :complete_value => true, :rename => :host, :ext_method => :search_by_host_or_hostgroup, :only_explicit => true
scoped_search :in => :hostgroup, :on => :name, :complete_value => true, :rename => :"host.hostgroup", :ext_method => :search_by_host_or_hostgroup, :only_explicit => true
scoped_search :in => :fact_name, :on => :short_name, :complete_value => true, :alias => "fact_short_name"
scoped_search :relation => :fact_name, :on => :name, :complete_value => true, :aliases => ["fact"]
scoped_search :relation => :host, :on => :name, :complete_value => true, :rename => :host, :ext_method => :search_by_host_or_hostgroup, :only_explicit => true
scoped_search :relation => :hostgroup, :on => :name, :complete_value => true, :rename => :"host.hostgroup", :ext_method => :search_by_host_or_hostgroup, :only_explicit => true
scoped_search :relation => :fact_name, :on => :short_name, :complete_value => true, :aliases => ["fact_short_name"]
scope :no_timestamp_facts, lambda {
eager_load(:fact_name).where("fact_names.name <> ?",:_timestamp)
app/models/filter.rb
scoped_search :on => :override, :complete_value => { :true => true, :false => false }
scoped_search :on => :limited, :complete_value => { :true => true, :false => false }, :ext_method => :search_by_limited, :only_explicit => true
scoped_search :on => :unlimited, :complete_value => { :true => true, :false => false }, :ext_method => :search_by_unlimited, :only_explicit => true
scoped_search :in => :role, :on => :id, :rename => :role_id, :complete_enabled => false, :only_explicit => true
scoped_search :in => :role, :on => :name, :rename => :role
scoped_search :in => :permissions, :on => :resource_type, :rename => :resource
scoped_search :in => :permissions, :on => :name, :rename => :permission
scoped_search :relation => :role, :on => :id, :rename => :role_id, :complete_enabled => false, :only_explicit => true
scoped_search :relation => :role, :on => :name, :rename => :role
scoped_search :relation => :permissions, :on => :resource_type, :rename => :resource
scoped_search :relation => :permissions, :on => :name, :rename => :permission
before_validation :build_taxonomy_search, :nilify_empty_searches, :enforce_override_flag
before_save :enforce_inherited_taxonomies
app/models/hostgroup.rb
}
scoped_search :on => :name, :complete_value => :true
scoped_search :in => :group_parameters, :on => :value, :on_key=> :name, :complete_value => true, :only_explicit => true, :rename => :params
scoped_search :in => :hosts, :on => :name, :complete_value => :true, :rename => "host"
scoped_search :in => :puppetclasses, :on => :name, :complete_value => true, :rename => :class, :operators => ['= ', '~ ']
scoped_search :in => :environment, :on => :name, :complete_value => :true, :rename => :environment
scoped_search :relation => :group_parameters, :on => :value, :on_key=> :name, :complete_value => true, :only_explicit => true, :rename => :params
scoped_search :relation => :hosts, :on => :name, :complete_value => :true, :rename => "host"
scoped_search :relation => :puppetclasses, :on => :name, :complete_value => true, :rename => :class, :operators => ['= ', '~ ']
scoped_search :relation => :environment, :on => :name, :complete_value => :true, :rename => :environment
scoped_search :on => :id, :complete_enabled => false, :only_explicit => true
# for legacy purposes, keep search on :label
scoped_search :on => :title, :complete_value => true, :rename => :label
scoped_search :in => :config_groups, :on => :name, :complete_value => true, :rename => :config_group, :only_explicit => true, :operators => ['= ', '~ '], :ext_method => :search_by_config_group
scoped_search :relation => :config_groups, :on => :name, :complete_value => true, :rename => :config_group, :only_explicit => true, :operators => ['= ', '~ '], :ext_method => :search_by_config_group
def self.search_by_config_group(key, operator, value)
conditions = sanitize_sql_for_conditions(["config_groups.name #{operator} ?", value_to_sql(operator, value)])
......
end
if SETTINGS[:unattended]
scoped_search :in => :architecture, :on => :name, :complete_value => true, :rename => :architecture
scoped_search :in => :operatingsystem, :on => :name, :complete_value => true, :rename => :os
scoped_search :in => :operatingsystem, :on => :description, :complete_value => true, :rename => :os_description
scoped_search :in => :operatingsystem, :on => :title, :complete_value => true, :rename => :os_title
scoped_search :in => :operatingsystem, :on => :major, :complete_value => true, :rename => :os_major
scoped_search :in => :operatingsystem, :on => :minor, :complete_value => true, :rename => :os_minor
scoped_search :in => :operatingsystem, :on => :id, :complete_enabled => false, :rename => :os_id, :only_explicit => true
scoped_search :in => :medium, :on => :name, :complete_value => true, :rename => "medium"
scoped_search :in => :provisioning_templates, :on => :name, :complete_value => true, :rename => "template"
scoped_search :relation => :architecture, :on => :name, :complete_value => true, :rename => :architecture
scoped_search :relation => :operatingsystem, :on => :name, :complete_value => true, :rename => :os
scoped_search :relation => :operatingsystem, :on => :description, :complete_value => true, :rename => :os_description
scoped_search :relation => :operatingsystem, :on => :title, :complete_value => true, :rename => :os_title
scoped_search :relation => :operatingsystem, :on => :major, :complete_value => true, :rename => :os_major
scoped_search :relation => :operatingsystem, :on => :minor, :complete_value => true, :rename => :os_minor
scoped_search :relation => :operatingsystem, :on => :id, :complete_enabled => false, :rename => :os_id, :only_explicit => true
scoped_search :relation => :medium, :on => :name, :complete_value => true, :rename => "medium"
scoped_search :relation => :provisioning_templates, :on => :name, :complete_value => true, :rename => "template"
end
# returns reports for hosts in the User's filter set
app/models/image.rb
validate :uuid_exists?
scoped_search :on => [:name, :username], :complete_value => true
scoped_search :in => :compute_resource, :on => :name, :complete_value => :true, :rename => "compute_resource"
scoped_search :in => :architecture, :on => :id, :rename => "architecture", :complete_enabled => false, :only_explicit => true
scoped_search :in => :operatingsystem, :on => :id, :rename => "operatingsystem", :complete_enabled => false, :only_explicit => true
scoped_search :relation => :compute_resource, :on => :name, :complete_value => :true, :rename => "compute_resource"
scoped_search :relation => :architecture, :on => :id, :rename => "architecture", :complete_enabled => false, :only_explicit => true
scoped_search :relation => :operatingsystem, :on => :id, :rename => "operatingsystem", :complete_enabled => false, :only_explicit => true
scoped_search :on => :user_data, :complete_value => {:true => true, :false => false}
private
app/models/lookup_keys/lookup_key.rb
def self.inherited(child)
child.instance_eval do
scoped_search :on => :key, :alias => :parameter, :complete_value => true, :default_order => true
scoped_search :on => :key, :aliases => [:parameter], :complete_value => true, :default_order => true
scoped_search :on => :override, :complete_value => {:true => true, :false => false}
scoped_search :on => :merge_overrides, :complete_value => {:true => true, :false => false}
scoped_search :on => :merge_default, :complete_value => {:true => true, :false => false}
app/models/lookup_keys/puppetclass_lookup_key.rb
validate :validate_default_value, :disable_merge_overrides, :disable_avoid_duplicates, :disable_merge_default, :if => :override?
after_validation :reset_override_params, :if => ->(key) { key.override_changed? && !key.override? }
scoped_search :in => :param_classes, :on => :name, :rename => :puppetclass, :alias => :puppetclass_name, :complete_value => true
scoped_search :relation => :param_classes, :on => :name, :rename => :puppetclass, :aliases => [:puppetclass_name], :complete_value => true
scope :smart_class_parameters_for_class, lambda { |puppetclass_ids, environment_id|
joins(:environment_classes).where(:environment_classes => {:puppetclass_id => puppetclass_ids, :environment_id => environment_id})
app/models/lookup_keys/variable_lookup_key.rb
validates :key, :uniqueness => true, :no_whitespace => true
validate :validate_default_value, :disable_merge_overrides, :disable_avoid_duplicates, :disable_merge_default
scoped_search :in => :puppetclass, :on => :name, :complete_value => true, :rename => :puppetclass
scoped_search :relation => :puppetclass, :on => :name, :complete_value => true, :rename => :puppetclass
def audit_class
puppetclass
app/models/lookup_value.rb
scoped_search :on => :value, :complete_value => true, :default_order => true
scoped_search :on => :match, :complete_value => true
scoped_search :in => :lookup_key, :on => :key, :rename => :lookup_key, :complete_value => true
scoped_search :relation => :lookup_key, :on => :key, :rename => :lookup_key, :complete_value => true
def value=(val)
if val.is_a?(HashWithIndifferentAccess)
app/models/mail_notifications/mail_notification.rb
scoped_search :on => :name, :complete_value => true
scoped_search :on => :description, :complete_value => true
scoped_search :in => :users, :on => :login, :complete_value => true, :rename => :user
scoped_search :relation => :users, :on => :login, :complete_value => true, :rename => :user
scope :subscriptable, -> { where(:subscriptable => true) }
app/models/operatingsystem.rb
scoped_search :on => :type, :complete_value => :true, :rename => "family"
scoped_search :on => :title, :complete_value => :true
scoped_search :in => :architectures, :on => :name, :complete_value => :true, :rename => "architecture", :only_explicit => true
scoped_search :in => :media, :on => :name, :complete_value => :true, :rename => "medium", :only_explicit => true
scoped_search :in => :provisioning_templates, :on => :name, :complete_value => :true, :rename => "template", :only_explicit => true
scoped_search :in => :os_parameters, :on => :value, :on_key=> :name, :complete_value => true, :rename => :params, :only_explicit => true
scoped_search :relation => :architectures, :on => :name, :complete_value => :true, :rename => "architecture", :only_explicit => true
scoped_search :relation => :media, :on => :name, :complete_value => :true, :rename => "medium", :only_explicit => true
scoped_search :relation => :provisioning_templates, :on => :name, :complete_value => :true, :rename => "template", :only_explicit => true
scoped_search :relation => :os_parameters, :on => :value, :on_key=> :name, :complete_value => true, :rename => :params, :only_explicit => true
FAMILIES = { 'Debian' => %r{Debian|Ubuntu}i,
'Redhat' => %r{RedHat|Centos|Fedora|Scientific|SLC|OracleLinux}i,
app/models/parameter.rb
belongs_to :location, :foreign_key => :reference_id, :inverse_of => :location_parameters
belongs_to :organization, :foreign_key => :reference_id, :inverse_of => :organization_parameters
# specific children search definitions, required for permission filters autocompletion
scoped_search :in => :domain, :on => :name, :complete_value => true, :rename => 'domain_name'
scoped_search :in => :operatingsystem, :on => :name, :complete_value => true, :rename => 'os_name'
scoped_search :in => :subnet, :on => :name, :complete_value => true, :rename => 'subnet_name'
scoped_search :in => :host, :on => :name, :complete_value => true, :rename => 'host_name'
scoped_search :in => :hostgroup, :on => :name, :complete_value => true, :rename => 'host_group_name'
scoped_search :relation => :domain, :on => :name, :complete_value => true, :rename => 'domain_name'
scoped_search :relation => :operatingsystem, :on => :name, :complete_value => true, :rename => 'os_name'
scoped_search :relation => :subnet, :on => :name, :complete_value => true, :rename => 'subnet_name'
scoped_search :relation => :host, :on => :name, :complete_value => true, :rename => 'host_name'
scoped_search :relation => :hostgroup, :on => :name, :complete_value => true, :rename => 'host_group_name'
if Taxonomy.locations_enabled
scoped_search :in => :location, :on => :name, :complete_value => true, :rename => 'location_name'
scoped_search :relation => :location, :on => :name, :complete_value => true, :rename => 'location_name'
end
if Taxonomy.organizations_enabled
scoped_search :in => :organization, :on => :name, :complete_value => true, :rename => 'organization_name'
scoped_search :relation => :organization, :on => :name, :complete_value => true, :rename => 'organization_name'
end
default_scope -> { order("parameters.name") }
app/models/provisioning_template.rb
scoped_search :on => :snippet, :complete_value => {:true => true, :false => false}
scoped_search :on => :template
scoped_search :in => :operatingsystems, :on => :name, :rename => :operatingsystem, :complete_value => true
scoped_search :in => :environments, :on => :name, :rename => :environment, :complete_value => true
scoped_search :in => :hostgroups, :on => :name, :rename => :hostgroup, :complete_value => true
scoped_search :in => :template_kind, :on => :name, :rename => :kind, :complete_value => true
scoped_search :relation => :operatingsystems, :on => :name, :rename => :operatingsystem, :complete_value => true
scoped_search :relation => :environments, :on => :name, :rename => :environment, :complete_value => true
scoped_search :relation => :hostgroups, :on => :name, :rename => :hostgroup, :complete_value => true
scoped_search :relation => :template_kind, :on => :name, :rename => :kind, :complete_value => true
attr_exportable :kind => Proc.new { |template| template.template_kind.try(:name) },
:oses => Proc.new { |template| template.operatingsystems.map(&:name).uniq }
app/models/puppetclass.rb
default_scope -> { order('puppetclasses.name') }
scoped_search :on => :name, :complete_value => :true
scoped_search :in => :environments, :on => :name, :complete_value => :true, :rename => "environment"
scoped_search :in => :hostgroups, :on => :name, :complete_value => :true, :rename => "hostgroup", :only_explicit => true
scoped_search :in => :config_groups, :on => :name, :complete_value => :true, :rename => "config_group", :only_explicit => true
scoped_search :in => :hosts, :on => :name, :complete_value => :true, :rename => "host", :ext_method => :search_by_host, :only_explicit => true
scoped_search :in => :class_params, :on => :key, :complete_value => :true, :only_explicit => true
scoped_search :relation => :environments, :on => :name, :complete_value => :true, :rename => "environment"
scoped_search :relation => :hostgroups, :on => :name, :complete_value => :true, :rename => "hostgroup", :only_explicit => true
scoped_search :relation => :config_groups, :on => :name, :complete_value => :true, :rename => "config_group", :only_explicit => true
scoped_search :relation => :hosts, :on => :name, :complete_value => :true, :rename => "host", :ext_method => :search_by_host, :only_explicit => true
scoped_search :relation => :class_params, :on => :key, :complete_value => :true, :only_explicit => true
scope :not_in_any_environment, -> { includes(:environment_classes).where(:environment_classes => {:environment_id => nil}) }
app/models/report.rb
def self.inherited(child)
child.instance_eval do
scoped_search :in => :host, :on => :name, :complete_value => true, :rename => :host
scoped_search :in => :environment, :on => :name, :complete_value => true, :rename => :environment
scoped_search :in => :messages, :on => :value, :rename => :log, :only_explicit => true
scoped_search :in => :sources, :on => :value, :rename => :resource, :only_explicit => true
scoped_search :in => :hostgroup, :on => :name, :complete_value => true, :rename => :hostgroup
scoped_search :in => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_fullname
scoped_search :in => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_title
scoped_search :relation => :host, :on => :name, :complete_value => true, :rename => :host
scoped_search :relation => :environment, :on => :name, :complete_value => true, :rename => :environment
scoped_search :relation => :messages, :on => :value, :rename => :log, :only_explicit => true
scoped_search :relation => :sources, :on => :value, :rename => :resource, :only_explicit => true
scoped_search :relation => :hostgroup, :on => :name, :complete_value => true, :rename => :hostgroup
scoped_search :relation => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_fullname
scoped_search :relation => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_title
scoped_search :on => :reported_at, :complete_value => true, :default_order => :desc, :rename => :reported, :only_explicit => true
end
app/models/smart_proxy.rb
scoped_search :on => :name, :complete_value => :true
scoped_search :on => :url, :complete_value => :true
scoped_search :in => :features, :on => :name, :rename => :feature, :complete_value => :true
scoped_search :relation => :features, :on => :name, :rename => :feature, :complete_value => :true
# with proc support, default_scope can no longer be chained
# include all default scoping here
app/models/subnet.rb
scoped_search :on => [:name, :network, :mask, :gateway, :dns_primary, :dns_secondary,
:vlanid, :ipam, :boot_mode, :type], :complete_value => true
scoped_search :in => :domains, :on => :name, :rename => :domain, :complete_value => true
scoped_search :in => :subnet_parameters, :on => :value, :on_key=> :name, :complete_value => true, :only_explicit => true, :rename => :params
scoped_search :relation => :domains, :on => :name, :rename => :domain, :complete_value => true
scoped_search :relation => :subnet_parameters, :on => :value, :on_key=> :name, :complete_value => true, :only_explicit => true, :rename => :params
delegate :supports_ipam_mode?, :supported_ipam_modes, :show_mask?, to: 'self.class'
app/models/user.rb
scoped_search :on => :description, :complete_value => false
scoped_search :on => :admin, :complete_value => { :true => true, :false => false }, :ext_method => :search_by_admin
scoped_search :on => :last_login_on, :complete_value => :true, :only_explicit => true
scoped_search :in => :roles, :on => :name, :rename => :role, :complete_value => true
scoped_search :in => :roles, :on => :id, :rename => :role_id, :complete_enabled => false, :only_explicit => true
scoped_search :in => :cached_usergroups, :on => :name, :rename => :usergroup, :complete_value => true
scoped_search :relation => :roles, :on => :name, :rename => :role, :complete_value => true
scoped_search :relation => :roles, :on => :id, :rename => :role_id, :complete_enabled => false, :only_explicit => true
scoped_search :relation => :cached_usergroups, :on => :name, :rename => :usergroup, :complete_value => true
default_scope lambda {
with_taxonomy_scope do
app/models/usergroup.rb
default_scope -> { order('usergroups.name') }
scope :visible, -> { }
scoped_search :on => :name, :complete_value => :true
scoped_search :in => :roles, :on => :name, :rename => :role, :complete_value => true
scoped_search :in => :roles, :on => :id, :rename => :role_id, :complete_enabled => false, :only_explicit => true
scoped_search :relation => :roles, :on => :name, :rename => :role, :complete_value => true
scoped_search :relation => :roles, :on => :id, :rename => :role_id, :complete_enabled => false, :only_explicit => true
validate :ensure_uniq_name, :ensure_last_admin_remains_admin
accepts_nested_attributes_for :external_usergroups, :reject_if => ->(a) { a[:name].blank? }, :allow_destroy => true
app/views/filters/index.html.erb
<thead>
<tr>
<% unless params[:role_id] %>
<th><%= sort :role, :as => _("Role") %></th>
<th><%= sort :role, :as => _("Role"), :permitted => [:role_id] %></th>
<% end %>
<th><%= sort :resource, :as => s_("Filter|Resource") %></th>
<th><%= sort :resource, :as => s_("Filter|Resource"), :permitted => [:role_id] %></th>
<th><%= s_("Filter|Permissions") %></th>
<th><%= sort :search, :as => s_("Filter|Unlimited") %></th>
<th><%= sort :search, :as => s_("Filter|Override") %></th>
<th><%= sort :search, :as => s_("Filter|Search") %></th>
<th><%= sort :search, :as => s_("Filter|Unlimited"), :permitted => [:role_id] %></th>
<th><%= sort :search, :as => s_("Filter|Override"), :permitted => [:role_id] %></th>
<th><%= sort :search, :as => s_("Filter|Search"), :permitted => [:role_id] %></th>
<th><%= _('Actions') %></th>
</tr>
</thead>
test/factories/user_related.rb
trait :with_widget do
after(:create) { |user,evaluator| FactoryGirl.create(:widget, :user => user) }
end
trait :with_usergroup do
usergroups { [FactoryGirl.create(:usergroup)] }
end
end
factory :permission do
test/models/user_test.rb
assert (users.include? user)
end
test 'can search users by usergroup' do
user = FactoryGirl.create(:user, :with_usergroup)
assert_equal [user], User.search_for("usergroup = #{user.usergroups.first.name}")
end
test 'can set valid timezone' do
timezone = "Fiji"
user = users(:one)

Also available in: Unified diff