diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-05-26 10:56:08 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-06-01 10:07:24 -0500 |
commit | dcd002a15bd9a3efee7b75de17c0f6d303c2a009 (patch) | |
tree | 3fd8d97ccfa808bcaa59ee13c0b1450fbc7539ec /app/services/gravatar_service.rb | |
parent | bd259d6bab4b3c9856be6c3d2e0c16e0836c9380 (diff) | |
download | gitlab-ce-dcd002a15bd9a3efee7b75de17c0f6d303c2a009.tar.gz |
Add username parameter to gravatar URL
Diffstat (limited to 'app/services/gravatar_service.rb')
-rw-r--r-- | app/services/gravatar_service.rb | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/app/services/gravatar_service.rb b/app/services/gravatar_service.rb index 433ecc2df32..e77e08aa380 100644 --- a/app/services/gravatar_service.rb +++ b/app/services/gravatar_service.rb @@ -1,15 +1,20 @@ class GravatarService include Gitlab::CurrentSettings - def execute(email, size = nil, scale = 2) - if current_application_settings.gravatar_enabled? && email.present? - size = 40 if size.nil? || size <= 0 + def execute(email, size = nil, scale = 2, username: nil) + return unless current_application_settings.gravatar_enabled? - sprintf gravatar_url, - hash: Digest::MD5.hexdigest(email.strip.downcase), - size: size * scale, - email: email.strip - end + identifier = email.presence || username.presence + return unless identifier + + hash = Digest::MD5.hexdigest(identifier.strip.downcase) + size = 40 unless size && size > 0 + + sprintf gravatar_url, + hash: hash, + size: size * scale, + email: ERB::Util.url_encode(email&.strip || ''), + username: ERB::Util.url_encode(username&.strip || '') end def gitlab_config |