Skip to content

Commit

Permalink
Merge pull request #12993 from yrudman/fixed-by_group-visibility-whil…
Browse files Browse the repository at this point in the history
…e-generating-content-for-widget

Fixed content generation for widget when visibility is 'By-Group'
  • Loading branch information
gtanzillo authored Dec 5, 2016
2 parents 75a7524 + 107b803 commit ecd2747
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/miq_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ def timezones_for_users(users)
end

def available_for_group?(group)
group ? has_visibility?(:roles, group.miq_user_role_name) : false
return false unless group
has_visibility?(:roles, group.miq_user_role_name) || has_visibility?(:groups, group.description)
end

def self.available_for_user(user)
Expand Down
17 changes: 17 additions & 0 deletions spec/models/miq_widget_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,23 @@ def add_dashboard_for_user(db_name, userid, group)
@widget.queue_generate_content
end

it "does not generate content if visibility set to group only and there are no users in that group" do
@widget.visibility.delete(:roles)
@widget.visibility[:groups] = @group2.description
@user2.delete

expect(@widget).not_to receive(:queue_generate_content_for_users_or_group)
@widget.queue_generate_content
end

it "generate content if visibility set to group only with users in that group" do
@widget.visibility.delete(:roles)
@widget.visibility[:groups] = @group2.description

expect(@widget).to receive(:queue_generate_content_for_users_or_group).once
@widget.queue_generate_content
end

it "creates a new task when previous task is finished" do
@widget.queue_generate_content
MiqTask.first.state_finished
Expand Down

0 comments on commit ecd2747

Please sign in to comment.