Sha256: b4bb5c830118c1f43f3c1e6c03a116ff96f35c1e37b6b0a67efc811201831093

Contents?: true

Size: 879 Bytes

Versions: 31

Compression:

Stored size: 879 Bytes

Contents

# frozen_string_literal: true
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

31 entries across 31 versions & 1 rubygems

Version Path
activeadmin-4.0.0.beta14 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta13 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta12 lib/active_admin/cancan_adapter.rb
activeadmin-3.2.5 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta11 lib/active_admin/cancan_adapter.rb
activeadmin-3.2.4 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta10 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta9 lib/active_admin/cancan_adapter.rb
activeadmin-3.2.3 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta8 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta7 lib/active_admin/cancan_adapter.rb
activeadmin-3.2.2 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta6 lib/active_admin/cancan_adapter.rb
activeadmin-3.2.1 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta5 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta4 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta3 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta2 lib/active_admin/cancan_adapter.rb
activeadmin-4.0.0.beta1 lib/active_admin/cancan_adapter.rb
activeadmin-3.2.0 lib/active_admin/cancan_adapter.rb