Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set @tree_selected_model when explorer or tree_select is called in OPS #2851

Merged
merged 2 commits into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/controllers/ops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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]
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/ops_controller/ops_rbac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
75 changes: 75 additions & 0 deletions spec/controllers/ops_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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