Class: Katello::Api::V2::ModuleStreamsController

Inherits:
ApiController
  • Object
show all
Extended by:
Apipie::DSL::Concern
Includes:
Concerns::Api::V2::RepositoryContentController
Defined in:
app/controllers/katello/api/v2/module_streams_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, #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

#all_for_content_view_filter(filter, _collection) ⇒ Object



38
39
40
41
42
# File 'app/controllers/katello/api/v2/module_streams_controller.rb', line 38

def all_for_content_view_filter(filter, _collection)
  available_ids = ModuleStream.joins(:repositories).merge(filter.applicable_repos)&.pluck(:id) || []
  added_ids = filter&.module_stream_rules&.pluck(:module_stream_id) || []
  ModuleStream.where(id: available_ids + added_ids)
end

#available_for_content_view_filter(filter, _collection) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/katello/api/v2/module_streams_controller.rb', line 44

def available_for_content_view_filter(filter, _collection)
  collection_ids = []
  current_ids = filter.module_stream_rules.map(&:module_stream_id)
  filter.applicable_repos.each do |repo|
    collection_ids.concat(repo.module_stream_ids)
  end
  collection = ModuleStream.where(:id => collection_ids)
  collection = collection.where("id not in (?)", current_ids) unless current_ids.empty?
  collection
end

#custom_index_relation(collection) ⇒ Object



26
27
28
29
30
31
32
# File 'app/controllers/katello/api/v2/module_streams_controller.rb', line 26

def custom_index_relation(collection)
  if @host_ids
    collection.available_for_hosts(@host_ids)
  else
    collection
  end
end

#default_sortObject



34
35
36
# File 'app/controllers/katello/api/v2/module_streams_controller.rb', line 34

def default_sort
  %w(name asc)
end

#filter_by_content_view(filter, collection) ⇒ Object



55
56
57
58
59
# File 'app/controllers/katello/api/v2/module_streams_controller.rb', line 55

def filter_by_content_view(filter, collection)
  repos = Katello::ContentView.find(filter.content_view_id).repositories
  ids = repos.map { |r| r.send(:module_stream_ids) }.flatten
  filter_by_ids(ids, collection)
end

#filter_by_content_view_filter(filter, collection) ⇒ Object



61
62
63
# File 'app/controllers/katello/api/v2/module_streams_controller.rb', line 61

def filter_by_content_view_filter(filter, collection)
  collection.where(:id => filter.module_stream_rules.pluck(:module_stream_id))
end

#indexObject



15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/katello/api/v2/module_streams_controller.rb', line 15

def index
  if @name_stream_only
    sort_by, sort_order, options = sort_options
    options[:group] = [:name, :stream]
    respond(:collection => scoped_search(index_relation, sort_by, sort_order, options),
            :template => 'name_streams')
  else
    super
  end
end