Skip to content

Commit a973dc4

Browse files
committed
WIP fix widgets serializing role names that could change
Based on changes in ManageIQ#9709
1 parent c2bd3bf commit a973dc4

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

app/controllers/report_controller/widgets.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,8 @@ def widget_get_node_info
292292
if @widget.visibility && @widget.visibility[:roles]
293293
@sb[:user_roles] = []
294294
if @widget.visibility[:roles][0] != "_ALL_"
295-
Rbac.filtered(MiqUserRole).sort_by(&:name).each do |r|
296-
@sb[:user_roles].push(r.name) if @widget.visibility[:roles].include?(r.name)
297-
end
295+
role_ids = @widget.visibility[:roles]
296+
@sb[:user_roles] = Rbac.filtered(MiqUserRole.where(:id => role_ids)).order(:name).pluck(:name)
298297
end
299298
elsif @widget.visibility && @widget.visibility[:groups]
300299
@sb[:groups] = []
@@ -335,8 +334,7 @@ def widget_set_form_vars
335334
if @widget.visibility[:roles][0] == "_ALL_"
336335
@edit[:new][:roles] = ["_ALL_"]
337336
else
338-
roles = Rbac.filtered(MiqUserRole.where(:name => @widget.visibility[:roles]))
339-
@edit[:new][:roles] = roles.collect(&:id).sort
337+
@edit[:new][:roles] = @widget.visibility[:roles].sort
340338
end
341339
elsif @widget.visibility[:groups]
342340
@edit[:new][:visibility_typ] = "group"
@@ -573,12 +571,7 @@ def widget_set_record_vars(widget)
573571
widget.visibility.delete(:roles) if widget.visibility[:roles]
574572
else
575573
if @edit[:new][:visibility_typ] == "role"
576-
roles = []
577-
@edit[:new][:roles].each do |r|
578-
role = MiqUserRole.find(r)
579-
roles.push(role.name) if r == role.id.to_s
580-
end
581-
widget.visibility[:roles] = roles
574+
widget.visibility[:roles] = @edit[:new][:roles]
582575
else
583576
widget.visibility[:roles] = ["_ALL_"]
584577
end

spec/controllers/report_controller/widget_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
@edit_hash[:new][:visibility_typ] = 'role'
6868
@edit_hash[:new][:roles] = [role.id.to_s]
6969
controller.send(:widget_set_record_vars, @widget)
70-
expect(@widget.visibility[:roles]).to eq([role.name])
70+
expect(@widget.visibility[:roles]).to eq([role.id.to_s])
7171
end
7272

7373
it "sets group visibility for widget" do

0 commit comments

Comments
 (0)