forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree_builder_ops_rbac_features.rb
140 lines (113 loc) · 3.72 KB
/
tree_builder_ops_rbac_features.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
class TreeBuilderOpsRbacFeatures < TreeBuilder
has_kids_for Menu::Section, [:x_get_tree_section_kids]
has_kids_for Menu::Item, [:x_get_tree_item_kids]
has_kids_for MiqProductFeature, [:x_get_tree_feature_kids]
def initialize(name, type, sandbox, build, role:, editable: false)
@role = role
@editable = editable
@features = @role.miq_product_features.order(:identifier).pluck(:identifier)
@root_counter = []
# Make sure tree_state doesn't hold on to old data between requests
TreeState.new(sandbox).remove_tree(name)
super(name, type, sandbox, build)
end
private
def set_locals_for_render
locals = {
:checkboxes => true,
:three_checks => true,
:check_url => "/ops/rbac_role_field_changed/",
:onclick => nil,
:post_check => true
}
locals[:oncheck] = "miqOnCheckHandler" if @editable
super.merge!(locals)
end
def x_get_tree_roots(count_only = false, _options)
top_nodes = Menu::Manager.map do |section|
next if section.id == :cons && !Settings.product.consumption
next if section.name.nil?
next unless Vmdb::PermissionStores.instance.can?(section.id)
section
end
top_nodes << MiqProductFeature.obj_features["all_vm_rules"][:feature]
count_only_or_objects(count_only, top_nodes)
end
def x_get_tree_section_kids(parent, count_only = false)
kids = parent.items.reject do |item|
if item.kind_of?(Menu::Item)
item.feature.nil? || !MiqProductFeature.feature_exists?(item.feature)
end
end
count_only_or_objects(count_only, kids)
end
def x_get_tree_item_kids(parent, count_only = false)
kids = MiqProductFeature.obj_feature_children(parent.feature)
count_only_or_objects(count_only, kids)
end
def x_get_tree_feature_kids(parent, count_only = false)
kids = MiqProductFeature.obj_feature_children(parent.identifier) || []
count_only_or_objects(count_only, kids)
end
def tree_init_options(_tree_name)
{
:lazy => false,
:add_root => true,
:role => @role,
:features => @features,
:editable => @editable,
:node_id_prefix => node_id_prefix
}
end
def root_options
{
:key => "#{node_id_prefix}__#{root_feature}",
:icon => "pficon pficon-folder-close",
:title => _(root_details[:name]),
:tooltip => _(root_details[:description]) || _(root_details[:name]),
:expand => true,
:cfmeNoClick => true,
:select => root_select_state,
:checkable => @editable
}
end
def root_details
@root_details ||= MiqProductFeature.feature_details(root_feature)
end
def root_select_state
@features.include?(root_feature) || select_state_from_counter
end
def select_state_from_counter
return false if @root_counter.empty?
return true if @root_counter.all? { |n| n == true } # true not truthy
return 'undefined' if @root_counter.any? { |n| n || n == 'undefined' }
false
end
def node_id_prefix
@role.id || "new"
end
def root_feature
@root_feature ||= MiqProductFeature.feature_root
end
def all_vm_options
text = _("Access Rules for all Virtual Machines")
checked = @features.include?("all_vm_rules") || root_select_state
{
:key => "#{node_id_prefix}___tab_all_vm_rules",
:title => text,
:tooltip => text,
:icon => "pficon pficon-folder-close",
:select => checked
}
end
def override(node, object, _, _)
case object
when Menu::Section
@root_counter << node[:select]
when MiqProductFeature
if object.identifier == "all_vm_rules"
node.merge!(all_vm_options)
end
end
end
end