Module: ActiveScaffold::Bridges::Cancan::ActiveRecord::SecurityMethods

Defined in:
lib/active_scaffold/bridges/cancan/cancan_bridge.rb

Defined Under Namespace

Classes: InvalidArgument

Instance Method Summary collapse

Instance Method Details

#authorized_for_with_cancan?(options = {}) ⇒ Boolean

is usually called with :crud_type and :column, or :action

{:crud_type=>:update, :column=>"some_colum_name"}
{:action=>"edit"}

to allow access cancan must allow both :crud_type and :action if cancan says “no”, it delegates to default AS behavior

Returns:

  • (Boolean)

Raises:



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/active_scaffold/bridges/cancan/cancan_bridge.rb', line 122

def authorized_for_with_cancan?(options = {})
  raise InvalidArgument if options[:crud_type].blank? && options[:action].blank?
  if current_ability.present?
    crud_type_result = options[:crud_type].nil? ? true : current_ability.can?(options[:crud_type], self)
    action_result = options[:action].nil? ? true : current_ability.can?(options[:action].to_sym, self)
  else
    crud_type_result, action_result = false, false
  end
  default_result = authorized_for_without_cancan?(options)
  (crud_type_result && action_result) || default_result
end