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

[EUWE] ops_rbac - group detail - don't render trees that are not visible #13399

Merged
merged 12 commits into from
Jan 11, 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/assets/javascripts/miq_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,21 @@ function add_expanding_icon(element) {
element.find('.pull-right').append("<a onclick='toggle_expansion(this)'> <i class='fa fa-angle-right'></i>");
}

function rbacGroupLoadTab(id) {
var lazy = $('#' + id).hasClass('lazy');
if (! lazy) {
// already loaded
return;
}

$('#' + id).removeClass('lazy');

miqJqueryRequest('/ops/rbac_group_load_tab?tab_id=' + id, {
beforeSend: true,
complete: true,
});
}

function chartData(type, data, data2) {
if (type === undefined) {
return;
Expand Down
44 changes: 42 additions & 2 deletions app/controllers/ops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,35 @@ def change_tab(new_tab_id = nil)
end
end

def rbac_group_load_tab
tab_id = params[:tab_id]
_, group_id = TreeBuilder.extract_node_model_and_id(x_node)
@sb[:active_rbac_group_tab] = tab_id
@edit = session[:edit]

rbac_group_get_details(group_id)

presenter = ExplorerPresenter.new

# needed to make tooolbar Configuration > Edit still work after lazy-loading a tab
presenter[:record_id] = group_id

r = proc { |opts| render_to_string(opts) }

rendered = case tab_id
when 'rbac_customer_tags'
r[:partial => 'ops/rbac_group/customer_tags']
when 'rbac_hosts_clusters'
r[:partial => 'ops/rbac_group/hosts_clusters']
when 'rbac_vms_templates'
r[:partial => 'ops/rbac_group/vms_templates']
end

presenter.update(tab_id, rendered)

render :json => presenter.for_render
end

private ############################

def features
Expand Down Expand Up @@ -239,7 +268,16 @@ def set_active_tab_and_node
end

if x_active_tree == :rbac_tree
x_node_set("root", :rbac_tree) unless x_node(:rbac_tree)
node = x_node(:rbac_tree)
if node
kind = node.split('-').first

# default to the first tab in group detail
@sb[:active_rbac_group_tab] = "rbac_customer_tags" if kind == 'g'
else
x_node_set("root", :rbac_tree)
end

@sb[:active_tab] ||= "rbac_details"
end

Expand Down Expand Up @@ -316,6 +354,9 @@ def set_active_tab(nodetype)
end
when :rbac_tree
@sb[:active_tab] = "rbac_details"

# default to the first tab in group detail
@sb[:active_rbac_group_tab] ||= "rbac_customer_tags" if node[0] == 'g'
when :diagnostics_tree
case node[0]
when "root"
Expand All @@ -326,7 +367,6 @@ def set_active_tab(nodetype)
@sb[:diag_selected_id] = nil
when "svr"
@sb[:active_tab] = "diagnostics_summary"
svr = MiqServer.find(from_cid(node[1]))
end
when :vmdb_tree
nodes = x_node.split('-')
Expand Down
38 changes: 23 additions & 15 deletions app/controllers/ops_controller/ops_rbac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ def rbac_get_info
rbac_user_get_details(id)
when "g"
@right_cell_text = _("%{model} \"%{name}\"") % {:model => ui_lookup(:model => "MiqGroup"), :name => MiqGroup.find_by_id(from_cid(id)).description}
@edit = nil
rbac_group_get_details(id)
when "ur"
@right_cell_text = _("%{model} \"%{name}\"") % {:model => ui_lookup(:model => "MiqUserRole"), :name => MiqUserRole.find_by_id(from_cid(id)).name}
Expand Down Expand Up @@ -928,7 +929,6 @@ def rbac_tenant_get_details(id)
end

def rbac_group_get_details(id)
@edit = nil
@record = @group = MiqGroup.find_by_id(from_cid(id))
get_tagdata(@group)
# Build the belongsto filters hash
Expand All @@ -943,13 +943,26 @@ def rbac_group_get_details(id)
[@group.get_managed_filters].flatten.each do |f|
@filters[f.split("/")[-2] + "-" + f.split("/")[-1]] = f
end
@tags_tree = TreeBuilderTags.new(:tags,
:tags_tree,
@sb,
true,
:edit => @edit, :filters => @filters, :group => @group)
@hac_tree = build_belongsto_tree(@belongsto.keys, false, false) # Build the Hosts & Clusters tree for this user
@vat_tree = build_belongsto_tree(@belongsto.keys, true, false) # Build the VMs & Templates tree for this user

rbac_group_right_tree(@belongsto.keys)
end

# this causes the correct tree to get instantiated, depending on the active tab
def rbac_group_right_tree(selected)
case @sb[:active_rbac_group_tab]
when 'rbac_customer_tags'
@tags_tree = TreeBuilderTags.new(:tags,
:tags_tree,
@sb,
true,
:edit => @edit,
:filters => @filters,
:group => @group)
when 'rbac_hosts_clusters'
@hac_tree = build_belongsto_tree(selected, false, false) # Build the Hosts & Clusters tree for this user
when 'rbac_vms_templates'
@vat_tree = build_belongsto_tree(selected, true, false) # Build the VMs & Templates tree for this user
end
end

def rbac_role_get_details(id)
Expand Down Expand Up @@ -1114,13 +1127,8 @@ def rbac_group_set_form_vars
@edit[:new][:group_tenant] = @group.tenant_id

@edit[:current] = copy_hash(@edit[:new])
@tags_tree = TreeBuilderTags.new(:tags,
:tags_tree,
@sb,
true,
:edit => @edit, :filters => @filters, :group => @group)
@hac_tree = build_belongsto_tree(@edit[:new][:belongsto].keys, false, false) # Build the Hosts & Clusters tree for this user
@vat_tree = build_belongsto_tree(@edit[:new][:belongsto].keys, true, false) # Build the VMs & Templates tree for this user

rbac_group_right_tree(@edit[:new][:belongsto].keys)
end

# Set group record variables to new values
Expand Down
22 changes: 16 additions & 6 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1347,19 +1347,29 @@ def start_page_allowed?(start_page)
end

def miq_tab_header(id, active = nil, options = {}, &_block)
content_tag(:li,
:class => "#{options[:class]} #{active == id ? 'active' : ''}",
:id => "#{id}_tab",
'ng-click' => "changeAuthTab('#{id}');") do
tag_options = {:class => "#{options[:class]} #{active == id ? 'active' : ''}",
:id => "#{id}_tab"}

tag_options['ng-click'] = options['ng-click'] if options.key?('ng-click')
tag_options[:onclick] = options[:onclick] if options.key?(:onclick)

content_tag(:li, tag_options) do
content_tag(:a, :href => "##{id}", 'data-toggle' => 'tab') do
yield
end
end
end

def miq_tab_content(id, active = nil, options = {}, &_block)
content_tag(:div, :id => id, :class => "tab-pane #{options[:class]} #{active == id ? 'active' : ''}") do
yield
lazy = options[:lazy] && active != id

classname = %w(tab-pane)
classname << options[:class] if options[:class]
classname << 'active' if active == id
classname << 'lazy' if lazy

content_tag(:div, :id => id, :class => classname.join(' ')) do
yield unless lazy
end
end

Expand Down
14 changes: 7 additions & 7 deletions app/views/layouts/_multi_auth_credentials.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
= legendtext
#auth_tabs
%ul.nav.nav-tabs
= miq_tab_header('default') do
= miq_tab_header('default', nil, {'ng-click' => "changeAuthTab('default')"}) do
= _("Default")
- if %w(ems_cloud ems_infra).include?(params[:controller])
- if @edit[:new][:emstype] == "rhevm"
= miq_tab_header('metrics') do
= miq_tab_header('metrics', nil, {'ng-click' => "changeAuthTab('metrics')"}) do
= _("C & U Database")
- if %w(openstack openstack_infra).include?(@edit[:new][:emstype])
= miq_tab_header('amqp') do
= miq_tab_header('amqp', nil, {'ng-click' => "changeAuthTab('amqp')"}) do
= _("AMQP")
- if %w(openstack_infra).include?(@edit[:new][:emstype])
= miq_tab_header('ssh_keypair') do
= miq_tab_header('ssh_keypair', nil, {'ng-click' => "changeAuthTab('ssh_keypair')"}) do
= _("RSA key pair")
- elsif !%w(ems_middleware).include?(params[:controller])
= miq_tab_header('remote') do
= miq_tab_header('remote', nil, {'ng-click' => "changeAuthTab('remote')"}) do
= _("Remote Login")
= miq_tab_header('web') do
= miq_tab_header('web', nil, {'ng-click' => "changeAuthTab('web')"}) do
= _("Web Services")
= miq_tab_header('ipmi') do
= miq_tab_header('ipmi', nil, {'ng-click' => "changeAuthTab('ipmi')"}) do
= _("IPMI")

.tab-content
Expand Down
76 changes: 26 additions & 50 deletions app/views/ops/_rbac_group_details.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -165,60 +165,36 @@
%hr
%h3
= @edit ? _("Assign Filters") : _("Assigned Filters (read only)")

#rbac_group_tabs
%ul.nav.nav-tabs
= miq_tab_header('customer_tags') do
= escape_javascript(current_tenant.name)
= _("Tags")
= miq_tab_header('hosts_clusters') do
= miq_tab_header('rbac_customer_tags', @sb[:active_rbac_group_tab], {:onclick => "rbacGroupLoadTab('rbac_customer_tags')"}) do
= _("%{current_tenant} Tags") % {:current_tenant => current_tenant.name}
= miq_tab_header('rbac_hosts_clusters', @sb[:active_rbac_group_tab], {:onclick => "rbacGroupLoadTab('rbac_hosts_clusters')"}) do
= _("%{title_for_hosts} & %{title_for_clusters}") % {:title_for_hosts => title_for_hosts, :title_for_clusters => title_for_clusters}
= miq_tab_header('vms_templates') do
= miq_tab_header('rbac_vms_templates', @sb[:active_rbac_group_tab], {:onclick => "rbacGroupLoadTab('rbac_vms_templates')"}) do
= _("VMs & Templates")

.tab-content
= miq_tab_content('customer_tags') do
%br/
= _("This user is limited to items with the selected tags.")
%br/
%br/
= render(:partial => 'shared/tree', :locals => {:tree => @tags_tree, :name => @tags_tree.name})
= miq_tab_content('hosts_clusters') do
%br/
= _("This user is limited to the selected items and their children.")
%br/
%br/
#hac_treebox.treeview-pf-hover.treeview-pf-select{:style => "color:#000"}
= render(:partial => "layouts/tree",
:locals => {:tree_id => "hac_treebox",
:tree_name => "hac_tree",
:bs_tree => @hac_tree,
:oncheck => @edit.nil? ? nil : "miqOnCheckUserFilters",
:check_url => "ops/rbac_group_field_changed/#{@group.id || "new"}___",
:highlight_changes => true,
:checkboxes => true})
= miq_tab_content('vms_templates') do
%br/
= _("This user is limited to the selected folders and their children.")
%br/
%br/
#vat_treebox.treeview-pf-hover.treeview-pf-select{:style => "color:#000"}
= render(:partial => "layouts/tree",
:locals => {:tree_id => "vat_treebox",
:tree_name => "vat_tree",
:bs_tree => @vat_tree,
:oncheck => @edit.nil? ? nil : "miqOnCheckUserFilters",
:check_url => "/ops/rbac_group_field_changed/#{@group.id || "new"}___",
:highlight_changes => true,
:checkboxes => true})
= miq_tab_content('rbac_customer_tags', @sb[:active_rbac_group_tab], {:lazy => true}) do
= render :partial => 'ops/rbac_group/customer_tags'
= miq_tab_content('rbac_hosts_clusters', @sb[:active_rbac_group_tab], {:lazy => true}) do
= render :partial => 'ops/rbac_group/hosts_clusters'
= miq_tab_content('rbac_vms_templates', @sb[:active_rbac_group_tab], {:lazy => true}) do
= render :partial => 'ops/rbac_group/vms_templates'

:javascript
miq_tabs_init('#rbac_group_tabs');
%script{:type => "text/javascript"}
- if get_vmdb_config[:authentication][:mode] == "httpd"
$('#user_id_ext_auth_form_group').show();
$('#user_id_form_group').hide();
$('#user_name_form_group').hide();
$('#user_password_form_group').hide();
- else
$('#user_id_ext_auth_form_group').hide();
$('#user_id_form_group').show();
$('#user_name_form_group').show();
$('#user_password_form_group').show();

- if @edit
%script{:type => "text/javascript"}
- if get_vmdb_config[:authentication][:mode] == "httpd"
$('#user_id_ext_auth_form_group').show();
$('#user_id_form_group').hide();
$('#user_name_form_group').hide();
$('#user_password_form_group').hide();
- else
$('#user_id_ext_auth_form_group').hide();
$('#user_id_form_group').show();
$('#user_name_form_group').show();
$('#user_password_form_group').show();
5 changes: 5 additions & 0 deletions app/views/ops/rbac_group/_customer_tags.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%br
= _("This user is limited to items with the selected tags.")
%br
%br
= render(:partial => 'shared/tree', :locals => {:tree => @tags_tree, :name => @tags_tree.name})
13 changes: 13 additions & 0 deletions app/views/ops/rbac_group/_hosts_clusters.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%br
= _("This user is limited to the selected items and their children.")
%br
%br
#hac_treebox.treeview-pf-hover.treeview-pf-select{:style => "color:#000"}
= render(:partial => "layouts/tree",
:locals => {:tree_id => "hac_treebox",
:tree_name => "hac_tree",
:bs_tree => @hac_tree,
:oncheck => @edit.nil? ? nil : "miqOnCheckUserFilters",
:check_url => "/ops/rbac_group_field_changed/#{@group.id || "new"}___",
:highlight_changes => true,
:checkboxes => true})
13 changes: 13 additions & 0 deletions app/views/ops/rbac_group/_vms_templates.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%br
= _("This user is limited to the selected folders and their children.")
%br
%br
#vat_treebox.treeview-pf-hover.treeview-pf-select{:style => "color:#000"}
= render(:partial => "layouts/tree",
:locals => {:tree_id => "vat_treebox",
:tree_name => "vat_tree",
:bs_tree => @vat_tree,
:oncheck => @edit.nil? ? nil : "miqOnCheckUserFilters",
:check_url => "/ops/rbac_group_field_changed/#{@group.id || "new"}___",
:highlight_changes => true,
:checkboxes => true})
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,7 @@
product_updates_list
rbac_group_edit
rbac_group_field_changed
rbac_group_load_tab
rbac_group_seq_edit
rbac_group_user_lookup
rbac_groups_list
Expand Down
6 changes: 5 additions & 1 deletion spec/views/ops/_rbac_group_details.html.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
allow(view).to receive(:current_tenant).and_return(Tenant.seed)
allow(view).to receive(:session).and_return(:assigned_filters => [])
FactoryGirl.create(:classification, :name => 'folder_selected', :show => true)

sb = {}
view.instance_variable_set(:@sb, sb)

@tags_tree = TreeBuilderTags.new(:tag,
:tag_tree,
{},
sb,
true,
:edit => {}, :filters => {}, :group => @group)
end
Expand Down