Skip to content

Commit

Permalink
Merge pull request #5192 from hstastna/Cannot_select_other_dashboard
Browse files Browse the repository at this point in the history
Fix displaying selected dashboard while clicking on its tab

(cherry picked from commit 76f27d9)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1748953
  • Loading branch information
h-kataria authored and simaishi committed Sep 5, 2019
1 parent f2ff403 commit d821b15
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 38 deletions.
4 changes: 2 additions & 2 deletions app/controllers/dashboard_controller.rb
Expand Up @@ -206,9 +206,9 @@ def show
records = current_group.ordered_widget_sets

@tabs = []
active_tab_id = (params[:tab] || @sb[:active_db_id]).try(:to_s)
active_tab_id = (params['uib-tab'] || @sb[:active_db_id]).try(:to_s)
active_tab = active_tab_id && records.detect { |r| r.id.to_s == active_tab_id } || records.first
# load first one on intial load, or load tab from params[:tab] changed,
# load first one on intial load, or load tab from params['uib-tab'] changed,
# or when coming back from another screen load active tab from sandbox
if active_tab
@active_tab = active_tab.id.to_s
Expand Down
97 changes: 61 additions & 36 deletions spec/controllers/dashboard_controller_spec.rb
@@ -1,12 +1,8 @@
describe DashboardController do
context "POST authenticate" do
before do
EvmSpecHelper.create_guid_miq_server_zone
end
before { EvmSpecHelper.create_guid_miq_server_zone }

let(:user_with_role) do
FactoryGirl.create(:user, :role => "random")
end
let(:user_with_role) { FactoryBot.create(:user, :role => "random") }

it "has secure headers" do
get :index
Expand Down Expand Up @@ -93,9 +89,7 @@
end

context "SAML and OIDC support" do
before do
EvmSpecHelper.create_guid_miq_server_zone
end
before { EvmSpecHelper.create_guid_miq_server_zone }

%i(saml oidc).each do |protocol|
it "#{protocol.upcase} login should redirect to the protected page" do
Expand Down Expand Up @@ -141,10 +135,8 @@

# would like to test these controller by calling authenticate
# need to ensure all cases are handled before deleting these
context "#validate_user" do
before do
EvmSpecHelper.create_guid_miq_server_zone
end
describe "#validate_user" do
before { EvmSpecHelper.create_guid_miq_server_zone }

