From 08e431bd43ba4560bb5768e8c0b58faf003ea1aa Mon Sep 17 00:00:00 2001 From: Harpreet Kataria Date: Fri, 1 Dec 2017 12:04:17 -0500 Subject: [PATCH] Fixed code to show Custom reports in Available Reports in menu editor Also fixed saving of reports menus for a selected group that broke with changes in https://github.com/ManageIQ/manageiq/pull/16142 https://bugzilla.redhat.com/show_bug.cgi?id=1517073 --- app/controllers/application_controller.rb | 1 + app/controllers/report_controller/menus.rb | 12 +++---- .../report_controller/menu_spec.rb | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3959c647ed98..158f2cd5cdc0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 = [] diff --git a/app/controllers/report_controller/menus.rb b/app/controllers/report_controller/menus.rb index c07f4af1d474..f4cae25dd779 100644 --- a/app/controllers/report_controller/menus.rb +++ b/app/controllers/report_controller/menus.rb @@ -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 @@ -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? @@ -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| diff --git a/spec/controllers/report_controller/menu_spec.rb b/spec/controllers/report_controller/menu_spec.rb index 1fbc28f95f40..f21b45a25416 100644 --- a/spec/controllers/report_controller/menu_spec.rb +++ b/spec/controllers/report_controller/menu_spec.rb @@ -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 => "current_user@test.com") + + 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