Commit 0aa7f79ca4255eadd7d2aad7c3378915ee54e107
1 parent
2c37fa38
Exists in
master
and in
4 other branches
allow customize gravatar url
Showing
4 changed files
with
36 additions
and
2 deletions
Show diff stats
app/helpers/application_helper.rb
| 1 | require 'digest/md5' | 1 | require 'digest/md5' |
| 2 | +require 'uri' | ||
| 2 | 3 | ||
| 3 | module ApplicationHelper | 4 | module ApplicationHelper |
| 4 | 5 | ||
| @@ -36,9 +37,9 @@ module ApplicationHelper | @@ -36,9 +37,9 @@ module ApplicationHelper | ||
| 36 | if Gitlab.config.disable_gravatar? || user_email.blank? | 37 | if Gitlab.config.disable_gravatar? || user_email.blank? |
| 37 | 'no_avatar.png' | 38 | 'no_avatar.png' |
| 38 | else | 39 | else |
| 39 | - gravatar_prefix = request.ssl? ? "https://secure" : "http://www" | 40 | + gravatar_url = request.ssl? ? Gitlab.config.gravatar_ssl_url : Gitlab.config.gravatar_url |
| 40 | user_email.strip! | 41 | user_email.strip! |
| 41 | - "#{gravatar_prefix}.gravatar.com/avatar/#{Digest::MD5.hexdigest(user_email.downcase)}?s=#{size}&d=mm" | 42 | + sprintf(gravatar_url, {:hash => Digest::MD5.hexdigest(user_email.downcase), :email => URI.escape(user_email), :size => size}) |
| 42 | end | 43 | end |
| 43 | end | 44 | end |
| 44 | 45 |
config/gitlab.yml.example
| @@ -24,6 +24,8 @@ app: | @@ -24,6 +24,8 @@ app: | ||
| 24 | # backup_path: "/vol/backups" # default: Rails.root + backups/ | 24 | # backup_path: "/vol/backups" # default: Rails.root + backups/ |
| 25 | # backup_keep_time: 604800 # default: 0 (forever) (in seconds) | 25 | # backup_keep_time: 604800 # default: 0 (forever) (in seconds) |
| 26 | # disable_gravatar: true # default: false - Disable user avatars from Gravatar.com | 26 | # disable_gravatar: true # default: false - Disable user avatars from Gravatar.com |
| 27 | + # gravatar_url: "http://" # default: http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=mm | ||
| 28 | + # gravatar_ssl_url: "https://" # default: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm | ||
| 27 | 29 | ||
| 28 | 30 | ||
| 29 | # | 31 | # |
config/initializers/1_settings.rb
| @@ -145,5 +145,14 @@ class Settings < Settingslogic | @@ -145,5 +145,14 @@ class Settings < Settingslogic | ||
| 145 | def disable_gravatar? | 145 | def disable_gravatar? |
| 146 | app['disable_gravatar'] || false | 146 | app['disable_gravatar'] || false |
| 147 | end | 147 | end |
| 148 | + | ||
| 149 | + def gravatar_url | ||
| 150 | + app['gravatar_url'] || 'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=mm' | ||
| 151 | + end | ||
| 152 | + | ||
| 153 | + def gravatar_ssl_url | ||
| 154 | + app['gravatar_ssl_url'] || 'https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm' | ||
| 155 | + end | ||
| 156 | + | ||
| 148 | end | 157 | end |
| 149 | end | 158 | end |
spec/helpers/application_helper_spec.rb
| @@ -51,14 +51,36 @@ describe ApplicationHelper do | @@ -51,14 +51,36 @@ describe ApplicationHelper do | ||
| 51 | gravatar_icon('').should == 'no_avatar.png' | 51 | gravatar_icon('').should == 'no_avatar.png' |
| 52 | end | 52 | end |
| 53 | 53 | ||
| 54 | + it "should return default gravatar url" do | ||
| 55 | + stub!(:request).and_return(double(:ssl? => false)) | ||
| 56 | + gravatar_icon(user_email).should match('http://www.gravatar.com/avatar/b58c6f14d292556214bd64909bcdb118') | ||
| 57 | + end | ||
| 58 | + | ||
| 54 | it "should use SSL when appropriate" do | 59 | it "should use SSL when appropriate" do |
| 55 | stub!(:request).and_return(double(:ssl? => true)) | 60 | stub!(:request).and_return(double(:ssl? => true)) |
| 56 | gravatar_icon(user_email).should match('https://secure.gravatar.com') | 61 | gravatar_icon(user_email).should match('https://secure.gravatar.com') |
| 57 | end | 62 | end |
| 58 | 63 | ||
| 64 | + it "should return custom gravatar path when gravatar_url is set" do | ||
| 65 | + stub!(:request).and_return(double(:ssl? => false)) | ||
| 66 | + Gitlab.config.stub(:gravatar_url).and_return('http://example.local/?s=%{size}&hash=%{hash}') | ||
| 67 | + gravatar_icon(user_email, 20).should == 'http://example.local/?s=20&hash=b58c6f14d292556214bd64909bcdb118' | ||
| 68 | + end | ||
| 69 | + | ||
| 59 | it "should accept a custom size" do | 70 | it "should accept a custom size" do |
| 60 | stub!(:request).and_return(double(:ssl? => false)) | 71 | stub!(:request).and_return(double(:ssl? => false)) |
| 61 | gravatar_icon(user_email, 64).should match(/\?s=64/) | 72 | gravatar_icon(user_email, 64).should match(/\?s=64/) |
| 62 | end | 73 | end |
| 74 | + | ||
| 75 | + it "should use default size when size is wrong" do | ||
| 76 | + stub!(:request).and_return(double(:ssl? => false)) | ||
| 77 | + gravatar_icon(user_email, nil).should match(/\?s=40/) | ||
| 78 | + end | ||
| 79 | + | ||
| 80 | + it "should be case insensitive" do | ||
| 81 | + stub!(:request).and_return(double(:ssl? => false)) | ||
| 82 | + gravatar_icon(user_email).should == gravatar_icon(user_email.upcase + " ") | ||
| 83 | + end | ||
| 84 | + | ||
| 63 | end | 85 | end |
| 64 | end | 86 | end |