avatar_service_url_configuration-v3.patch

Go MAEDA, 2019-05-04 03:57

Download (3.72 KB)

View differences:

app/helpers/application_helper.rb
1507 1507
  # Returns a link to edit user's avatar if avatars are enabled
1508 1508
  def avatar_edit_link(user, options={})
1509 1509
    if Setting.gravatar_enabled?
1510
      url = "https://gravatar.com"
1510
      url = avatar_server_url
1511 1511
      link_to avatar(user, {:title => l(:button_edit)}.merge(options)), url, :target => '_blank'
1512 1512
    end
1513 1513
  end
config/configuration.yml.example
209 209
  # allowed values: :memory, :file, :memcache
210 210
  #openid_authentication_store: :memory
211 211

  
212
  # URL of the avatar service
213
  #
214
  # By default, Redmine uses Gravatar as the avatar service for displaying
215
  # the user's icon. You can swich to another Gravatar-compatible service
216
  # such as Libravatar.
217
  #
218
  # URL of each avatar is: #{avatar_server_url}/avatar/#{hash}
219
  #
220
  # Examples:
221
  # avatar_server_url: https://www.gravatar.com        # default
222
  # avatar_server_url: https://seccdn.libravatar.org
223
  avatar_server_url:
224

  
212 225
# specific configuration options for production environment
213 226
# that overrides the default ones
214 227
production:
lib/plugins/gravatar/lib/gravatar.rb
63 63

  
64 64
    # Returns the base Gravatar URL for the given email hash
65 65
    def gravatar_api_url(hash)
66
      'https://www.gravatar.com/avatar/' + hash.to_s
66
      +"#{avatar_server_url}/avatar/#{hash}"
67 67
    end
68 68

  
69 69
    # Return the gravatar URL for the given email address.
......
83 83
      end
84 84
    end
85 85

  
86
    def avatar_server_url
87
      @avatar_server_url ||= Redmine::Configuration['avatar_server_url'] || 'https://www.gravatar.com'
88
    end
89

  
86 90
  end
87 91

  
88 92
end
test/functional/my_controller_test.rb
367 367
    with_settings :gravatar_enabled => '1' do
368 368
      get :account
369 369
      assert_response :success
370
      assert_select 'a[href=?] img.gravatar', 'https://gravatar.com'
370
      assert_select 'a[href=?] img.gravatar',
371
        Redmine::Configuration['avatar_server_url'] || 'https://www.gravatar.com'
371 372
    end
372 373
  end
373 374

  
test/helpers/application_helper_test.rb
1529 1529
    end
1530 1530
  end
1531 1531

  
1532
  def test_avatar_server_url
1533
    to_test = {
1534
      'https://seccdn.libravatar.org' => %r|https://seccdn.libravatar.org/avatar/\h{32}|,
1535
      'http://localhost:8080' => %r|http://localhost:8080/avatar/\h{32}|,
1536
      # gravatar.com is used by default
1537
      nil => %r|https://www.gravatar.com/avatar/\h{32}|
1538
    }
1539
    with_settings :gravatar_enabled => '1' do
1540
      to_test.each do |url, expected|
1541
        @avatar_server_url = nil
1542
        Redmine::Configuration.with 'avatar_server_url' => url do
1543
          assert_match expected, avatar('<jsmith@somenet.foo>')
1544
        end
1545
      end
1546
    end
1547
  ensure
1548
    @avatar_server_url = nil
1549
  end
1550

  
1532 1551
  def test_link_to_user
1533 1552
    user = User.find(2)
1534 1553
    result = link_to("John Smith", "/users/2", :class => "user active")