Permalink
Browse files

added current_user_method to RailsAdmin, allowing the logged in user …

…method to be customized easily
  • Loading branch information...
1 parent f30bc84 commit 2f57b725e60af2897f7eb5ff9c32770d436ae468 @joshk joshk committed Dec 18, 2010
@@ -6,6 +6,8 @@ class ApplicationController < ::ApplicationController
before_filter :_authorize!
before_filter :set_plugin_name
+ helper_method :_current_user
+
private
def _authenticate!
@@ -16,6 +18,10 @@ def _authorize!
instance_eval &RailsAdmin.authorize_with
end
+ def _current_user
+ instance_eval &RailsAdmin.current_user_method
+ end
+
def set_plugin_name
@plugin_name = "RailsAdmin"
end
@@ -350,7 +350,7 @@ def check_history
:message => message,
:item => @object.id,
:table => @abstract_model.pretty_name,
- :username => current_user ? current_user.email : "",
+ :username => _current_user ? _current_user.email : "",
:month => date.month,
:year => date.year
)
@@ -36,7 +36,7 @@
<%= render(:partial => 'rails_admin/main/navigation') %>
<div id="headerRight">
-<%= render(:partial => 'rails_admin/main/user_info', :locals => {:current_user => current_user}) %>
+<%= render(:partial => 'rails_admin/main/user_info', :locals => {:current_user => _current_user}) %>
</div>
</div>
@@ -38,7 +38,7 @@
<%= render(:partial => 'rails_admin/main/navigation') %>
<div id="headerRight">
-<%= render(:partial => 'rails_admin/main/user_info', :locals => {:current_user => current_user}) %>
+<%= render(:partial => 'rails_admin/main/user_info', :locals => {:current_user => _current_user}) %>
</div>
</div>
<div id="content">
@@ -70,7 +70,7 @@
<%= render(:partial => 'rails_admin/main/navigation') %>
<div id="headerRight">
-<%= render(:partial => 'rails_admin/main/user_info', :locals => {:current_user => current_user}) %>
+<%= render(:partial => 'rails_admin/main/user_info', :locals => {:current_user => _current_user}) %>
</div>
</div>
<div id="content">
@@ -56,7 +56,7 @@
<%= render(:partial => 'rails_admin/main/navigation') %>
<div id="headerRight">
-<%= render(:partial => 'rails_admin/main/user_info', :locals => {:current_user => current_user}) %>
+<%= render(:partial => 'rails_admin/main/user_info', :locals => {:current_user => _current_user}) %>
</div>
</div>
<div id="content">
@@ -1,4 +1,4 @@
-<% if current_user %>
+<% if current_user = _current_user %>
<div class="user_info">
<img src="http://www.gravatar.com/avatar/<%=Digest::MD5.hexdigest current_user.email %>?s=30" alt="" />
<ul>
View
@@ -32,6 +32,10 @@ class AuthenticationNotConfigured < StandardError; end
DEFAULT_AUTHORIZE = Proc.new {}
+ DEFAULT_CURRENT_USER = Proc.new do
+ current_user
+ end
+
# Setup authentication to be run as a before filter
# This is run inside the controller instance so you can setup any authentication you need to
#
@@ -72,6 +76,22 @@ def self.authorize_with(&blk)
@authorize || DEFAULT_AUTHORIZE
end
+ # Setup a different method to determine the current user or admin logged in.
+ # This is run inside the controller instance and made available as a helper.
+ #
+ # By default, _current_user_ will be used.
+ #
+ # @example Custom
+ # RailsAdmin.current_user_method do
+ # current_admin
+ # end
+ #
+ # @see RailsAdmin::DEFAULT_CURRENT_USER
+ def self.current_user_method(&blk)
+ @current_user = blk if blk
+ @current_user || DEFAULT_CURRENT_USER
+ end
+
# Setup RailsAdmin
#
# If a model class is provided as the first argument model specific

0 comments on commit 2f57b72

Please sign in to comment.