Sha256: 142dac569880f0342764c1b0cda948411c353db78618af7b30a20314fb2467b1

Contents?: true

Size: 849 Bytes

Versions: 63

Compression:

Stored size: 849 Bytes

Contents

unless ActiveAdmin::Dependency.cancan? || ActiveAdmin::Dependency.cancancan?
  ActiveAdmin::Dependency.cancan!
end

require 'cancan'

# Add a setting to the application to configure the ability
ActiveAdmin::Application.inheritable_setting :cancan_ability_class, "Ability"

module ActiveAdmin

  class CanCanAdapter < AuthorizationAdapter

    def authorized?(action, subject = nil)
      cancan_ability.can?(action, subject)
    end

    def cancan_ability
      @cancan_ability ||= initialize_cancan_ability
    end

    def scope_collection(collection, action = ActiveAdmin::Auth::READ)
      collection.accessible_by(cancan_ability, action)
    end

    private

    def initialize_cancan_ability
      klass = resource.namespace.cancan_ability_class
      klass = klass.constantize if klass.is_a? String
      klass.new user
    end

  end

end

Version data entries

63 entries across 63 versions & 6 rubygems

Version Path
activeadmin-rails-1.7.1 lib/active_admin/cancan_adapter.rb
activeadmin-rails-1.7.0 lib/active_admin/cancan_adapter.rb
activeadmin-rb-1.6.0 lib/active_admin/cancan_adapter.rb
activeadmin-rb-1.5.2 lib/active_admin/cancan_adapter.rb
activeadmin-2.8.0 lib/active_admin/cancan_adapter.rb
activeadmin-rb-1.5.1 lib/active_admin/cancan_adapter.rb
activeadmin-2.7.0 lib/active_admin/cancan_adapter.rb
activeadmin-2.6.1 lib/active_admin/cancan_adapter.rb
activeadmin-2.6.0 lib/active_admin/cancan_adapter.rb
activeadmin-2.5.0 lib/active_admin/cancan_adapter.rb
activeadmin-2.4.0 lib/active_admin/cancan_adapter.rb
activeadmin-2.3.1 lib/active_admin/cancan_adapter.rb
activeadmin-2.3.0 lib/active_admin/cancan_adapter.rb
activeadmin-2.2.0 lib/active_admin/cancan_adapter.rb
activeadmin-2.1.0 lib/active_admin/cancan_adapter.rb
activeadmin-2.0.0 lib/active_admin/cancan_adapter.rb
activeadmin-rb-1.5.0 lib/active_admin/cancan_adapter.rb
activeadmin-2.0.0.rc2 lib/active_admin/cancan_adapter.rb
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/cancan_adapter.rb
activeadmin-2.0.0.rc1 lib/active_admin/cancan_adapter.rb