debian-mirror-gitlab/app/services/gravatar_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
863 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
class GravatarService
2017-09-10 17:25:29 +05:30
def execute(email, size = nil, scale = 2, username: nil)
2022-08-13 15:12:31 +05:30
return if Gitlab::FIPS.enabled?
2018-03-17 18:26:18 +05:30
return unless Gitlab::CurrentSettings.gravatar_enabled?
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
identifier = email.presence || username.presence
return unless identifier
hash = Digest::MD5.hexdigest(identifier.strip.downcase)
2022-01-26 12:08:38 +05:30
size = Groups::GroupMembersHelper::AVATAR_SIZE unless size && size > 0
2017-09-10 17:25:29 +05:30
sprintf gravatar_url,
hash: hash,
size: size * scale,
email: ERB::Util.url_encode(email&.strip || ''),
username: ERB::Util.url_encode(username&.strip || '')
2014-09-02 18:07:02 +05:30
end
def gitlab_config
Gitlab.config.gitlab
end
def gravatar_config
Gitlab.config.gravatar
end
def gravatar_url
if gitlab_config.https
gravatar_config.ssl_url
else
gravatar_config.plain_url
end
end
end