Skip to content

Commit

Permalink
use cancancan2 fix from CanCanCommunity/cancancan#413
Browse files Browse the repository at this point in the history
  • Loading branch information
glebtv committed Aug 21, 2017
1 parent ca07f9a commit 3aeaaaf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/rails_admin/extensions/cancancan/authorization_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ def initialize(controller, ability = ::Ability)
# AbstractModel instance that applies. The third argument is the actual model
# instance if it is available.
def authorize(action, abstract_model = nil, model_object = nil)
@controller.current_ability.authorize!(action, model_object || abstract_model && abstract_model.model) if action
return unless action
subject = model_object || abstract_model && abstract_model.model
@controller.current_ability.authorize!(subject ? action : :read, subject)
end

# This method is called primarily from the view to determine whether the given user
# has access to perform the action on a given model. It should return true when authorized.
# This takes the same arguments as +authorize+. The difference is that this will
# return a boolean whereas +authorize+ will raise an exception when not authorized.
def authorized?(action, abstract_model = nil, model_object = nil)
@controller.current_ability.can?(action, model_object || abstract_model && abstract_model.model) if action
return unless action
subject = model_object || abstract_model && abstract_model.model
@controller.current_ability.can?(subject ? action : :read, subject)
end

# This is called when needing to scope a database query. It is called within the list
Expand Down

0 comments on commit 3aeaaaf

Please sign in to comment.