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