Skip to content

Commit

Permalink
issue: when user changing display Timezone than widget content for ne…
Browse files Browse the repository at this point in the history
…w Timezone was not generated yet and some widgets on dasgboard does not show any data since Timezone is present in condition. Fix: if contents with respect to Timezone not found than try to search for widgets content without Timezone filter.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1676584
  • Loading branch information
yrudman committed Feb 20, 2019
1 parent 80bcb81 commit 1cc4672
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions app/models/miq_widget.rb
Expand Up @@ -327,7 +327,7 @@ def find_or_build_contents_for_user(group, user, timezone = nil)
settings_for_build = {:miq_group_id => group.id}
settings_for_build[:user_id] = user.id if user
settings_for_build[:timezone] = timezone if timezone
contents = contents_for_owner(group, user, timezone) || miq_widget_contents.build(settings_for_build)
contents = miq_widget_contents.find_by(settings_for_build) || miq_widget_contents.build(settings_for_build)
contents.updated_at = Time.now.utc # Force updated timestamp to change when saved even if the new contents are the same

contents
Expand Down Expand Up @@ -355,20 +355,22 @@ def create_initial_content_for_user(user, group = nil)
end
end

def contents_for_owner(group, user, timezone = nil)
return unless group
timezone = "UTC" if timezone && !timezone_matters?
conditions = {:miq_group_id => group.id}
conditions[:user_id] = user.id if user
conditions[:timezone] = timezone if timezone
miq_widget_contents.find_by(conditions)
end

def contents_for_user(user)
user = self.class.get_user(user)
timezone = timezone_matters? ? user.get_timezone : "UTC"
contents = contents_for_owner(user.current_group, user, timezone)
contents ||= contents_for_owner(user.current_group, nil, timezone)
conditions = {:miq_group_id => user.current_group.id}
conditions[:user_id] = user.id
conditions[:timezone] = timezone
contents = miq_widget_contents.find_by(conditions)

conditions.delete(:user_id)
contents ||= miq_widget_contents.find_by(conditions)

if contents.nil?
_log.warn("No contents found for Widget: '#{title}' Group: #{user.current_group.description} in Timezone '#{timezone}'. Attempting to get widget's contents from any Timezone ...")
conditions.delete(:timezone)
contents = miq_widget_contents.find_by(conditions)
end
contents
end

Expand Down

0 comments on commit 1cc4672

Please sign in to comment.