From f338ff43c13a6dd5c3bf90bd58c0d5cff52fc79c Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Wed, 7 Feb 2018 18:20:20 +0100 Subject: Refactor and split ApplicationHelper#avatar_icon. When we don't use the original `ApplicationHelper#avatar_icon` anymore, we can just remove it (and its specs). Closes #42800. --- app/helpers/application_helper.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'app/helpers/application_helper.rb') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6530327698b..77c86be4714 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -69,17 +69,27 @@ module ApplicationHelper 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 + if user_or_email.is_a?(User) + avatar_icon_for_user(user_or_email, size, scale, only_path: only_path) + else + avatar_icon_for_email(user_or_email, size, scale, only_path: only_path) + 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 -- cgit v1.2.3 From c4cf7220146f74196ef20b12cf0db3502649ac06 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Fri, 9 Feb 2018 13:28:59 +0100 Subject: Remove generic #avatar_icon helper. --- app/helpers/application_helper.rb | 8 -------- 1 file changed, 8 deletions(-) (limited to 'app/helpers/application_helper.rb') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 77c86be4714..a889decab26 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -68,14 +68,6 @@ module ApplicationHelper end end - def avatar_icon(user_or_email = nil, size = nil, scale = 2, only_path: true) - if user_or_email.is_a?(User) - avatar_icon_for_user(user_or_email, size, scale, only_path: only_path) - else - avatar_icon_for_email(user_or_email, size, scale, only_path: only_path) - 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 -- cgit v1.2.3 From dd1d13b859c4c4cd7b6a64eb93f761c10c9262d4 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Tue, 13 Feb 2018 17:02:06 +0100 Subject: 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. --- app/helpers/application_helper.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/helpers/application_helper.rb') 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 -- cgit v1.2.3