Module: Checken::Extensions::ActionController

Defined in:
lib/checken/extensions/action_controller.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/checken/extensions/action_controller.rb', line 5

def self.included(base)
  base.extend ClassMethods
  base.helper_method :granted_checken_permissions
  base.class_eval do
    private :checken_user_proxy
    private :restrict
    private :granted_checken_permissions
  end
end

Instance Method Details

#checken_user_proxyObject



15
16
17
18
# File 'lib/checken/extensions/action_controller.rb', line 15

def checken_user_proxy
  # Can be overriden to return the user proxy class which can be used
  # when performing permission checks using `restrict`.
end

#granted_checken_permissionsObject



34
35
36
# File 'lib/checken/extensions/action_controller.rb', line 34

def granted_checken_permissions
  @granted_checken_permissions ||= []
end

#restrict(permission_path, object = nil, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/checken/extensions/action_controller.rb', line 20

def restrict(permission_path, object = nil, options = {})
  if checken_user_proxy.nil?
    user = send(Checken.current_schema.config.current_user_method_name)
    user_proxy = Checken.current_schema.config.user_proxy_class.new(user)
  else
    user_proxy = checken_user_proxy
  end
  strict = options.delete(:strict) { true }
  granted_permissions = Checken.current_schema.check_permission!(permission_path, user_proxy, object, strict: strict)
  granted_permissions.each do |permission|
    granted_checken_permissions << permission
  end
end