Skip to content

Commit

Permalink
Added "all_vm_rules" feature to OOTB roles
Browse files Browse the repository at this point in the history
- Fixed product features count in spec test
- Addressed some of the rubocop comments

https://bugzilla.redhat.com/show_bug.cgi?id=1247375
  • Loading branch information
h-kataria committed Sep 22, 2015
1 parent e0f5571 commit aa43f69
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
24 changes: 12 additions & 12 deletions app/controllers/ops_controller/rbac_tree.rb
Expand Up @@ -3,9 +3,9 @@ class RbacTree
include CompressedIds

def self.build(role, role_features)
self.new(role, role_features).build
new(role, role_features).build
end

def initialize(role, role_features)
@role = role
@role_features = role_features
Expand All @@ -23,7 +23,7 @@ def build
:expand => true,
:select => @role_features.include?(root_feature)
}

top_nodes = []
@all_vm_node = { # FIXME: handle the below special name!
:key => "#{@role.id ? to_cid(@role.id) : "new"}___tab_all_vm_rules",
Expand All @@ -43,19 +43,19 @@ def build
:title => feature_title,
:tooltip => feature_title + " Main Tab"
}

subitems.each do |f| # Go thru the features of this tab
f_tab = f.ends_with?("_accords") ? f.split("_accords").first : f # Remove _accords suffix if present, to get tab feature name
next unless MiqProductFeature.feature_exists?(f_tab)
feature = rbac_features_tree_add_node(f_tab, t_node[:key], root_node[:select])
t_kids.push(feature) unless feature.nil?
end

if root_node[:select] # Root node is checked
t_node[:select] = true
elsif !t_kids.empty? # If kids are present
full_chk = (t_kids.collect{|k| k if k[:select]}.compact).length
part_chk = (t_kids.collect{|k| k unless k[:select]}.compact).length
full_chk = (t_kids.collect { |k| k if k[:select] }.compact).length
part_chk = (t_kids.collect { |k| k unless k[:select] }.compact).length
if full_chk == t_kids.length
t_node[:select] = true # All kids are checked
elsif full_chk > 0 || part_chk > 0
Expand All @@ -66,8 +66,8 @@ def build
t_node[:children] = t_kids unless t_kids.empty?
# only show storage node if product setting is set to show the nodes
case feature_title.downcase
when "storage"; top_nodes.push(t_node) if VMDB::Config.new("vmdb").config[:product][:storage]
else top_nodes.push(t_node)
when "storage"; top_nodes.push(t_node) if VMDB::Config.new("vmdb").config[:product][:storage]
else top_nodes.push(t_node)
end
end
top_nodes << @all_vm_node
Expand All @@ -79,7 +79,7 @@ def rbac_features_tree_add_node(feature, pid, parent_checked = false)
details = MiqProductFeature.feature_details(feature)

