diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-02-13 19:02:06 +0300 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-02-13 20:04:53 +0300 |
commit | dd1d13b859c4c4cd7b6a64eb93f761c10c9262d4 (patch) | |
tree | 171ce3b968edd8b46d0b58b97248f815169d8ab3 /app/helpers/application_helper.rb | |
parent | 6670074c0663be55f28de7cdb04a27432c7304f2 (diff) |
Extract repeated logic into #avatar_icon_for.
This essentially allows to pass both user and email, so that we can
either prefer the user to retrieve the avatar or (if user is not
present) fall back to the email lookup.
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r-- | app/helpers/application_helper.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a889decab26..a6011eb9f30 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -68,6 +68,18 @@ module ApplicationHelper end 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 |