Class: Authorization::ControllerPermission

Inherits:
Object
  • Object
show all
Defined in:
lib/declarative_authorization/controller_permission.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.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/declarative_authorization/controller_permission.rb', line 4

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.



3
4
5
# File 'lib/declarative_authorization/controller_permission.rb', line 3

def actions
  @actions
end

#attribute_checkObject (readonly)

Returns the value of attribute attribute_check.



3
4
5
# File 'lib/declarative_authorization/controller_permission.rb', line 3

def attribute_check
  @attribute_check
end

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/declarative_authorization/controller_permission.rb', line 3

def context
  @context
end

#privilegeObject (readonly)

Returns the value of attribute privilege.



3
4
5
# File 'lib/declarative_authorization/controller_permission.rb', line 3

def privilege
  @privilege
end

#strong_paramsObject (readonly)

Returns the value of attribute strong_params.



3
4
5
# File 'lib/declarative_authorization/controller_permission.rb', line 3

def strong_params
  @strong_params
end

Instance Method Details

#matches?(action_name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/declarative_authorization/controller_permission.rb', line 17

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

#permit!(contr, action_name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/declarative_authorization/controller_permission.rb', line 21

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

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

#remove_actions(actions) ⇒ Object



36
37
38
39
# File 'lib/declarative_authorization/controller_permission.rb', line 36

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