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

#full_result_response, #resource_class, #scoped_search

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



89
90
91
92
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 89

def add_products
  sync_task(::Actions::Katello::SyncPlan::AddProducts, @sync_plan, params[:product_ids])
  respond_for_show
end

#createObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 47

def create
  sync_date = sync_plan_params[:sync_date].to_time

  unless sync_date.is_a?(Time)
    fail _("Date format is incorrect.")
  end

  @sync_plan = SyncPlan.new(sync_plan_params)
  @sync_plan.organization = @organization
  @sync_plan.save!

  respond_for_show(:resource => @sync_plan)
end

#destroyObject



81
82
83
84
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 81

def destroy
  sync_task(::Actions::Katello::SyncPlan::Destroy, @sync_plan)
  respond_for_show(:resource => @sync_plan)
end

#indexObject



24
25
26
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 24

def index
  respond_for_index(:collection => scoped_search(index_relation.uniq, :name, :desc))
end

#index_relationObject



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

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



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

def remove_products
  sync_task(::Actions::Katello::SyncPlan::RemoveProducts, @sync_plan, params[:product_ids])
  respond_for_show
end

#showObject



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

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

#syncObject



105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 105

def sync
  syncable_products = @sync_plan.products.syncable
  syncable_repositories = Repository.where(:product_id => syncable_products).has_url

  task = async_task(::Actions::BulkAction,
                    ::Actions::Katello::Repository::Sync,
                    syncable_repositories)

  respond_for_async :resource => task
rescue Foreman::Exception
  raise HttpErrors::BadRequest, _("No products within sync plan")
end

#updateObject



66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/katello/api/v2/sync_plans_controller.rb', line 66

def update
  sync_date = sync_plan_params.try(:[], :sync_date).try(:to_time)

  if !sync_date.nil? && !sync_date.is_a?(Time)
    fail _("Date format is incorrect.")
  end

  sync_task(::Actions::Katello::SyncPlan::Update, @sync_plan, sync_plan_params)
  respond_for_show(:resource => @sync_plan)
end