diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3712b8a05..832c22b13 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1507,7 +1507,7 @@ module ApplicationHelper # 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 = Redmine::Configuration['avatar_server_url'] link_to avatar(user, {:title => l(:button_edit)}.merge(options)), url, :target => '_blank' end end diff --git a/app/views/settings/_display.html.erb b/app/views/settings/_display.html.erb index 3b62eabd8..30e6525f7 100644 --- a/app/views/settings/_display.html.erb +++ b/app/views/settings/_display.html.erb @@ -19,7 +19,8 @@

<%= setting_select :user_format, @options[:user_format] %>

-

<%= setting_check_box :gravatar_enabled, :data => {:enables => '#settings_gravatar_default'} %>

+

<%= setting_check_box :gravatar_enabled, :data => {:enables => '#settings_gravatar_default'} %> +<%= t(:text_avatar_server_config_html, :url => Redmine::Configuration['avatar_server_url']) %>

<%= setting_select :gravatar_default, gravatar_default_setting_options, :blank => :label_none %>

diff --git a/config/configuration.yml.example b/config/configuration.yml.example index bff4c9740..1b3372c54 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -209,6 +209,19 @@ default: # 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: diff --git a/config/locales/en.yml b/config/locales/en.yml index 087e74939..79f47cb6c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1202,6 +1202,8 @@ en: text_project_closed: This project is closed and read-only. text_turning_multiple_off: "If you disable multiple values, multiple values will be removed in order to preserve only one value per item." text_select_apply_tracker: "Select tracker" + text_avatar_server_config_html: The current avatar server is %{url}. You can configure it in config/configuration.yml. + default_role_manager: Manager default_role_developer: Developer diff --git a/lib/plugins/gravatar/lib/gravatar.rb b/lib/plugins/gravatar/lib/gravatar.rb index 7c2fca6d3..aa8500ba9 100644 --- a/lib/plugins/gravatar/lib/gravatar.rb +++ b/lib/plugins/gravatar/lib/gravatar.rb @@ -63,7 +63,7 @@ module GravatarHelper # Returns the base Gravatar URL for the given email hash def gravatar_api_url(hash) - 'https://www.gravatar.com/avatar/' + hash.to_s + +"#{Redmine::Configuration['avatar_server_url']}/avatar/#{hash}" end # Return the gravatar URL for the given email address. diff --git a/lib/redmine/configuration.rb b/lib/redmine/configuration.rb index 4ecd4766b..88501e40b 100644 --- a/lib/redmine/configuration.rb +++ b/lib/redmine/configuration.rb @@ -22,6 +22,7 @@ module Redmine # Configuration default values @defaults = { + 'avatar_server_url' => 'https://www.gravatar.com', 'email_delivery' => nil, 'max_concurrent_ajax_uploads' => 2 } diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb index d761d5b8e..c625f73fa 100644 --- a/test/functional/my_controller_test.rb +++ b/test/functional/my_controller_test.rb @@ -365,9 +365,11 @@ class MyControllerTest < Redmine::ControllerTest def test_my_account_with_avatar_enabled_should_link_to_edit_avatar with_settings :gravatar_enabled => '1' do - get :account - assert_response :success - assert_select 'a[href=?] img.gravatar', 'https://gravatar.com' + Redmine::Configuration.with 'avatar_server_url' => 'https://gravatar.com' do + get :account + assert_response :success + assert_select 'a[href=?] img.gravatar', 'https://gravatar.com' + end end end diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 74acae4b0..b91012b58 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -1529,6 +1529,21 @@ RAW end end + def test_avatar_server_url + to_test = { + 'https://www.gravatar.com' => %r|https://www.gravatar.com/avatar/\h{32}|, + 'https://seccdn.libravatar.org' => %r|https://seccdn.libravatar.org/avatar/\h{32}|, + 'http://localhost:8080' => %r|http://localhost:8080/avatar/\h{32}|, + } + with_settings :gravatar_enabled => '1' do + to_test.each do |url, expected| + Redmine::Configuration.with 'avatar_server_url' => url do + assert_match expected, avatar('') + end + end + end + end + def test_link_to_user user = User.find(2) result = link_to("John Smith", "/users/2", :class => "user active")