diff --git a/app/controllers/ops_controller.rb b/app/controllers/ops_controller.rb index eacaf18c42c..a0519050cd9 100644 --- a/app/controllers/ops_controller.rb +++ b/app/controllers/ops_controller.rb @@ -99,6 +99,18 @@ def button custom_buttons if params[:pressed] == 'custom_button' end + def tree_selected_model + @tree_selected_model = if x_node == 'root' + MiqRegion + else + model, id, _ = TreeBuilder.extract_node_model_and_id(x_node) + if model == 'Hash' + model = TreeBuilder.get_model_for_prefix(id) + end + model.constantize + end + end + def explorer @explorer = true @trees = [] @@ -116,6 +128,8 @@ def explorer @breadcrumbs = [] build_accordions_and_trees + tree_selected_model + @sb[:rails_log] = $rails_log.filename.to_s.include?("production.log") ? N_("Production") : N_("Development") if !params[:no_refresh] @@ -151,6 +165,7 @@ def tree_select session[:flash_msgs] = @flash_array = nil # clear out any messages from previous screen i.e import tab @sb[:active_node] ||= {} self.x_node = params[:id] + tree_selected_model set_active_tab(params[:id]) session[:changed] = false self.x_node = params[:id] # if x_active_tree == :vmdb_tree #params[:action] == "x_show" diff --git a/app/controllers/ops_controller/ops_rbac.rb b/app/controllers/ops_controller/ops_rbac.rb index b0751d8be9e..88de0ccbe88 100644 --- a/app/controllers/ops_controller/ops_rbac.rb +++ b/app/controllers/ops_controller/ops_rbac.rb @@ -891,19 +891,15 @@ def rbac_get_info case id when "u" @right_cell_text = _("Access Control EVM Users") - @tree_selected_model = User rbac_users_list when "g" @right_cell_text = _("Access Control EVM Groups") - @tree_selected_model = MiqGroup rbac_groups_list when "ur" @right_cell_text = _("Access Control Roles") - @tree_selected_model = MiqUserRole rbac_roles_list when "tn" @right_cell_text = _("Access Control Tenants") - @tree_selected_model = Tenant rbac_tenants_list end when "u" diff --git a/spec/controllers/ops_controller_spec.rb b/spec/controllers/ops_controller_spec.rb index bc1b0b29dfa..db85db2beb4 100644 --- a/spec/controllers/ops_controller_spec.rb +++ b/spec/controllers/ops_controller_spec.rb @@ -266,6 +266,13 @@ expect(response.status).to eq(200) expect(assigns(:sb)[:active_accord]).to eq(:rbac) end + + it 'calls #tree_selected_model' do + controller.instance_variable_set(:@sb, {}) + allow(controller).to receive(:render) + expect(controller).to receive(:tree_selected_model) + controller.send(:explorer) + end end context "#replace_explorer_trees" do @@ -380,4 +387,72 @@ end end end + + context "#tree_selected_model" do + it 'sets @tree_model_selected to User for user node' do + allow(controller).to receive(:x_node).and_return('u-42') + controller.tree_selected_model + expect(assigns(:tree_selected_model)).to eq(User) + end + + it 'sets @tree_model_selected to Tenant for tenant node' do + allow(controller).to receive(:x_node).and_return('tn-42') + controller.tree_selected_model + expect(assigns(:tree_selected_model)).to eq(Tenant) + end + + it 'sets @tree_model_selected to MiqGroup for group node' do + allow(controller).to receive(:x_node).and_return('g-42') + controller.tree_selected_model + expect(assigns(:tree_selected_model)).to eq(MiqGroup) + end + + it 'sets @tree_model_selected to MiqUserRole for group node' do + allow(controller).to receive(:x_node).and_return('ur-42') + controller.tree_selected_model + expect(assigns(:tree_selected_model)).to eq(MiqUserRole) + end + + it 'sets @tree_model_selected to User for all users node' do + allow(controller).to receive(:x_node).and_return('xx-u') + controller.tree_selected_model + expect(assigns(:tree_selected_model)).to eq(User) + end + + it 'sets @tree_model_selected to Tenant for all tenants node' do + allow(controller).to receive(:x_node).and_return('xx-tn') + controller.tree_selected_model + expect(assigns(:tree_selected_model)).to eq(Tenant) + end + + it 'sets @tree_model_selected to MiqGroup for all groups node' do + allow(controller).to receive(:x_node).and_return('xx-g') + controller.tree_selected_model + expect(assigns(:tree_selected_model)).to eq(MiqGroup) + end + + it 'sets @tree_model_selected to MiqUserRole for all roles node' do + allow(controller).to receive(:x_node).and_return('xx-ur') + controller.tree_selected_model + expect(assigns(:tree_selected_model)).to eq(MiqUserRole) + end + + it 'sets @tree_model_selected to MiqRegion for root node' do + allow(controller).to receive(:x_node).and_return('root') + controller.tree_selected_model + expect(assigns(:tree_selected_model)).to eq(MiqRegion) + end + end + + context '#tree_select' do + it 'calls #tree_select_model' do + controller.instance_variable_set(:@sb, {}) + controller.params[:id] = 'root' + allow(controller).to receive(:set_active_tab) + allow(controller).to receive(:get_node_info) + allow(controller).to receive(:replace_right_cell) + expect(controller).to receive(:tree_selected_model) + controller.send(:tree_select) + end + end end