Class: Katello::Api::V2::PackagesController

Inherits:
ApiController
  • Object
show all
Includes:
Concerns::Api::V2::RepositoryContentController
Defined in:
app/controllers/katello/api/v2/packages_controller.rb

Instance Method Summary collapse

Methods inherited from ApiController

#check_katello_agent_not_disabled, #deprecate_katello_agent, #empty_search_query?, #full_result_response, #katello_agent_removal_release, #scoped_search, #skip_session

Methods included from Rendering

#respond_for_async, #respond_for_bulk_async, #respond_for_create, #respond_for_destroy, #respond_for_index, #respond_for_show, #respond_for_status, #respond_for_update, #respond_with_template, #respond_with_template_collection, #respond_with_template_resource, #try_specific_collection_template, #try_specific_resource_template

Methods included from Katello::Api::Version2

#api_version

Instance Method Details

#auto_complete_archObject



19
20
21
22
23
24
25
26
27
# File 'app/controllers/katello/api/v2/packages_controller.rb', line 19

def auto_complete_arch
  page_size = Katello::Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
  rpms = Rpm.in_repositories(@repositories)
  col = "#{Rpm.table_name}.arch"
  rpms = rpms.where("#{col} ILIKE ?", "%#{params[:term]}%").select(col).group(col).order(col).limit(page_size)
  rpms = rpms.modular if ::Foreman::Cast.to_bool(params[:modular_only])
  rpms = rpms.non_modular if ::Foreman::Cast.to_bool(params[:non_modular_only])
  render :json => rpms.pluck(col)
end

#auto_complete_nameObject



9
10
11
12
13
14
15
16
17
# File 'app/controllers/katello/api/v2/packages_controller.rb', line 9

def auto_complete_name
  page_size = Katello::Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
  rpms = Rpm.in_repositories(@repositories)
  col = "#{Rpm.table_name}.name"
  rpms = rpms.where("#{Rpm.table_name}.name ILIKE ?", "#{params[:term]}%").select(col).group(col).order(col).limit(page_size)
  rpms = rpms.modular if ::Foreman::Cast.to_bool(params[:modular_only])
  rpms = rpms.non_modular if ::Foreman::Cast.to_bool(params[:non_modular_only])
  render :json => rpms.pluck(col)
end

#available_for_content_view_version(version) ⇒ Object



49
50
51
# File 'app/controllers/katello/api/v2/packages_controller.rb', line 49

def available_for_content_view_version(version)
  version.available_packages
end

#custom_index_relation(collection) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/katello/api/v2/packages_controller.rb', line 53

def custom_index_relation(collection)
  applicable = ::Foreman::Cast.to_bool(params[:packages_restrict_applicable]) || params[:host_id]
  upgradable = ::Foreman::Cast.to_bool(params[:packages_restrict_upgradable])
  not_installed = ::Foreman::Cast.to_bool(params[:packages_restrict_not_installed])

  if upgradable
    collection = collection.installable_for_hosts(@hosts)
  elsif not_installed && params[:host_id]
    host = @hosts.first
    collection = Katello::Rpm.yum_installable_for_host(host)
  elsif applicable
    collection = collection.applicable_to_hosts(@hosts)
  end

  collection
end

#filter_by_content_view_filter(filter, collection) ⇒ Object



80
81
82
83
84
85
86
87
# File 'app/controllers/katello/api/v2/packages_controller.rb', line 80

def filter_by_content_view_filter(filter, collection)
  filtered_rpms = []
  filter.package_rules.each do |rule|
    filtered_rpms += filter.query_rpms_from_collection(collection, rule).pluck(:id)
  end

  collection.where(id: filter.applicable_rpms.pluck(:id) & filtered_rpms)
end

#filter_by_content_view_filter_rule(rule, collection) ⇒ Object



89
90
91
92
93
94
# File 'app/controllers/katello/api/v2/packages_controller.rb', line 89

def filter_by_content_view_filter_rule(rule, collection)
  filter = rule.filter
  filtered_rpms = filter.query_rpms_from_collection(collection, rule).pluck(:id)

  collection.where(id: filter.applicable_rpms.pluck(:id) & filtered_rpms)
end

#final_custom_index_relation(collection) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'app/controllers/katello/api/v2/packages_controller.rb', line 70

def final_custom_index_relation(collection)
  # :packages_restrict_latest is intended to filter the result set after all
  # other constraints have been applied, including the scoped_search
  # constraints.  If any constraints are applied after this, then a package
  # will not be returned if its latest version does not match those
  # constraints, even if an older version does match those constraints.
  collection = Katello::Rpm.latest(collection) if ::Foreman::Cast.to_bool(params[:packages_restrict_latest])
  collection
end

#indexObject



45
46
47
# File 'app/controllers/katello/api/v2/packages_controller.rb', line 45

def index
  super
end