diff options
author | Eric Eastwood <contact@ericeastwood.com> | 2018-02-22 09:34:44 -0600 |
---|---|---|
committer | Eric Eastwood <contact@ericeastwood.com> | 2018-02-22 09:34:44 -0600 |
commit | 2e29597c942a524d206895510a10c541ff724c71 (patch) | |
tree | e564de8aa995a9d2dbce3049c7022eb55647b4b4 /app/helpers/application_helper.rb | |
parent | 21c16b900be62bb7074753517bacf5b59f971d2c (diff) | |
parent | 275efeeb529cdcba606c3d36f4d700551d5ba371 (diff) | |
download | gitlab-ce-2e29597c942a524d206895510a10c541ff724c71.tar.gz |
Merge branch 'master' into 42431-add-auto-devops-and-clusters-button-to-projects
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r-- | app/helpers/application_helper.rb | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 479797231cc..7b71f636397 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -68,18 +68,32 @@ module ApplicationHelper end end - def avatar_icon(user_or_email = nil, size = nil, scale = 2, only_path: true) - user = - if user_or_email.is_a?(User) - user_or_email - else - User.find_by_any_email(user_or_email.try(:downcase)) - end + # Takes both user and email and returns the avatar_icon by + # user (preferred) or email. + def avatar_icon_for(user = nil, email = nil, size = nil, scale = 2, only_path: true) + if user + avatar_icon_for_user(user, size, scale, only_path: only_path) + elsif email + avatar_icon_for_email(email, size, scale, only_path: only_path) + else + default_avatar + end + end + + def avatar_icon_for_email(email = nil, size = nil, scale = 2, only_path: true) + user = User.find_by_any_email(email.try(:downcase)) + if user + avatar_icon_for_user(user, size, scale, only_path: only_path) + else + gravatar_icon(email, size, scale) + end + end + def avatar_icon_for_user(user = nil, size = nil, scale = 2, only_path: true) if user user.avatar_url(size: size, only_path: only_path) || default_avatar else - gravatar_icon(user_or_email, size, scale) + gravatar_icon(nil, size, scale) end end |