Feature #9112 » avatar_service_url_configuration-v3.patch
| app/helpers/application_helper.rb | ||
|---|---|---|
|
# Returns a link to edit user's avatar if avatars are enabled
|
||
|
def avatar_edit_link(user, options={})
|
||
|
if Setting.gravatar_enabled?
|
||
|
url = "https://gravatar.com"
|
||
|
url = avatar_server_url
|
||
|
link_to avatar(user, {:title => l(:button_edit)}.merge(options)), url, :target => '_blank'
|
||
|
end
|
||
|
end
|
||
| config/configuration.yml.example | ||
|---|---|---|
|
# allowed values: :memory, :file, :memcache
|
||
|
#openid_authentication_store: :memory
|
||
|
# URL of the avatar service
|
||
|
#
|
||
|
# By default, Redmine uses Gravatar as the avatar service for displaying
|
||
|
# the user's icon. You can swich to another Gravatar-compatible service
|
||
|
# such as Libravatar.
|
||
|
#
|
||
|
# URL of each avatar is: #{avatar_server_url}/avatar/#{hash}
|
||
|
#
|
||
|
# Examples:
|
||
|
# avatar_server_url: https://www.gravatar.com # default
|
||
|
# avatar_server_url: https://seccdn.libravatar.org
|
||
|
avatar_server_url:
|
||
|
# specific configuration options for production environment
|
||
|
# that overrides the default ones
|
||
|
production:
|
||
| lib/plugins/gravatar/lib/gravatar.rb | ||
|---|---|---|
|
# Returns the base Gravatar URL for the given email hash
|
||
|
def gravatar_api_url(hash)
|
||
|
'https://www.gravatar.com/avatar/' + hash.to_s
|
||
|
+"#{avatar_server_url}/avatar/#{hash}"
|
||
|
end
|
||
|
# Return the gravatar URL for the given email address.
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def avatar_server_url
|
||
|
@avatar_server_url ||= Redmine::Configuration['avatar_server_url'] || 'https://www.gravatar.com'
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| test/functional/my_controller_test.rb | ||
|---|---|---|
|
with_settings :gravatar_enabled => '1' do
|
||
|
get :account
|
||
|
assert_response :success
|
||
|
assert_select 'a[href=?] img.gravatar', 'https://gravatar.com'
|
||
|
assert_select 'a[href=?] img.gravatar',
|
||
|
Redmine::Configuration['avatar_server_url'] || 'https://www.gravatar.com'
|
||
|
end
|
||
|
end
|
||
| test/helpers/application_helper_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_avatar_server_url
|
||
|
to_test = {
|
||
|
'https://seccdn.libravatar.org' => %r|https://seccdn.libravatar.org/avatar/\h{32}|,
|
||
|
'http://localhost:8080' => %r|http://localhost:8080/avatar/\h{32}|,
|
||
|
# gravatar.com is used by default
|
||
|
nil => %r|https://www.gravatar.com/avatar/\h{32}|
|
||
|
}
|
||
|
with_settings :gravatar_enabled => '1' do
|
||
|
to_test.each do |url, expected|
|
||
|
@avatar_server_url = nil
|
||
|
Redmine::Configuration.with 'avatar_server_url' => url do
|
||
|
assert_match expected, avatar('<jsmith@somenet.foo>')
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
ensure
|
||
|
@avatar_server_url = nil
|
||
|
end
|
||
|
def test_link_to_user
|
||
|
user = User.find(2)
|
||
|
result = link_to("John Smith", "/users/2", :class => "user active")
|
||