Module: Katello::Concerns::ContentFacetHostExtensions::ClassMethods

Defined in:
app/models/katello/concerns/content_facet_host_extensions.rb

Instance Method Summary collapse

Instance Method Details

#find_by_applicable_debs(_key, operator, value) ⇒ Object



100
101
102
103
104
105
106
107
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 100

def find_by_applicable_debs(_key, operator, value)
  hosts = find_by_debs(::Host::Managed.joins(:applicable_debs), operator, value)
  if hosts.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Host::Managed.table_name}.id IN (#{hosts.pluck(:id).join(',')})" }
  end
end

#find_by_applicable_errata(_key, operator, value) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 80

def find_by_applicable_errata(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Erratum.table_name}.errata_id #{operator} ?", value_to_sql(operator, value)])
  hosts = ::Host::Managed.joins(:applicable_errata).where(conditions)
  if hosts.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Host::Managed.table_name}.id IN (#{hosts.pluck(:id).join(',')})" }
  end
end

#find_by_applicable_rpms(_key, operator, value) ⇒ Object



118
119
120
121
122
123
124
125
126
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 118

def find_by_applicable_rpms(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Rpm.table_name}.nvra #{operator} ?", value_to_sql(operator, value)])
  hosts = ::Host::Managed.joins(:applicable_rpms).where(conditions)
  if hosts.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Host::Managed.table_name}.id IN (#{hosts.pluck(:id).join(',')})" }
  end
end

#find_by_installable_debs(_key, operator, value) ⇒ Object



109
110
111
112
113
114
115
116
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 109

def find_by_installable_debs(_key, operator, value)
  facets = find_by_debs(Katello::Host::ContentFacet.joins_installable_debs, operator, value)
  if facets.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Host::Managed.table_name}.id IN (#{facets.pluck(:host_id).join(',')})" }
  end
end

#find_by_installable_errata(_key, operator, value) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 90

def find_by_installable_errata(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Erratum.table_name}.errata_id #{operator} ?", value_to_sql(operator, value)])
  facets = Katello::Host::ContentFacet.joins_installable_errata.where(conditions)
  if facets.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Host::Managed.table_name}.id IN (#{facets.pluck(:host_id).join(',')})" }
  end
end

#find_by_installable_rpms(_key, operator, value) ⇒ Object



128
129
130
131
132
133
134
135
136
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 128

def find_by_installable_rpms(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Rpm.table_name}.nvra #{operator} ?", value_to_sql(operator, value)])
  facets = Katello::Host::ContentFacet.joins_installable_rpms.where(conditions)
  if facets.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Host::Managed.table_name}.id IN (#{facets.pluck(:host_id).join(',')})" }
  end
end

#find_by_repository_content_label(_key, operator, value) ⇒ Object



138
139
140
141
142
143
144
145
146
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 138

def (_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Content.table_name}.label #{operator} ?", value_to_sql(operator, value)])
  facets = Katello::Host::ContentFacet.joins_repositories.where(conditions)
  if facets.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Host::Managed.table_name}.id IN (#{facets.pluck(:host_id).join(',')})" }
  end
end

#find_by_repository_name(_key, operator, value) ⇒ Object



148
149
150
151
152
153
154
155
156
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 148

def find_by_repository_name(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::RootRepository.table_name}.name #{operator} ?", value_to_sql(operator, value)])
  facets = Katello::Host::ContentFacet.joins_repositories.where(conditions)
  if facets.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Host::Managed.table_name}.id IN (#{facets.pluck(:host_id).join(',')})" }
  end
end

#in_content_view_environment(content_view: nil, lifecycle_environment: nil) ⇒ Object



169
170
171
172
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 169

def in_content_view_environment(content_view: nil, lifecycle_environment: nil)
  Rails.logger.warn "DEPRECATION WARNING: in_content_view_environment is deprecated and will be removed in Katello 4.8.  Please use in_content_view_environments instead."
  in_content_view_environments(:content_views => content_view, :lifecycle_environments => lifecycle_environment)
end

#in_content_view_environments(content_views: nil, lifecycle_environments: nil) ⇒ Object



158
159
160
161
162
163
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 158

def in_content_view_environments(content_views: nil, lifecycle_environments: nil)
  relation = self.joins(:content_facet => {:content_view_environment_content_facets => :content_view_environment })
  relation = relation.where("#{::Katello::ContentViewEnvironment.table_name}.content_view_id" => content_views) if content_views
  relation = relation.where("#{::Katello::ContentViewEnvironment.table_name}.environment_id" => lifecycle_environments) if lifecycle_environments
  relation
end

#in_environment(lifecycle_environment) ⇒ Object



174
175
176
177
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 174

def in_environment(lifecycle_environment)
  Rails.logger.warn "DEPRECATION WARNING: in_environment is deprecated and will be removed in Katello 4.9.  Please use in_environments instead."
  in_environments(lifecycle_environment)
end

#in_environments(lifecycle_environments) ⇒ Object



165
166
167
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 165

def in_environments(lifecycle_environments)
  in_content_view_environments(:lifecycle_environments => lifecycle_environments)
end