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_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/cancan_adapter.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/cancan_adapter.rb
activeadmin-1.1.0 lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.15.pre lib/active_admin/cancan_adapter.rb
activeadmin-1.0.0 lib/active_admin/cancan_adapter.rb
activeadmin-1.0.0.pre5 lib/active_admin/cancan_adapter.rb
activeadmin-orac-1.0.0.pre4 lib/active_admin/cancan_adapter.rb
activeadmin-orac-1.0.0 lib/active_admin/cancan_adapter.rb
activeadmin-orac-1.0.0.pre.orac lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.14.pre lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.13.pre lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.12.pre lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.11.pre lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.10.pre lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.9.pre lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.8.pre lib/active_admin/cancan_adapter.rb
activeadmin-1.0.0.pre4 lib/active_admin/cancan_adapter.rb
activeadmin-1.0.0.pre3 lib/active_admin/cancan_adapter.rb
activeadmin-1.0.0.pre2 lib/active_admin/cancan_adapter.rb
activeadmin-1.0.0.pre1 lib/active_admin/cancan_adapter.rb