Skip to content

Commit

Permalink
Fixed code to show Custom reports in Available Reports in menu editor
Browse files Browse the repository at this point in the history
Also fixed saving of reports menus for a selected group that broke with changes in ManageIQ/manageiq#16142

https://bugzilla.redhat.com/show_bug.cgi?id=1517073
  • Loading branch information
h-kataria committed Dec 1, 2017
1 parent 4aeb53c commit 08e431b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ def get_reports_menu(group = current_group, tree_type = "reports", mode = "menu"
data.each do |r|
r_group = r.rpt_group == "Custom" ? "#{@sb[:grp_title]} - Custom" : r.rpt_group # Get the report group
title = r_group.reverse.split('-', 2).collect(&:reverse).collect(&:strip).reverse
next if mode == "menu" && title[1] == "Custom"
if @temp_title != title[0]
@temp_title = title[0]
reports = []
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/report_controller/menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ def menu_update
@menu_lastaction = "save"
role = session[:role_choice] unless session[:role_choice].nil?
rec = MiqGroup.find_by_description(role)
rec.settings ||= {}
rec[:settings] ||= {}
if @sb[:menu_default]
# delete report_menus from settings if menu set to default
rec.settings.delete(:report_menus)
rec[:settings].delete(:report_menus)
else
rec.settings[:report_menus] ||= {}
rec.settings[:report_menus] = copy_array(@edit[:new])
rec[:settings]["report_menus"] ||= {}
rec[:settings]["report_menus"] = copy_array(@edit[:new])
end

if rec.save
Expand Down Expand Up @@ -262,7 +262,7 @@ def edit_reports
current_group_id = current_user.current_group.try(:id).to_i
id = session[:node_selected].split('__')
@selected = id[1].split(':')
all = MiqReport.for_user(current_user).sort_by { |r| [r.rpt_type, r.filename.to_s, r.name] }
all = MiqReport.all.sort_by { |r| [r.rpt_type, r.filename.to_s, r.name] }
@all_reports = []
all.each do |r|
next if r.template_type != "report" && !r.template_type.blank?
Expand Down Expand Up @@ -297,7 +297,7 @@ def edit_reports
end
end

# Calculating reports that are asigned to any of the folders
# Calculating reports that are assigned to any of the folders
@edit[:new].each do |arr|
if arr.class == Array
arr.each do |a|
Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/report_controller/menu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,35 @@
{:id => "|-|i_B", :text => "B"}])
end
end

describe "#edit_reports" do
before(:each) do
MiqUserRole.seed

role = MiqUserRole.find_by_name("EvmRole-administrator")
current_group = FactoryGirl.create(:miq_group, :miq_user_role => role, :description => "Current Group")
@current_user = FactoryGirl.create(:user, :userid => "Current User", :miq_groups => [current_group],
:email => "[email protected]")

login_as @current_user
FactoryGirl.create(:miq_report, :name => "VM 1", :rpt_group => "Configuration Management - Folder Foo", :rpt_type => "Default")
FactoryGirl.create(:miq_report, :name => "Provisioning 1", :rpt_group => "Provisioning - Folder Bar", :rpt_type => "Default")
FactoryGirl.create(:miq_report, :name => "Provisioning 2", :rpt_group => "Provisioning - Folder Bar", :rpt_type => "Default")
FactoryGirl.create(:miq_report, :name => "custom report 1", :rpt_group => "Custom", :rpt_type => "Custom")
FactoryGirl.create(:miq_report, :name => "custom report 2", :rpt_group => "Custom", :rpt_type => "Custom")

controller.instance_variable_set(:@edit,
:new => [
["Configuration Management", [["Folder Foo", ["VM 1"]]]],
["Provisioning", [["Folder Bar", ["Provisioning 1"]]]]
])
session[:node_selected] = 'foo__bar'
allow(controller).to receive(:replace_right_cell)
end

it "returns custom reports in available_reports array along with other default available reports" do
controller.send(:edit_reports)
expect(assigns(:available_reports)).to eq(["custom report 1", "custom report 2", "Provisioning 2"])
end
end
end

0 comments on commit 08e431b

Please sign in to comment.