app/controllers/katello/api/v2/errata_controller.rb in katello-2.2.2 vs app/controllers/katello/api/v2/errata_controller.rb in katello-2.4.0.rc1
- old
+ new
@@ -1,22 +1,9 @@
-#
-# 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::ErrataController < Api::V2::ApiController
apipie_concern_subst(:a_resource => N_("an erratum"), :resource => "errata")
include Katello::Concerns::Api::V2::RepositoryContentController
- include Katello::Concerns::Api::V2::RepositoryDbContentController
api :GET, "/errata", N_("List errata")
param :content_view_version_id, :identifier, :desc => N_("content view version identifier")
param :content_view_filter_id, :identifier, :desc => N_("content view filter identifier")
param :repository_id, :number, :desc => N_("repository identifier")
@@ -27,25 +14,41 @@
param_group :search, Api::V2::ApiController
def index
super
end
+ def available_for_content_view_filter(filter, collection)
+ collection = filter_by_content_view(filter, collection)
+ ids = Katello::ContentViewErratumFilterRule.where(:content_view_filter_id => filter.id).pluck("errata_id")
+ collection = collection.where("errata_id not in (?)", ids) unless ids.empty?
+ collection = collection.where('issued >= ?', params[:start_date]) if params[:start_date]
+ collection = collection.where('issued <= ?', params[:end_date]) if params[:end_date]
+ collection = collection.of_type(params[:types]) if params[:types]
+ collection
+ end
+
def custom_index_relation(collection)
collection = filter_by_cve(params[:cve], collection) if params[:cve]
- if params[:errata_restrict_applicable] && params[:errata_restrict_applicable].to_bool
+ if ::Foreman::Cast.to_bool(params[:errata_restrict_applicable])
collection = collection.applicable_to_systems(System.readable)
end
- if params[:errata_restrict_installable] && params[:errata_restrict_installable].to_bool
+ if ::Foreman::Cast.to_bool(params[:errata_restrict_installable])
collection = collection.installable_for_systems(System.readable)
end
collection
end
private
def filter_by_cve(cve, collection)
collection.joins(:cves).where('katello_erratum_cves.cve_id' => cve)
+ end
+
+ def filter_by_content_view(filter, collection)
+ repos = Katello::ContentView.find(filter.content_view_id).repositories
+ uuid = repos.map { |r| r.send("errata").pluck("uuid") }
+ filter_by_ids(uuid, collection)
end
def filter_by_content_view_filter(filter, collection)
collection.where(:errata_id => filter.erratum_rules.pluck(:errata_id))
end