it "returns flash message when user's group is missing" do
user = FactoryGirl.create(:user)
Expand Down Expand Up @@ -193,8 +185,8 @@
context "Create Dashboard" do
it "dashboard show" do
# create dashboard for a group
ws = FactoryGirl.create(:miq_widget_set, :name => "default",
:set_data => {:last_group_db_updated => Time.now.utc,
ws = FactoryBot.create(:miq_widget_set, :name => "default",
:set_data => {:last_group_db_updated => Time.now.utc,
:col1 => [1], :col2 => [], :col3 => []})

ur = FactoryGirl.create(:miq_user_role)
Expand All @@ -205,23 +197,23 @@
controller.instance_variable_set(:@tabs, [])
login_as user
# create a user's dashboard using group dashboard name.
FactoryGirl.create(:miq_widget_set,
:name => "#{user.userid}|#{group.id}|#{ws.name}",
:set_data => {:last_group_db_updated => Time.now.utc, :col1 => [1], :col2 => [], :col3 => []})
FactoryBot.create(:miq_widget_set,
:name => "#{user.userid}|#{group.id}|#{ws.name}",
:set_data => {:last_group_db_updated => Time.now.utc, :col1 => [1], :col2 => [], :col3 => []})
controller.show
expect(controller.send(:flash_errors?)).not_to be_truthy
end

it "widget_add" do
ur = FactoryGirl.create(:miq_user_role)
group = FactoryGirl.create(:miq_group, :miq_user_role => ur)
user = FactoryGirl.create(:user, :miq_groups => [group])
wi = FactoryGirl.create(:miq_widget)
ws = FactoryGirl.create(:miq_widget_set, :name => "default",
:set_data => {:last_group_db_updated => Time.now.utc,
ur = FactoryBot.create(:miq_user_role)
group = FactoryBot.create(:miq_group, :miq_user_role => ur)
user = FactoryBot.create(:user, :miq_groups => [group])
wi = FactoryBot.create(:miq_widget)
ws = FactoryBot.create(:miq_widget_set, :name => "default",
:set_data => {:last_group_db_updated => Time.now.utc,
:col1 => [], :col2 => [], :col3 => []},
:userid => user.userid,
:group_id => group.id)
:userid => user.userid,
:group_id => group.id)
session[:sandboxes] = {"dashboard" => {:active_db => ws.name,
:dashboards => {ws.name => {:col1 => [], :col2 => [], :col3 => []}}}}
login_as user
Expand Down Expand Up @@ -274,7 +266,7 @@
end
end

context "#start_url_for_user" do
describe "#start_url_for_user" do
before do
MiqShortcut.seed
allow(controller).to receive(:check_privileges).and_return(true)
Expand Down Expand Up @@ -343,11 +335,12 @@
end
end

context "#maintab" do
describe "#maintab" do
before do
allow_any_instance_of(described_class).to receive(:set_user_time_zone)
allow(controller).to receive(:check_privileges).and_return(true)
end

it "redirects a restful link correctly" do
ems_cloud_amz = FactoryGirl.create(:ems_amazon)
breadcrumbs = [{:name => "Name", :url => "/controller/action"}]
Expand All @@ -359,7 +352,7 @@
end
end

context "#session_reset" do
describe "#session_reset" do
it "verify certain keys are restored after session is cleared" do
user_TZO = '5'
browser_info = {:name => 'firefox', :version => '32'}
Expand All @@ -376,15 +369,13 @@
end
end

describe "building tabs" do
context "building tabs" do
let(:group) do
role = FactoryGirl.create(:miq_user_role)
FactoryGirl.create(:miq_group, :miq_user_role => role)
end

let(:user) do
FactoryGirl.create(:user, :miq_groups => [group])
end
let(:user) { FactoryBot.create(:user, :miq_groups => [group]) }

let(:wset) do
FactoryGirl.create(
Expand Down Expand Up @@ -457,9 +448,9 @@
end

describe 'private #load_dialog_definition' do
let (:klass) { 'Foobar' }
let (:name) { 'existing_dialog' }
let (:dialog_path) { Pathname.new("/dialogs/#{name}.json") }
let(:klass) { 'Foobar' }
let(:name) { 'existing_dialog' }
let(:dialog_path) { Pathname.new("/dialogs/#{name}.json") }

before do
plug = double('Plugin')
Expand Down Expand Up @@ -505,6 +496,40 @@
end
end

describe '#show' do
context 'changing tabs' do
let(:group) { FactoryBot.create(:miq_group) }
let(:user) { FactoryBot.create(:user_admin, :current_group => group, :miq_groups => [group]) }
let(:ws1) do
FactoryBot.create(:miq_widget_set,
:name => 'A',
:owner_id => group.id,
:set_data => {:col1 => [], :col2 => [], :col3 => []})
end
let(:ws2) do
FactoryBot.create(:miq_widget_set,
:name => 'B',
:owner_id => group.id,
:set_data => {:col1 => [], :col2 => [], :col3 => []})
end

before do
login_as user
controller.instance_variable_set(:@_params, 'uib-tab' => ws2.id.to_s)
controller.instance_variable_set(:@sb, {})
controller.instance_variable_set(:@current_user, user)
group.update_attributes(:settings => { :dashboard_order => [ws1.id.to_s, ws2.id.to_s] })
end

it 'sets id of selected tab properly' do
controller.send(:show)
expect(controller.instance_variable_get(:@sb)[:active_db]).to eq(ws2.name)
expect(controller.instance_variable_get(:@sb)[:active_db_id]).to eq(ws2.id)
expect(controller.instance_variable_get(:@active_tab)).to eq(ws2.id.to_s)
end
end
end

def skip_data_checks(url = '/')
allow_any_instance_of(UserValidationService).to receive(:server_ready?).and_return(true)
allow(controller).to receive(:start_url_for_user).and_return(url)
Expand Down

0 comments on commit d821b15

Please sign in to comment.