Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #26697 - adding bulk actions (#92)
- Loading branch information
Showing
8 changed files
with
281 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%= render 'selected_hosts', :hosts => @hosts %> | ||
<%= form_for :salt_environment, :url => update_multiple_salt_environment_hosts_path(:host_ids => params[:host_ids]) do |f| %> | ||
<%= selectable_f f, :id, [[_("Select salt environment"), "None"]] + | ||
[[_("*Clear environment*"), ""]] + | ||
ForemanSalt::SaltEnvironment.all.map{|e| [e.name, e.id]},{}, | ||
:label => _("Salt Environment"), :onchange => "toggle_multiple_ok_button(this)" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= render 'selected_hosts', :hosts => @hosts %> | ||
<%= form_for :proxy, :url => update_multiple_salt_master_hosts_path(:host_ids => params[:host_ids]) do |f| %> | ||
<%= multiple_proxy_select(f, 'Salt') %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
require 'test_plugin_helper' | ||
|
||
module ForemanSalt | ||
class HostsControllerExtensionsTest < ActionController::TestCase | ||
tests ::HostsController | ||
|
||
describe "setting salt master proxy on multiple hosts" do | ||
before do | ||
setup_user "edit" | ||
as_admin do | ||
@hosts = FactoryBot.create_list(:host, 2) | ||
@proxy = FactoryBot.create(:smart_proxy, :with_salt_feature) | ||
end | ||
end | ||
|
||
test 'user without edit permission should not be able to change salt master' do | ||
@request.env['HTTP_REFERER'] = hosts_path | ||
|
||
params = { :host_ids => @hosts.map(&:id), | ||
:proxy => { :proxy_id => '' } } | ||
|
||
post :update_multiple_salt_master, params: params, | ||
session: set_session_user.merge(:user => users(:one).id) | ||
assert_response :forbidden | ||
end | ||
|
||
test "should change the salt master proxy" do | ||
@request.env['HTTP_REFERER'] = hosts_path | ||
|
||
params = { :host_ids => @hosts.map(&:id), | ||
:proxy => { :proxy_id => @proxy.id } } | ||
|
||
post :update_multiple_salt_master, params: params, | ||
session: set_session_user.merge(:user => users(:admin).id) | ||
|
||
assert_empty flash[:error] | ||
|
||
@hosts.each do |host| | ||
as_admin do | ||
assert_equal @proxy, host.reload.salt_proxy | ||
end | ||
end | ||
end | ||
|
||
test "should clear the salt master proxy of multiple hosts" do | ||
@request.env['HTTP_REFERER'] = hosts_path | ||
|
||
params = { :host_ids => @hosts.map(&:id), | ||
:proxy => { :proxy_id => '' } } | ||
|
||
post :update_multiple_salt_master, params: params, | ||
session: set_session_user.merge(:user => users(:admin).id) | ||
|
||
assert_empty flash[:error] | ||
|
||
@hosts.each do |host| | ||
as_admin do | ||
assert_nil host.reload.salt_proxy | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe "setting salt environment on multiple hosts" do | ||
before do | ||
setup_user "edit" | ||
as_admin do | ||
@hosts = FactoryBot.create_list(:host, 2) | ||
@proxy = FactoryBot.create(:smart_proxy, :with_salt_feature) | ||
@salt_environment = FactoryBot.create :salt_environment | ||
end | ||
end | ||
|
||
test 'user without edit permission should not be able to change salt environment' do | ||
@request.env['HTTP_REFERER'] = hosts_path | ||
|
||
params = { :host_ids => @hosts.map(&:id), | ||
:salt_environment => { :id => @salt_environment.id } } | ||
|
||
post :update_multiple_salt_environment, params: params, | ||
session: set_session_user.merge(:user => users(:one).id) | ||
assert_response :forbidden | ||
end | ||
|
||
test "should change the salt environment" do | ||
@request.env['HTTP_REFERER'] = hosts_path | ||
|
||
params = { :host_ids => @hosts.map(&:id), | ||
:salt_environment => { :id => @salt_environment.id } } | ||
|
||
post :update_multiple_salt_environment, params: params, | ||
session: set_session_user.merge(:user => users(:admin).id) | ||
|
||
assert_empty flash[:error] | ||
|
||
@hosts.each do |host| | ||
as_admin do | ||
assert_equal @salt_environment, host.reload.salt_environment | ||
end | ||
end | ||
end | ||
|
||
test "should clear the salt environment of multiple hosts" do | ||
@request.env['HTTP_REFERER'] = hosts_path | ||
|
||
params = { :host_ids => @hosts.map(&:id), | ||
:salt_environment => { :id => '' } } | ||
|
||
post :update_multiple_salt_environment, params: params, | ||
session: set_session_user.merge(:user => users(:admin).id) | ||
|
||
assert_empty flash[:error] | ||
|
||
@hosts.each do |host| | ||
as_admin do | ||
assert_nil host.reload.salt_environment | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
require 'test_plugin_helper' | ||
require 'integration_test_helper' | ||
|
||
module ForemanSalt | ||
class HostJSTest < IntegrationTestWithJavascript | ||
def index_modal | ||
page.find('#confirmation-modal') | ||
end | ||
|
||
def multiple_actions_div | ||
page.find('#submit_multiple') | ||
end | ||
|
||
setup do | ||
as_admin do | ||
proxy = FactoryBot.create(:smart_proxy, :with_salt_feature) | ||
salt_environment = FactoryBot.create(:salt_environment) | ||
@host = FactoryBot.create(:host, :salt_proxy => proxy, :salt_environment => salt_environment) | ||
end | ||
end | ||
|
||
describe "hosts index salt multiple actions" do | ||
test 'change salt master action' do | ||
visit hosts_path | ||
page.find('#check_all').trigger('click') | ||
|
||
# Ensure and wait for all hosts to be checked, and that no unchecked hosts remain | ||
assert page.has_no_selector?('input.host_select_boxes:not(:checked)') | ||
|
||
# Dropdown visible? | ||
assert multiple_actions_div.find('.dropdown-toggle').visible? | ||
multiple_actions_div.find('.dropdown-toggle').click | ||
assert multiple_actions_div.find('ul').visible? | ||
|
||
# Hosts are added to cookie | ||
host_ids_on_cookie = JSON.parse(CGI.unescape(page.driver.cookies['_ForemanSelectedhosts'].value)) | ||
assert(host_ids_on_cookie.include?(@host.id)) | ||
|
||
within('#submit_multiple') do | ||
click_on('Change Salt Master') | ||
end | ||
|
||
assert index_modal.visible?, "Modal window was shown" | ||
page.find('#proxy_proxy_id').find("option[value='#{@host.salt_proxy.id}']").select_option | ||
|
||
# remove hosts cookie on submit | ||
index_modal.find('.btn-primary').click | ||
assert_current_path hosts_path | ||
assert_empty(page.driver.cookies['_ForemanSelectedhosts']) | ||
end | ||
|
||
test 'change salt environment action' do | ||
visit hosts_path | ||
page.find('#check_all').trigger('click') | ||
|
||
# Ensure and wait for all hosts to be checked, and that no unchecked hosts remain | ||
assert page.has_no_selector?('input.host_select_boxes:not(:checked)') | ||
|
||
# Dropdown visible? | ||
assert multiple_actions_div.find('.dropdown-toggle').visible? | ||
multiple_actions_div.find('.dropdown-toggle').click | ||
assert multiple_actions_div.find('ul').visible? | ||
|
||
# Hosts are added to cookie | ||
host_ids_on_cookie = JSON.parse(CGI.unescape(page.driver.cookies['_ForemanSelectedhosts'].value)) | ||
assert(host_ids_on_cookie.include?(@host.id)) | ||
|
||
within('#submit_multiple') do | ||
click_on('Change Salt Environment') | ||
end | ||
|
||
assert index_modal.visible?, "Modal window was shown" | ||
page.find('#salt_environment_id').find("option[value='#{@host.salt_environment.id}']").select_option | ||
|
||
# remove hosts cookie on submit | ||
index_modal.find('.btn-primary').click | ||
assert_current_path hosts_path | ||
assert_empty(page.driver.cookies['_ForemanSelectedhosts']) | ||
end | ||
end | ||
end | ||
end |