diff --git a/app/models/miq_widget.rb b/app/models/miq_widget.rb index 88a746eb9db..1c78f7d23cb 100644 --- a/app/models/miq_widget.rb +++ b/app/models/miq_widget.rb @@ -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) diff --git a/spec/models/miq_widget_spec.rb b/spec/models/miq_widget_spec.rb index 5c7fae9402d..1a5268f4136 100644 --- a/spec/models/miq_widget_spec.rb +++ b/spec/models/miq_widget_spec.rb @@ -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