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, attribute_check = false, load_object_model = nil, load_object_method = nil, filter_block = nil) ⇒ ControllerPermission

Returns a new instance of ControllerPermission.



561
562
563
564
565
566
567
568
569
570
571
# File 'lib/declarative_authorization/in_controller.rb', line 561

def initialize (actions, privilege, context, 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
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



560
561
562
# File 'lib/declarative_authorization/in_controller.rb', line 560

def actions
  @actions
end

#attribute_checkObject (readonly)

Returns the value of attribute attribute_check.



560
561
562
# File 'lib/declarative_authorization/in_controller.rb', line 560

def attribute_check
  @attribute_check
end

#contextObject (readonly)

Returns the value of attribute context.



560
561
562
# File 'lib/declarative_authorization/in_controller.rb', line 560

def context
  @context
end

#privilegeObject (readonly)

Returns the value of attribute privilege.



560
561
562
# File 'lib/declarative_authorization/in_controller.rb', line 560

def privilege
  @privilege
end

Instance Method Details

#matches?(action_name) ⇒ Boolean

Returns:

  • (Boolean)


573
574
575
# File 'lib/declarative_authorization/in_controller.rb', line 573

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

#permit!(contr) ⇒ Object



577
578
579
580
581
582
583
584
585
586
587
588
589
# File 'lib/declarative_authorization/in_controller.rb', line 577

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



591
592
593
594
# File 'lib/declarative_authorization/in_controller.rb', line 591

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