diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-06-01 17:19:17 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-06-01 17:19:17 +0000 |
commit | 97d6085fb507d53f92699d5cfea06dd319125994 (patch) | |
tree | 37a7de6bafde1c71e40a83d8615f0d23da4d90c0 /app | |
parent | 950db1bd6472813bb539b69a309402c4eb115122 (diff) | |
parent | dcd002a15bd9a3efee7b75de17c0f6d303c2a009 (diff) | |
download | gitlab-ce-97d6085fb507d53f92699d5cfea06dd319125994.tar.gz |
Merge branch 'dm-gravatar-username' into 'master'
Add username parameter to gravatar URL
Closes #24472
See merge request !11741
Diffstat (limited to 'app')
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/services/gravatar_service.rb | 21 |
2 files changed, 14 insertions, 9 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 8114d0ff88e..32048da6c6f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -781,7 +781,7 @@ class User < ActiveRecord::Base def avatar_url(size: nil, scale: 2, **args) # We use avatar_path instead of overriding avatar_url because of carrierwave. # See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11001/diffs#note_28659864 - avatar_path(args) || GravatarService.new.execute(email, size, scale) + avatar_path(args) || GravatarService.new.execute(email, size, scale, username: username) end def all_emails 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 |