Sha256: 00533152b90e9cb7a1406a068dacdf38122e3dee6126c8a9e7e133654eae7483

Contents?: true

Size: 953 Bytes

Versions: 46

Compression:

Stored size: 953 Bytes

Contents

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)
      collection.accessible_by(cancan_ability)
    end

    private

    # The setting allows the class to be stored as a string
    # to enable reloading in development.
    def initialize_cancan_ability
      ability_class_name = resource.namespace.cancan_ability_class

      if ability_class_name.is_a?(String)
        ability_class = ActiveSupport::Dependencies.constantize(ability_class_name)
      else
        ability_class = ability_class_name
      end

      ability_class.new(user)
    end

  end

end

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
lalala-4.0.0.dev.141 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.128 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.126 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.125 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.124 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.123 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.118 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.116 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.114 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.113 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.111 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.109 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb
lalala-4.0.0.dev.107 vendor/deps/active_admin/lib/active_admin/cancan_adapter.rb