Class: Katello::Api::V2::ContentViewFilterRulesController

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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/katello/api/v2/content_view_filter_rules_controller.rb', line 43

def create
  rule_clazz = ContentViewFilter.rule_class_for(@filter)

  rules = (rule_params[:name] || []).map do |name|
    rule_clazz.create!(rule_params.except(:name).merge(:filter => @filter, name: name))
  end

  rules += (rule_params[:errata_ids] || []).map do |errata_id|
    rule_clazz.create!(rule_params.except(:errata_ids)
      .merge(filter: @filter, errata_id: errata_id))
  end
  if rule_params[:module_stream_ids]
    rules += (rule_params[:module_stream_ids] || []).map do |module_stream_id|
      rule_clazz.create!(rule_params.except(:module_stream_ids)
        .merge(filter: @filter, module_stream_id: module_stream_id))
    end
  end

  if rules.empty?
    rules = [rule_clazz.create!(rule_params.merge(:filter => @filter))]
  end

  if rules.many?
    respond_for_index(:collection => {:results => rules}, :template => 'index')
  else
    respond_for_create resource: rules.first
  end
end

#destroyObject



109
110
111
112
# File 'app/controllers/katello/api/v2/content_view_filter_rules_controller.rb', line 109

def destroy
  @rule.destroy
  respond_for_show :resource => @rule
end

#indexObject



12
13
14
# File 'app/controllers/katello/api/v2/content_view_filter_rules_controller.rb', line 12

def index
  respond(collection: scoped_search(index_relation, :id, :asc, resource_class: ContentViewFilter.rule_class_for(@filter)))
end

#index_relationObject



16
17
18
19
20
21
# File 'app/controllers/katello/api/v2/content_view_filter_rules_controller.rb', line 16

def index_relation
  query = ContentViewFilter.rule_class_for(@filter).where(content_view_filter_id: @filter.id)
  query = query.where(:name => params[:name]) if params[:name]
  query = query.where(:errata_id => params[:errata_id]) if params[:errata_id]
  query
end

#resource_classObject



23
24
25
# File 'app/controllers/katello/api/v2/content_view_filter_rules_controller.rb', line 23

def resource_class
  ContentViewFilter.rule_class_for(@filter)
end

#showObject



75
76
77
# File 'app/controllers/katello/api/v2/content_view_filter_rules_controller.rb', line 75

def show
  respond :resource => @rule
end

#updateObject



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/katello/api/v2/content_view_filter_rules_controller.rb', line 92

def update
  update_params = rule_params
  update_params[:name] = update_params[:name].first if update_params[:name]

  if @rule.filter.content_type == ContentViewPackageFilter::CONTENT_TYPE
    update_params[:version] = "" unless rule_params[:version]
    update_params[:min_version] = "" unless rule_params[:min_version]
    update_params[:max_version] = "" unless rule_params[:max_version]
  end

  @rule.update!(update_params)
  respond :resource => @rule
end