unless details[:hidden]
f_kids = [] # Array to hold node children
f_kids = [] # Array to hold node children
f_node = {
:key => "#{@role.id ? to_cid(@role.id) : "new"}__#{feature}",
:icon => "feature_#{details[:feature_type]}.png",
Expand All @@ -102,7 +102,7 @@ def rbac_features_tree_add_node(feature, pid, parent_checked = false)
f_kids.push(feat)
end
end
f_node[:children] = f_kids unless f_kids.empty? # Add in the node's children, if any
f_node[:children] = f_kids unless f_kids.empty? # Add in the node's children, if any

if parent_checked || # Parent is checked
@role_features.include?(feature) # This feature is checked
Expand All @@ -113,7 +113,7 @@ def rbac_features_tree_add_node(feature, pid, parent_checked = false)
if full_chk == f_kids.length
f_node[:select] = true # All kids are checked
elsif full_chk > 0 || part_chk > 0
f_node[:select] = false # Some kids are checked
f_node[:select] = false # Some kids are checked
end
end
f_node
Expand Down
11 changes: 11 additions & 0 deletions db/fixtures/miq_user_roles.yml
Expand Up @@ -9,6 +9,7 @@
:read_only: true
:miq_product_feature_identifiers:
- about
- all_vm_rules
- availability_zone
- flavor
- bottlenecks
Expand Down Expand Up @@ -66,6 +67,7 @@
:read_only: true
:miq_product_feature_identifiers:
- about
- all_vm_rules
- chargeback
- chargeback_reports
- cim_base_storage_extent_show
Expand Down Expand Up @@ -170,6 +172,7 @@
:read_only: true
:miq_product_feature_identifiers:
- about
- all_vm_rules
- bottlenecks
- chargeback
- chargeback_reports
Expand Down Expand Up @@ -275,6 +278,7 @@
:read_only: true
:miq_product_feature_identifiers:
- about
- all_vm_rules
- dashboard
- miq_request_admin
- miq_request_view
Expand Down Expand Up @@ -324,6 +328,7 @@
:read_only: true
:miq_product_feature_identifiers:
- about
- all_vm_rules
- chargeback
- chargeback_reports
- cim_base_storage_extent_show
Expand Down Expand Up @@ -466,6 +471,7 @@
:read_only: true
:miq_product_feature_identifiers:
- about
- all_vm_rules
- chargeback
- chargeback_reports
- cim_base_storage_extent_show
Expand Down Expand Up @@ -565,6 +571,7 @@
:read_only: true
:miq_product_feature_identifiers:
- about
- all_vm_rules
- chargeback
- chargeback_reports
- cim_base_storage_extent_show
Expand Down Expand Up @@ -658,6 +665,7 @@
:read_only: true
:miq_product_feature_identifiers:
- about
- all_vm_rules
- chargeback
- chargeback_reports
- cim_base_storage_extent_show
Expand Down Expand Up @@ -751,6 +759,7 @@
:vms: :user
:miq_product_feature_identifiers:
- about
- all_vm_rules
- miq_request_admin
- miq_request_view
- my_settings_default_views
Expand Down Expand Up @@ -784,6 +793,7 @@
:vms: :user_or_group
:miq_product_feature_identifiers:
- about
- all_vm_rules
- miq_template_clone
- miq_template_drift
- miq_template_edit
Expand Down Expand Up @@ -836,6 +846,7 @@
:read_only: true
:miq_product_feature_identifiers:
- about
- all_vm_rules
- miq_request_admin
- miq_request_view
- miq_template_analyze
Expand Down
6 changes: 3 additions & 3 deletions spec/helpers/application_helper/toolbar_builder_spec.rb
Expand Up @@ -1822,7 +1822,7 @@ def setup_x_tree_history
it "vm_scan button should be hidden when user does not have access to vm_rules feature" do
EvmSpecHelper.seed_specific_product_features("vm_infra_explorer")
feature = MiqProductFeature.find_all_by_identifier("vm_infra_explorer")
test_user_role = FactoryGirl.create(:miq_user_role,
test_user_role = FactoryGirl.create(:miq_user_role,
:name => "test_user_role",
:miq_product_features => feature)
test_user_group = FactoryGirl.create(:miq_group, :miq_user_role => test_user_role)
Expand All @@ -1832,8 +1832,8 @@ def setup_x_tree_history

it "vm_scan button should be displayed when user does has access to vm_scan feature" do
EvmSpecHelper.seed_specific_product_features("vm_infra_explorer", "vm_scan")
feature = MiqProductFeature.find_all_by_identifier(["vm_infra_explorer", "vm_scan"])
test_user_role = FactoryGirl.create(:miq_user_role,
feature = MiqProductFeature.find_all_by_identifier(%w(vm_infra_explorer vm_scan))
test_user_role = FactoryGirl.create(:miq_user_role,
:name => "test_user_role",
:miq_product_features => feature)
test_user_group = FactoryGirl.create(:miq_group, :miq_user_role => test_user_role)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/miq_product_feature_spec.rb
Expand Up @@ -2,7 +2,7 @@

describe MiqProductFeature do
before do
@expected_feature_count = 860
@expected_feature_count = 858
end

context ".seed" do
Expand Down

0 comments on commit aa43f69

Please sign in to comment.