Skip to content

Commit

Permalink
Merge pull request #2570 from micdahl/gravatar-optional
Browse files Browse the repository at this point in the history
Making Gravatar optional in config
  • Loading branch information
bbenezech committed Jun 7, 2016
2 parents 20be7f0 + 7778217 commit 3924e5b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/rails_admin/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def edit_user_link
return nil unless (edit_action = RailsAdmin::Config::Actions.find(:edit, controller: controller, abstract_model: abstract_model, object: _current_user)).try(:authorized?)
link_to url_for(action: edit_action.action_name, model_name: abstract_model.to_param, id: _current_user.id, controller: 'rails_admin/main') do
html = []
html << image_tag("#{(request.ssl? ? 'https://secure' : 'http://www')}.gravatar.com/avatar/#{Digest::MD5.hexdigest _current_user.email}?s=30", alt: '') if _current_user.email.present?
html << image_tag("#{(request.ssl? ? 'https://secure' : 'http://www')}.gravatar.com/avatar/#{Digest::MD5.hexdigest _current_user.email}?s=30", alt: '') if RailsAdmin::Config.show_gravatar && _current_user.email.present?
html << content_tag(:span, _current_user.email)
html.join.html_safe
end
Expand Down
4 changes: 4 additions & 0 deletions lib/generators/rails_admin/templates/initializer.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ RailsAdmin.config do |config|

### More at https://github.com/sferik/rails_admin/wiki/Base-configuration

## == Gravatar integration ==
## To disable Gravatar integration in Navigation Bar set to false
# config.show_gravatar true

config.actions do
dashboard # mandatory
index # mandatory
Expand Down
4 changes: 4 additions & 0 deletions lib/rails_admin/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class << self
# @see RailsAdmin.config
attr_reader :registry

# show Gravatar in Navigation bar
attr_accessor :show_gravatar

# accepts a hash of static links to be shown below the main navigation
attr_accessor :navigation_static_links
attr_accessor :navigation_static_label
Expand Down Expand Up @@ -279,6 +282,7 @@ def reset
@label_methods = [:name, :title]
@main_app_name = proc { [Rails.application.engine_name.titleize.chomp(' Application'), 'Admin'] }
@registry = {}
@show_gravatar = true
@navigation_static_links = {}
@navigation_static_label = nil
@parent_controller = '::ApplicationController'
Expand Down
16 changes: 16 additions & 0 deletions spec/helpers/rails_admin/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,22 @@ def initialize(_user)
result = helper.edit_user_link
expect(result).to match('href')
end

it 'show gravatar' do
allow(helper).to receive(:_current_user).and_return(FactoryGirl.create(:user))
result = helper.edit_user_link
expect(result).to include('gravatar')
end

it "don't show gravatar" do
RailsAdmin.config do |config|
config.show_gravatar = false
end

allow(helper).to receive(:_current_user).and_return(FactoryGirl.create(:user))
result = helper.edit_user_link
expect(result).not_to include('gravatar')
end
end
end

Expand Down

0 comments on commit 3924e5b

Please # to comment.