Skip to content

Commit

Permalink
Refs #36878 - move bulk actions to foreman
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Nov 6, 2023
1 parent a4c7889 commit bcd4478
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 187 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Katello
class Api::V2::ContentViewVersionsController < Api::V2::ApiController
include Concerns::Api::V2::BulkHostsExtensions
include ::Api::V2::BulkHostsExtension
include Katello::Concerns::FilteredAutoCompleteSearch

before_action :find_authorized_katello_resource, :only => [:show, :update, :promote, :destroy, :republish_repositories]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Katello
# this is Katello's host bulk actions controller, not to be confused with Foreman's
class Api::V2::HostsBulkActionsController < Api::V2::ApiController
include Concerns::Api::V2::BulkHostsExtensions
include ::Api::V2::BulkHostsExtension
include Katello::Concerns::Api::V2::ContentOverridesController
include Katello::ContentSourceHelper
include ::Foreman::Renderer::Scope::Macros::Base
Expand Down
47 changes: 0 additions & 47 deletions app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/katello/remote_execution_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Katello
if Katello.with_remote_execution?
class RemoteExecutionController < JobInvocationsController
include Concerns::Api::V2::BulkHostsExtensions
include ::Api::V2::BulkHostsExtension
include Concerns::Api::V2::HostErrataExtensions

def new
Expand Down
141 changes: 4 additions & 137 deletions test/controllers/api/v2/concerns/bulk_hosts_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

module Katello
class TestController
include Concerns::Api::V2::BulkHostsExtensions
# this now tests the bulk hosts extension that was moved to Foreman
include ::Api::V2::BulkHostsExtension

def initialize(params = {})
@params = params
Expand Down Expand Up @@ -35,48 +36,8 @@ def setup
@controller = TestController.new(organization_id: @organization.id)
end

def test_search
bulk_params = {
:included => {
:search => "name = #{@host1.name}"
}
}
result = @controller.find_bulk_hosts(@edit, bulk_params)

assert_equal result, [@host1]
end

def test_search_restrict
bulk_params = {
:included => {
:search => "name ~ host"
}
}
restrict = lambda { |hosts| hosts.where("id != #{@host2.id}") }
result = @controller.find_bulk_hosts(@edit, bulk_params, restrict)

assert_includes result, @host1
refute_includes result, @host2
assert_includes result, @host3
end

def test_search_exclude
bulk_params = {
:included => {
:search => "name ~ host"
},
:excluded => {
:ids => [@host1.id]
}
}
result = @controller.find_bulk_hosts(@edit, bulk_params)

refute_includes result, @host1
assert_includes result, @host2
assert_includes result, @host3
end

def test_select_all_hosts_for_errata_apply
def test_select_all_hosts_for_errata_apply_bastion
# bastion sends the install_all param
@controller.instance_variable_set(
:@params,
{
Expand All @@ -86,99 +47,5 @@ def test_select_all_hosts_for_errata_apply

assert_equal_arrays [@host1, @host2, @host3, @host4, @host5, @host6], result
end

def test_no_hosts_specified
bulk_params = {
:included => {}
}

assert_raises(HttpErrors::BadRequest) do
@controller.find_bulk_hosts(@edit, bulk_params)
end
end

def test_ids
bulk_params = {
:included => {
:ids => [@host1.id, @host2.id]
}
}
result = @controller.find_bulk_hosts(@edit, bulk_params)

assert_equal [@host1, @host2].sort, result.sort
end

def test_ids_excluded
bulk_params = {
:included => {
:ids => [@host1.id, @host2.id]
},
:excluded => {
:ids => [@host2.id]
}
}
result = @controller.find_bulk_hosts(@edit, bulk_params)

assert_equal result, [@host1]
end

def test_ids_restricted
bulk_params = {
:included => {
:ids => [@host1.id, @host2.id]
}
}
restrict = lambda { |hosts| hosts.where("id != #{@host2.id}") }
result = @controller.find_bulk_hosts(@edit, bulk_params, restrict)

assert_equal result, [@host1]
end

def test_included_ids_with_nil_scoped_search
bulk_params = {
:included => {
:ids => [@host1.id, @host2.id],
:search => nil
}
}

result = @controller.find_bulk_hosts(@edit, bulk_params)

assert_equal [@host1, @host2].sort, result.sort
end

def test_ids_with_scoped_search
bulk_params = {
:included => {
:ids => [@host1.id, @host2.id],
:search => "name != #{@host2.name}"
}
}

result = @controller.find_bulk_hosts(@edit, bulk_params)

assert_equal result, [@host1]
end

def test_forbidden
bulk_params = {
:included => {
:ids => [@host1.id]
},
:excluded => {
:ids => [@host1.id]
}
}

assert_raises(HttpErrors::Forbidden) do
@controller.find_bulk_hosts(@edit, bulk_params)
end
end

def test_empty_params
assert_raises(HttpErrors::BadRequest) do
@controller.find_bulk_hosts(@edit, {})
end
end
end
end

0 comments on commit bcd4478

Please sign in to comment.