Commit 65bcc41f authored by Robert Speicher's avatar Robert Speicher

Allow disabling Gravatars in gitlab.yml settings

Closes #1237
parent 0456dd72
...@@ -2,10 +2,13 @@ require 'digest/md5' ...@@ -2,10 +2,13 @@ require 'digest/md5'
module ApplicationHelper module ApplicationHelper
def gravatar_icon(user_email = '', size = 40) def gravatar_icon(user_email = '', size = 40)
return unless user_email if Gitlab.config.disable_gravatar? || user_email.blank?
gravatar_host = request.ssl? ? "https://secure.gravatar.com" : "http://www.gravatar.com" 'no_avatar.png'
else
gravatar_prefix = request.ssl? ? "https://secure" : "http://www"
user_email.strip! user_email.strip!
"#{gravatar_host}/avatar/#{Digest::MD5.hexdigest(user_email.downcase)}?s=#{size}&d=identicon" "#{gravatar_prefix}.gravatar.com/avatar/#{Digest::MD5.hexdigest(user_email.downcase)}?s=#{size}&d=identicon"
end
end end
def request_protocol def request_protocol
......
...@@ -23,7 +23,7 @@ app: ...@@ -23,7 +23,7 @@ app:
default_projects_limit: 10 default_projects_limit: 10
# backup_path: "/vol/backups" # default: Rails.root + backups/ # backup_path: "/vol/backups" # default: Rails.root + backups/
# backup_keep_time: 604800 # default: 0 (forever) (in seconds) # backup_keep_time: 604800 # default: 0 (forever) (in seconds)
# disable_gravatar: true # default: false - Disable user avatars from Gravatar.com
# #
# 2. Advanced settings: # 2. Advanced settings:
...@@ -39,7 +39,6 @@ git_host: ...@@ -39,7 +39,6 @@ git_host:
receive_pack: true receive_pack: true
# port: 22 # port: 22
# Git settings # Git settings
# Use default values unless you understand it # Use default values unless you understand it
git: git:
......
...@@ -111,5 +111,9 @@ class Settings < Settingslogic ...@@ -111,5 +111,9 @@ class Settings < Settingslogic
def backup_keep_time def backup_keep_time
app['backup_keep_time'] || 0 app['backup_keep_time'] || 0
end end
def disable_gravatar?
app['disable_gravatar'] || false
end
end end
end end
require 'spec_helper'
describe ApplicationHelper do
describe "gravatar_icon" do
let(:user_email) { 'user@email.com' }
it "should return a generic avatar path when Gravatar is disabled" do
Gitlab.config.stub(:disable_gravatar?).and_return(true)
gravatar_icon(user_email).should == 'no_avatar.png'
end
it "should return a generic avatar path when email is blank" do
gravatar_icon('').should == 'no_avatar.png'
end
it "should use SSL when appropriate" do
stub!(:request).and_return(double(:ssl? => true))
gravatar_icon(user_email).should match('https://secure.gravatar.com')
end
it "should accept a custom size" do
stub!(:request).and_return(double(:ssl? => false))
gravatar_icon(user_email, 64).should match(/\?s=64/)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment