Class: Katello::Api::V2::SyncPlansController

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

#add_productsObject



94
95
96
97
98
99
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 94

def add_products
  products = ::Katello::Product.where(:id => params[:product_ids]).editable
  @sync_plan.product_ids = (@sync_plan.product_ids + products.collect { |p| p.id }).uniq
  @sync_plan.save!
  respond_for_show
end

#createObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 52

def create
  if params[:sync_plan].key?(:enabled) || params.key?(:enabled)
    enabled = params[:sync_plan][:enabled] || params[:enabled]
  end
  unless sync_plan_params[:sync_date].to_time(:utc).is_a?(Time)
    fail _("Date format is incorrect.")
  end
  @sync_plan = SyncPlan.new(sync_plan_params.except(:enabled))
  @sync_plan.organization = @organization
  @sync_plan.save_with_logic!(enabled)
  respond_for_create(:resource => @sync_plan)
end

#destroyObject



86
87
88
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 86

def destroy
  @sync_plan.destroy!
end

#indexObject



29
30
31
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 29

def index
  respond_for_index(:collection => scoped_search(index_relation.distinct, :name, :asc))
end

#index_relationObject



33
34
35
36
37
38
39
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 33

def index_relation
  query = SyncPlan.readable.where(:organization_id => @organization.id)
  query = query.where(:name => params[:name]) if params[:name]
  query = query.where(:sync_date => params[:sync_date]) if params[:sync_date]
  query = query.where(:interval => params[:interval]) if params[:interval]
  query
end

#remove_productsObject



105
106
107
108
109
110
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 105

def remove_products
  products = ::Katello::Product.where(:id => params[:product_ids]).editable
  @sync_plan.product_ids = (@sync_plan.product_ids - products.collect { |p| p.id }).uniq
  @sync_plan.save!
  respond_for_show
end

#showObject



45
46
47
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 45

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

#syncObject



115
116
117
118
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 115

def sync
  task = async_task(::Actions::Katello::SyncPlan::Run, @sync_plan)
  respond_for_async :resource => task
end

#updateObject



70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 70

def update
  sync_date = sync_plan_params.try(:[], :sync_date).try(:to_time)
  params[:enabled] = params[:enabled] || params[:sync_plan][:enabled]
  toggle_enabled = (@sync_plan.enabled? != params[:enabled]) && !params[:enabled].nil? && !@sync_plan.foreman_tasks_recurring_logic.cancelled?
  @sync_plan.foreman_tasks_recurring_logic.enabled = params[:enabled] if toggle_enabled
  if !sync_date.nil? && !sync_date.is_a?(Time)
    fail _("Date format is incorrect.")
  end
  @sync_plan.update_attributes_with_logics!(sync_plan_params) if sync_plan_params
  respond_for_show(:resource => @sync_plan)
end