Sha256: 22ddc994b63089fe764c69b3fd617bd0f8c13cd700d5302bb38390ec584346c7

Contents?: true

Size: 1.86 KB

Versions: 7

Compression:

Stored size: 1.86 KB

Contents

module Katello
  class Api::V2::ContentViewRepositoriesController < Api::V2::ApiController
    # There are other Content View Repository related endpoints that are in RepositoriesController
    include Katello::Concerns::FilteredAutoCompleteSearch

    before_action :find_content_view
    before_action :find_organization_from_cv

    # content_views/:id/repositories/show_all
    # Shows all repositories, added and available to add, for a content view
    # Undocumented endpoint since the functionality exists in separate calls already.
    # This was created for ease of pagination and search for the UI
    param :id, :number, desc: N_("Content View id"), required: true
    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)
      # 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(order_query) }
      options = { resource_class: Katello::Repository, custom_sort: custom_sort }
      repos = scoped_search(query, nil, nil, options)

      respond_for_index(:collection => repos)
    end

    private

    def find_content_view
      @content_view = ContentView.find(params[:content_view_id])
    end

    def find_organization_from_cv
      @organization = @content_view.organization
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
katello-3.17.3 app/controllers/katello/api/v2/content_view_repositories_controller.rb
katello-3.17.2 app/controllers/katello/api/v2/content_view_repositories_controller.rb
katello-3.17.1 app/controllers/katello/api/v2/content_view_repositories_controller.rb
katello-3.17.0 app/controllers/katello/api/v2/content_view_repositories_controller.rb
katello-3.17.0.rc2.2 app/controllers/katello/api/v2/content_view_repositories_controller.rb
katello-3.17.0.rc2.1 app/controllers/katello/api/v2/content_view_repositories_controller.rb
katello-3.17.0.rc2 app/controllers/katello/api/v2/content_view_repositories_controller.rb