]> source.dussan.org Git - redmine.git/commitdiff
Add avatar_server_url configuration option in order to support Libravatar (#9112).
authorGo MAEDA <maeda@farend.jp>
Sat, 4 May 2019 15:59:50 +0000 (15:59 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 4 May 2019 15:59:50 +0000 (15:59 +0000)
Patch by Go MAEDA.

git-svn-id: http://svn.redmine.org/redmine/trunk@18124 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
app/views/settings/_display.html.erb
config/configuration.yml.example
config/locales/en.yml
lib/plugins/gravatar/lib/gravatar.rb
lib/redmine/configuration.rb
test/functional/my_controller_test.rb
test/helpers/application_helper_test.rb

index 3712b8a0525eca2b211b8f1af474febfbcb90604..832c22b13a1a7479113f5f5e885b12e04c26f71f 100644 (file)
@@ -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
index 3b62eabd8bc7d2a993e9ab89de33ffe57d343a9a..30e6525f70fb01375eefa5912244c12ea2b02619 100644 (file)
@@ -19,7 +19,8 @@
 
 <p><%= setting_select :user_format, @options[:user_format] %></p>
 
-<p><%= setting_check_box :gravatar_enabled, :data => {:enables => '#settings_gravatar_default'} %></p>
+<p><%= setting_check_box :gravatar_enabled, :data => {:enables => '#settings_gravatar_default'} %>
+<em class="info"><%= t(:text_avatar_server_config_html, :url => Redmine::Configuration['avatar_server_url']) %></em></p>
 
 <p><%= setting_select :gravatar_default, gravatar_default_setting_options, :blank => :label_none %></p>
 
index bff4c97408690275410a3037adca87c346e16f03..d11bc6146997f2dbcde78cfd44702a32d5afb727 100644 (file)
@@ -209,6 +209,21 @@ default:
   # allowed values: :memory, :file, :memcache
   #openid_authentication_store: :memory
 
+  # URL of the avatar server
+  #
+  # By default, Redmine uses Gravatar as the avatar server for displaying
+  # user icons. You can switch to another Gravatar-compatible server such
+  # as Libravatar and opensource servers listed on
+  # https://wiki.libravatar.org/running_your_own/
+  #
+  # 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:
index 087e749390833230c177abd6e2a26a49f52fb25a..79f47cb6c5ea71154d934d9401379d6a49226f72 100644 (file)
@@ -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 <a href="%{url}">%{url}</a>. You can configure it in config/configuration.yml.
+
 
   default_role_manager: Manager
   default_role_developer: Developer
index 7c2fca6d3a25f0024a12ae48365379fabe01b9be..aa8500ba9efc34c43cca5317b77af136aa3968ee 100644 (file)
@@ -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.
index 4ecd4766b3e58c5eff33f058a2a60e019738cf51..88501e40bbbdf818a14998b78bf534c3a925c07c 100644 (file)
@@ -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
     }
index d761d5b8edf589c062ffea2e48afb7e3b6620e36..c625f73fa4f78f736ad439be2f45de1e93f5ad7b 100644 (file)
@@ -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
 
index 74acae4b0ce884ecacaf4760ac8b3fbd2fbe728a..b91012b588d6dc375e3555064b757794b143c6dc 100644 (file)
@@ -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('<jsmith@somenet.foo>')
+        end
+      end
+    end
+  end
+
   def test_link_to_user
     user = User.find(2)
     result = link_to("John Smith", "/users/2", :class => "user active")