Class: Katello::Api::V2::AlternateContentSourcesController

Inherits:
ApiController
  • Object
show all
Includes:
Concerns::FilteredAutoCompleteSearch
Defined in:
app/controllers/katello/api/v2/alternate_content_sources_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

#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

#createObject



71
72
73
74
75
76
# File 'app/controllers/katello/api/v2/alternate_content_sources_controller.rb', line 71

def create
  @alternate_content_source = ::Katello::AlternateContentSource.new(acs_params.except(:smart_proxy_ids, :smart_proxy_names, :product_ids))
  sync_task(::Actions::Katello::AlternateContentSource::Create, @alternate_content_source, @smart_proxies, @products)
  @alternate_content_source.reload
  respond_for_create(resource: @alternate_content_source)
end

#destroyObject



104
105
106
107
# File 'app/controllers/katello/api/v2/alternate_content_sources_controller.rb', line 104

def destroy
  sync_task(::Actions::Katello::AlternateContentSource::Destroy, @alternate_content_source)
  respond_for_destroy
end

#indexObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/katello/api/v2/alternate_content_sources_controller.rb', line 33

def index
  respond_to do |format|
    format.csv do
      options[:csv] = true
      alternate_content_sources = scoped_search(index_relation, :name, :asc)
      if @acs.custom? || @acs.rhui?
        csv_response(alternate_content_sources,
                    [:id, :name, :description, :label, :base_url, :subpaths, :content_type, :alternate_content_source_type],
                    ['Id', 'Name', 'Description', 'label', 'Base URL', 'Subpaths', 'Content Type', 'Alternate Content Source Type'])
      elsif @acs.simplified?
        csv_response(alternate_content_sources,
                    [:id, :name, :description, :label, :content_type, :alternate_content_source_type, :products],
                    ['Id', 'Name', 'Description', 'label', 'Content Type', 'Alternate Content Source Type', 'Products'])
      end
    end
    format.any do
      alternate_content_sources = scoped_search(index_relation, :name, :asc)
      respond(collection: alternate_content_sources)
    end
  end
end

#index_relationObject



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

def index_relation
  query = AlternateContentSource.readable.distinct
  query = query.where(name: params[:name]) if params[:name]
  query
end

#refreshObject



111
112
113
114
# File 'app/controllers/katello/api/v2/alternate_content_sources_controller.rb', line 111

def refresh
  task = async_task(::Actions::Katello::AlternateContentSource::Refresh, @alternate_content_source)
  respond_for_async :resource => task
end

#showObject



63
64
65
# File 'app/controllers/katello/api/v2/alternate_content_sources_controller.rb', line 63

def show
  respond_for_show(:resource => @alternate_content_source)
end

#updateObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/katello/api/v2/alternate_content_sources_controller.rb', line 81

def update
  # If a user doesn't include smart proxies or products in the update call, don't accidentally remove all of them.
  if params[:smart_proxy_ids].nil? && params[:smart_proxy_names].nil?
    @smart_proxies = @alternate_content_source.smart_proxies
  elsif params[:smart_proxy_ids] == [] || params[:smart_proxy_names] == []
    @smart_proxies = []
  else
    find_smart_proxies
  end
  if params[:product_ids].nil?
    @products = @alternate_content_source.products
  elsif params[:product_ids] == []
    @products = []
  else
    find_products
  end

  sync_task(::Actions::Katello::AlternateContentSource::Update, @alternate_content_source, @smart_proxies, @products, acs_params.except(:smart_proxy_ids, :smart_proxy_names, :product_ids))
  respond_for_show(:resource => @alternate_content_source)
end