Skip to content

Commit

Permalink
Fixes #11370: Bulk content host actions weren't respecting organizati…
Browse files Browse the repository at this point in the history
…on param.
  • Loading branch information
ehelms committed Aug 15, 2015
1 parent 86a1227 commit 582a318
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions app/controllers/katello/concerns/api/v2/bulk_systems_extensions.rb
Expand Up @@ -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
Expand All @@ -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
6 changes: 2 additions & 4 deletions 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)
Expand Down

0 comments on commit 582a318

Please sign in to comment.