class RailsAdmin::Extensions::CanCan::AuthorizationAdapter
This adapter is for the CanCan authorization library. You can create another adapter for different authorization behavior, just be certain it responds to each of the public methods here.
Public Class Methods
new(controller, ability = ::Ability)
click to toggle source
See the authorize_with
config method for where the initialization happens.
# File lib/rails_admin/extensions/cancan/authorization_adapter.rb, line 9 def initialize(controller, ability = ::Ability) @controller = controller @controller.instance_variable_set '@ability', ability @controller.extend ControllerExtension @controller.current_ability.authorize! :access, :rails_admin end
Public Instance Methods
attributes_for(action, abstract_model)
click to toggle source
This is called in the new/create actions to determine the initial attributes for new records. It should return a hash of attributes which match what the user is authorized to create.
# File lib/rails_admin/extensions/cancan/authorization_adapter.rb, line 43 def attributes_for(action, abstract_model) @controller.current_ability.attributes_for(action, abstract_model && abstract_model.model) end
query(action, abstract_model)
click to toggle source
This is called when needing to scope a database query. It is called within the list and bulk_delete/destroy actions and should return a scope which limits the records to those which the user can perform the given action on.
# File lib/rails_admin/extensions/cancan/authorization_adapter.rb, line 36 def query(action, abstract_model) abstract_model.model.accessible_by(@controller.current_ability, action) end