Class: Katello::Api::V2::ContentViewRepositoriesController

Inherits:
ApiController
  • Object
show all
Includes:
Concerns::FilteredAutoCompleteSearch
Defined in:
app/controllers/katello/api/v2/content_view_repositories_controller.rb

Constant Summary

Constants included from Concerns::FilteredAutoCompleteSearch

Concerns::FilteredAutoCompleteSearch::PAGE_SIZE

Instance Method Summary collapse

Methods included from Concerns::FilteredAutoCompleteSearch

#auto_complete_search

Methods inherited from ApiController

#empty_search_query?, #full_result_response, #resource_class, #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

#show_allObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/katello/api/v2/content_view_repositories_controller.rb', line 14

def show_all
  kr = Katello::Repository.table_name
  krr = Katello::RootRepository.table_name
  kcvr = Katello::ContentViewRepository.table_name
  join_query = <<-SQL
    LEFT OUTER JOIN #{kcvr}
    ON #{kr}.id = #{kcvr}.repository_id
    AND #{kcvr}.content_view_id = #{@content_view.id}
  SQL
  order_query = <<-SQL
    CAST (#{kcvr}.repository_id as BOOLEAN) ASC, #{krr}.name
  SQL

  query = Katello::Repository.readable.in_default_view.in_organization(@organization)
  if @content_view.rolling
    # Exclude container push repositories
    query = query.joins(:root).where(katello_root_repositories: { is_container_push: false })
  end

  query = query.with_type(params[:content_type]) if params[:content_type]
  # Use custom sort to perform the join and order since we need to order by specific content_view
  # and the ORDER BY query needs access to the katello_content_view_repositories table
  custom_sort = ->(sort_query) { sort_query.joins(:root).joins(join_query).order(Arel.sql(order_query)) }
  options = { resource_class: Katello::Repository, custom_sort: custom_sort }
  repos = scoped_search(query, nil, nil, options)

  respond_for_index(:collection => repos)
end