Class: Authorization::ControllerPermission

Inherits:
Object
  • Object
show all
Defined in:
lib/declarative_authorization/in_controller.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actions, privilege, context, strong_params, attribute_check = false, load_object_model = nil, load_object_method = nil, filter_block = nil) ⇒ ControllerPermission

Returns a new instance of ControllerPermission.


638
639
640
641
642
643
644
645
646
647
648
649
# File 'lib/declarative_authorization/in_controller.rb', line 638

def initialize (actions, privilege, context, strong_params, attribute_check = false,
                load_object_model = nil, load_object_method = nil,
                filter_block = nil)
  @actions = actions.to_set
  @privilege = privilege
  @context = context
  @load_object_model = load_object_model
  @load_object_method = load_object_method
  @filter_block = filter_block
  @attribute_check = attribute_check
  @strong_params = strong_params
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions


637
638
639
# File 'lib/declarative_authorization/in_controller.rb', line 637

def actions
  @actions
end

#attribute_checkObject (readonly)

Returns the value of attribute attribute_check


637
638
639
# File 'lib/declarative_authorization/in_controller.rb', line 637

def attribute_check
  @attribute_check
end

#contextObject (readonly)

Returns the value of attribute context


637
638
639
# File 'lib/declarative_authorization/in_controller.rb', line 637

def context
  @context
end

#privilegeObject (readonly)

Returns the value of attribute privilege


637
638
639
# File 'lib/declarative_authorization/in_controller.rb', line 637

def privilege
  @privilege
end

#strong_paramsObject (readonly)

Returns the value of attribute strong_params


637
638
639
# File 'lib/declarative_authorization/in_controller.rb', line 637

def strong_params
  @strong_params
end

Instance Method Details

#matches?(action_name) ⇒ Boolean

Returns:

  • (Boolean)

651
652
653
# File 'lib/declarative_authorization/in_controller.rb', line 651

def matches? (action_name)
  @actions.include?(action_name.to_sym)
end

#permit!(contr) ⇒ Object


655
656
657
658
659
660
661
662
663
664
665
666
667
# File 'lib/declarative_authorization/in_controller.rb', line 655

def permit! (contr)
  if @filter_block
    return contr.instance_eval(&@filter_block)
  end
  object = @attribute_check ? load_object(contr) : nil
  privilege = @privilege || :"#{contr.action_name}"

  contr.authorization_engine.permit!(privilege, 
                                     :user => contr.send(:current_user),
                                     :object => object,
                                     :skip_attribute_test => !@attribute_check,
                                     :context => @context || contr.class.decl_auth_context)
end

#remove_actions(actions) ⇒ Object


669
670
671
672
# File 'lib/declarative_authorization/in_controller.rb', line 669

def remove_actions (actions)
  @actions -= actions
  self
end