app/controllers/katello/api/v2/system_errata_controller.rb in katello-2.2.2 vs app/controllers/katello/api/v2/system_errata_controller.rb in katello-2.4.0.rc1
- old
+ new
@@ -1,27 +1,38 @@
-#
-# Copyright 2014 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public
-# License as published by the Free Software Foundation; either version
-# 2 of the License (GPLv2) or (at your option) any later version.
-# There is NO WARRANTY for this software, express or implied,
-# including the implied warranties of MERCHANTABILITY,
-# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
-# have received a copy of GPLv2 along with this software; if not, see
-# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-
module Katello
class Api::V2::SystemErrataController < Api::V2::ApiController
+ include Katello::Concerns::FilteredAutoCompleteSearch
+
before_filter :find_system
before_filter :find_errata_ids, :only => :apply
+ before_filter :find_environment, :only => :index
+ before_filter :find_content_view, :only => :index
resource_description do
api_version 'v2'
api_base_url "/katello/api"
end
+ def resource_class
+ Erratum
+ end
+
+ api :GET, "/systems/:system_id/errata", N_("List errata available for the content host"), :deprecated => true
+ param :system_id, :identifier, :desc => N_("UUID of the content host"), :required => true
+ param :content_view_id, :number, :desc => N_("Calculate Applicable Errata based on a particular Content View"), :required => false
+ param :environment_id, :number, :desc => N_("Calculate Applicable Errata based on a particular Environment"), :required => false
+ param_group :search, Api::V2::ApiController
+ def index
+ if (params[:content_view_id] && params[:environment_id].nil?) || (params[:environment_id] && params[:content_view_id].nil?)
+ fail _("Either both parameters 'content_view_id' and 'environment_id' should be specified or neither should be specified")
+ end
+
+ collection = scoped_search(index_relation, 'updated_at', 'desc', :resource_class => Erratum, :includes => [:cves])
+ @installable_errata_ids = @system.installable_errata.pluck("#{Katello::Erratum.table_name}.id")
+ respond_for_index :collection => collection
+ end
+
api :PUT, "/systems/:system_id/errata/apply", N_("Schedule errata for installation"), :deprecated => true
param :system_id, :identifier, :desc => N_("System UUID"), :required => true
param :errata_ids, Array, :desc => N_("List of Errata ids to install"), :required => true
def apply
task = async_task(::Actions::Katello::System::Erratum::Install, @system, params[:errata_ids])
@@ -34,13 +45,27 @@
def show
errata = Erratum.find_by_errata_id(params[:id])
respond_for_show :resource => errata
end
+ protected
+
+ def index_relation
+ @system.installable_errata(@environment, @content_view)
+ end
+
private
+ def find_content_view
+ @content_view = ContentView.readable.find(params[:content_view_id]) if params[:content_view_id]
+ end
+
+ def find_environment
+ @environment = KTEnvironment.readable.find(params[:environment_id]) if params[:environment_id]
+ end
+
def find_system
- @system = System.first(:conditions => { :uuid => params[:system_id] })
+ @system = System.where(:uuid => params[:system_id]).first
fail HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:system_id] if @system.nil?
@system
end
def find_errata_ids