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.



502
503
504
505
506
507
508
509
510
511
512
# File 'lib/declarative_authorization/in_controller.rb', line 502

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.



501
502
503
# File 'lib/declarative_authorization/in_controller.rb', line 501

def actions
  @actions
end

#attribute_checkObject (readonly)

Returns the value of attribute attribute_check.



501
502
503
# File 'lib/declarative_authorization/in_controller.rb', line 501

def attribute_check
  @attribute_check
end

#contextObject (readonly)

Returns the value of attribute context.



501
502
503
# File 'lib/declarative_authorization/in_controller.rb', line 501

def context
  @context
end

#privilegeObject (readonly)

Returns the value of attribute privilege.



501
502
503
# File 'lib/declarative_authorization/in_controller.rb', line 501

def privilege
  @privilege
end

Instance Method Details

#matches?(action_name) ⇒ Boolean

Returns:

  • (Boolean)


514
515
516
# File 'lib/declarative_authorization/in_controller.rb', line 514

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

#permit!(contr) ⇒ Object



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/declarative_authorization/in_controller.rb', line 518

def permit! (contr)
  if @filter_block
    return contr.instance_eval(&@filter_block)
  end
  context = @context || contr.class.controller_name.to_sym
  object = @attribute_check ? load_object(contr, context) : nil
  privilege = @privilege || :"#{contr.action_name}"
  
  #puts "Trying permit?(#{privilege.inspect}, "
  #puts "               :user => #{contr.send(:current_user).inspect}, "
  #puts "               :object => #{object.inspect}," 
  #puts "               :skip_attribute_test => #{!@attribute_check}," 
  #puts "               :context => #{contr.class.controller_name.pluralize.to_sym})"
  res = contr.authorization_engine.permit!(privilege, 
                                     :user => contr.send(:current_user),
                                     :object => object,
                                     :skip_attribute_test => !@attribute_check,
                                     :context => context)
  #puts "permit? result: #{res.inspect}"
  res
end

#remove_actions(actions) ⇒ Object



540
541
542
543
# File 'lib/declarative_authorization/in_controller.rb', line 540

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