Commit 1ef1a4ae6e8f91e78e57ccd9d458ed2806f9bf77
Exists in
master
and in
4 other branches
Merge pull request #1239 from tsigo/disable_gravatar
Allow disabling Gravatars in gitlab.yml settings
Showing
4 changed files
with
43 additions
and
11 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -2,10 +2,13 @@ require 'digest/md5' |
2 | 2 | module ApplicationHelper |
3 | 3 | |
4 | 4 | def gravatar_icon(user_email = '', size = 40) |
5 | - return unless user_email | |
6 | - gravatar_host = request.ssl? ? "https://secure.gravatar.com" : "http://www.gravatar.com" | |
7 | - user_email.strip! | |
8 | - "#{gravatar_host}/avatar/#{Digest::MD5.hexdigest(user_email.downcase)}?s=#{size}&d=identicon" | |
5 | + if Gitlab.config.disable_gravatar? || user_email.blank? | |
6 | + 'no_avatar.png' | |
7 | + else | |
8 | + gravatar_prefix = request.ssl? ? "https://secure" : "http://www" | |
9 | + user_email.strip! | |
10 | + "#{gravatar_prefix}.gravatar.com/avatar/#{Digest::MD5.hexdigest(user_email.downcase)}?s=#{size}&d=identicon" | |
11 | + end | |
9 | 12 | end |
10 | 13 | |
11 | 14 | def request_protocol | ... | ... |
config/gitlab.yml.example
1 | -# # # # # # # # # # # # # # # # # # | |
1 | +# # # # # # # # # # # # # # # # # # | |
2 | 2 | # Gitlab application config file # |
3 | 3 | # # # # # # # # # # # # # # # # # # |
4 | 4 | |
... | ... | @@ -19,14 +19,14 @@ email: |
19 | 19 | |
20 | 20 | # Application specific settings |
21 | 21 | # Like default project limit for user etc |
22 | -app: | |
23 | - default_projects_limit: 10 | |
22 | +app: | |
23 | + default_projects_limit: 10 | |
24 | 24 | # backup_path: "/vol/backups" # default: Rails.root + backups/ |
25 | 25 | # backup_keep_time: 604800 # default: 0 (forever) (in seconds) |
26 | + # disable_gravatar: true # default: false - Disable user avatars from Gravatar.com | |
26 | 27 | |
27 | - | |
28 | -# | |
29 | -# 2. Advanced settings: | |
28 | +# | |
29 | +# 2. Advanced settings: | |
30 | 30 | # ========================== |
31 | 31 | |
32 | 32 | # Git Hosting configuration |
... | ... | @@ -39,7 +39,6 @@ git_host: |
39 | 39 | receive_pack: true |
40 | 40 | # port: 22 |
41 | 41 | |
42 | - | |
43 | 42 | # Git settings |
44 | 43 | # Use default values unless you understand it |
45 | 44 | git: | ... | ... |
config/initializers/1_settings.rb
... | ... | @@ -0,0 +1,26 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe ApplicationHelper do | |
4 | + describe "gravatar_icon" do | |
5 | + let(:user_email) { 'user@email.com' } | |
6 | + | |
7 | + it "should return a generic avatar path when Gravatar is disabled" do | |
8 | + Gitlab.config.stub(:disable_gravatar?).and_return(true) | |
9 | + gravatar_icon(user_email).should == 'no_avatar.png' | |
10 | + end | |
11 | + | |
12 | + it "should return a generic avatar path when email is blank" do | |
13 | + gravatar_icon('').should == 'no_avatar.png' | |
14 | + end | |
15 | + | |
16 | + it "should use SSL when appropriate" do | |
17 | + stub!(:request).and_return(double(:ssl? => true)) | |
18 | + gravatar_icon(user_email).should match('https://secure.gravatar.com') | |
19 | + end | |
20 | + | |
21 | + it "should accept a custom size" do | |
22 | + stub!(:request).and_return(double(:ssl? => false)) | |
23 | + gravatar_icon(user_email, 64).should match(/\?s=64/) | |
24 | + end | |
25 | + end | |
26 | +end | ... | ... |