Class: Authorization::ControllerPermission
- Inherits:
-
Object
- Object
- Authorization::ControllerPermission
- Defined in:
- lib/declarative_authorization/in_controller.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#attribute_check ⇒ Object
readonly
Returns the value of attribute attribute_check.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#privilege ⇒ Object
readonly
Returns the value of attribute privilege.
Instance Method Summary collapse
- #controller_context(contr) ⇒ Object
-
#initialize(actions, privilege, context, namespace, attribute_check = false, load_object_model = nil, load_object_method = nil, filter_block = nil) ⇒ ControllerPermission
constructor
A new instance of ControllerPermission.
- #matches?(action_name) ⇒ Boolean
- #permit!(contr) ⇒ Object
- #remove_actions(actions) ⇒ Object
Constructor Details
#initialize(actions, privilege, context, namespace, attribute_check = false, load_object_model = nil, load_object_method = nil, filter_block = nil) ⇒ ControllerPermission
Returns a new instance of ControllerPermission.
538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/declarative_authorization/in_controller.rb', line 538 def initialize (actions, privilege, context, namespace, attribute_check = false, load_object_model = nil, load_object_method = nil, filter_block = nil) @actions = actions.to_set @privilege = privilege @context = context @namespace = namespace @load_object_model = load_object_model @load_object_method = load_object_method @filter_block = filter_block @attribute_check = attribute_check end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
537 538 539 |
# File 'lib/declarative_authorization/in_controller.rb', line 537 def actions @actions end |
#attribute_check ⇒ Object (readonly)
Returns the value of attribute attribute_check.
537 538 539 |
# File 'lib/declarative_authorization/in_controller.rb', line 537 def attribute_check @attribute_check end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
537 538 539 |
# File 'lib/declarative_authorization/in_controller.rb', line 537 def context @context end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
537 538 539 |
# File 'lib/declarative_authorization/in_controller.rb', line 537 def namespace @namespace end |
#privilege ⇒ Object (readonly)
Returns the value of attribute privilege.
537 538 539 |
# File 'lib/declarative_authorization/in_controller.rb', line 537 def privilege @privilege end |
Instance Method Details
#controller_context(contr) ⇒ Object
551 552 553 554 555 556 557 558 559 560 |
# File 'lib/declarative_authorization/in_controller.rb', line 551 def controller_context(contr) case @namespace when true "#{contr.class.name.gsub(/::/, "_").gsub(/Controller$/, "").underscore}".to_sym when String, Symbol "#{@namespace.to_s}_#{contr.class.controller_name}".to_sym else contr.class.controller_name.to_sym end end |
#matches?(action_name) ⇒ Boolean
562 563 564 |
# File 'lib/declarative_authorization/in_controller.rb', line 562 def matches? (action_name) @actions.include?(action_name.to_sym) end |
#permit!(contr) ⇒ Object
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
# File 'lib/declarative_authorization/in_controller.rb', line 566 def permit! (contr) if @filter_block return contr.instance_eval(&@filter_block) end context = @context || controller_context(contr) 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..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
588 589 590 591 |
# File 'lib/declarative_authorization/in_controller.rb', line 588 def remove_actions (actions) @actions -= actions self end |