Sha256: eaca3c8edf4d7f843cce28cb7ecbd479141e714845822809e1bee682e220b89c

Contents?: true

Size: 995 Bytes

Versions: 17

Compression:

Stored size: 995 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, action = ActiveAdmin::Auth::READ)
      collection.accessible_by(cancan_ability, action)
    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

17 entries across 17 versions & 5 rubygems

Version Path
activeadmin-0.6.6 lib/active_admin/cancan_adapter.rb
activeadmin-0.6.5 lib/active_admin/cancan_adapter.rb
activeadmin-0.6.4 lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.4.pre lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.3.pre lib/active_admin/cancan_adapter.rb
active_administration-0.0.3 lib/active_admin/cancan_adapter.rb
activeadministration-0.0.2 lib/active_admin/cancan_adapter.rb
active_administration-0.0.2 lib/active_admin/cancan_adapter.rb
activeadministration-0.0.1 lib/active_admin/cancan_adapter.rb
active_administration-0.0.1 lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.2.pre lib/active_admin/cancan_adapter.rb
activeadmin-0.6.3 lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.1.pre lib/active_admin/cancan_adapter.rb
yousty-activeadmin-1.0.0.pre lib/active_admin/cancan_adapter.rb
activeadmin-0.6.2 lib/active_admin/cancan_adapter.rb
activeadmin-0.6.1 lib/active_admin/cancan_adapter.rb
aa-rails4-0.6.0 lib/active_admin/cancan_adapter.rb