diff --git a/app/controllers/katello/api/v2/systems_bulk_actions_controller.rb b/app/controllers/katello/api/v2/systems_bulk_actions_controller.rb index 02a5ebd536a..b3cdcbb0c76 100644 --- a/app/controllers/katello/api/v2/systems_bulk_actions_controller.rb +++ b/app/controllers/katello/api/v2/systems_bulk_actions_controller.rb @@ -2,7 +2,6 @@ module Katello class Api::V2::SystemsBulkActionsController < Api::V2::ApiController include Concerns::Api::V2::BulkSystemsExtensions - before_filter :find_organization before_filter :find_host_collections, :only => [:bulk_add_host_collections, :bulk_remove_host_collections] before_filter :find_environment, :only => [:environment_content_view] before_filter :find_content_view, :only => [:environment_content_view] @@ -226,7 +225,7 @@ def content_action task = async_task(::Actions::BulkAction, ::Actions::Katello::System::Erratum::ApplicableErrataInstall, @systems, errata_uuids.uniq) respond_for_async :resource => task else - action = Katello::BulkActions.new(User.current, @organization, @systems) + action = Katello::BulkActions.new(@systems) job = action.send(PARAM_ACTIONS[params[:action]][params[:content_type]], params[:content]) respond_for_show :template => 'job', :resource => job end diff --git a/app/controllers/katello/concerns/api/v2/bulk_systems_extensions.rb b/app/controllers/katello/concerns/api/v2/bulk_systems_extensions.rb index 7d901b1c76c..d6cff281892 100644 --- a/app/controllers/katello/concerns/api/v2/bulk_systems_extensions.rb +++ b/app/controllers/katello/concerns/api/v2/bulk_systems_extensions.rb @@ -5,18 +5,20 @@ module Api::V2::BulkSystemsExtensions def find_bulk_systems(perm_method, bulk_params, restrict_to = nil) #works on a structure of param_group bulk_params and transforms it into a list of systems + organization = find_organization bulk_params[:included] ||= {} bulk_params[:excluded] ||= {} @systems = [] unless bulk_params[:included][:ids].blank? @systems = System.send(perm_method).where(:uuid => bulk_params[:included][:ids]) - @systems.where('uuid not in (?)', bulk_params[:excluded]) unless bulk_params[:excluded][:ids].blank? + @systems = @systems.where(:environment_id => organization.kt_environments) if organization + @systems = @systems.where('uuid not in (?)', bulk_params[:excluded]) unless bulk_params[:excluded][:ids].blank? @systems = restrict_to.call(@systems) if restrict_to end if bulk_params[:included][:search] - ids = find_system_ids_by_search(bulk_params[:included][:search]) + ids = find_system_ids_by_search(bulk_params[:included][:search], organization) search_systems = System.send(perm_method).where(:id => ids) search_systems = search_systems.where('uuid not in (?)', bulk_params[:excluded][:ids]) unless bulk_params[:excluded][:ids].blank? search_systems = restrict_to.call(search_systems) if restrict_to @@ -31,15 +33,19 @@ def find_bulk_systems(perm_method, bulk_params, restrict_to = nil) @systems end - def find_system_ids_by_search(search) + def find_system_ids_by_search(search, organization) options = { - :filters => System.readable_search_filters(@organization), + :filters => System.readable_search_filters(organization), :load_records? => false, :full_result => true, :fields => [:id] } item_search(System, {:search => search}, options)[:results].collect { |i| i.id } end + + def find_organization + Organization.find_by_id(params[:organization_id]) + end end end end diff --git a/app/lib/katello/bulk_actions.rb b/app/lib/katello/bulk_actions.rb index 51605cbea40..cfa867c67f2 100644 --- a/app/lib/katello/bulk_actions.rb +++ b/app/lib/katello/bulk_actions.rb @@ -1,11 +1,9 @@ module Katello class BulkActions - attr_accessor :systems, :user, :organization + attr_accessor :systems - def initialize(user, org, systems) + def initialize(systems) self.systems = systems - self.organization = org - self.user = user end def install_packages(packages)