Class: Portier::ApplicationPermission
Overview
************************************************************************************* Control the access for each controller actions *************************************************************************************
Instance Attribute Summary
#access_denied_message, #application_controller, #current_user
Class Method Summary
collapse
Instance Method Summary
collapse
#initialize, #set_access_denied_message
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'lib/portier/application_permission.rb', line 84
def method_missing(*args, &block)
if args.first == record_name and model_exists?
current_record
elsif current_record.class.to_s.downcase == args.first.to_s
current_record
else
raise NoMethodError.new("undefined local variable or method '#{args.first}' for #{self.class}")
end
end
|
Class Method Details
.action_tree(action) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/portier/application_permission.rb', line 5
def self.action_tree(action)
case action.to_s
when 'index' then [:index, :consult, :default]
when 'show' then [:show, :consult, :default]
when 'new' then [:new, :add, :default]
when 'create' then [:create, :add, :default]
when 'edit' then [:edit, :modify, :default]
when 'update' then [:update, :modify, :default]
when 'destroy' then [:destroy, :default]
else [action.to_sym, :default]
end
end
|
Instance Method Details
#build_permitted_params ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/portier/application_permission.rb', line 19
def build_permitted_params
ps = self.respond_to?(:permitted_params) ? permitted_params : []
begin
params.require(record_name).permit ps
rescue
{}
end
end
|
#can?(action, record, options = {}) ⇒ Boolean
29
30
31
32
33
34
|
# File 'lib/portier/application_permission.rb', line 29
def can?(action, record, options={})
@current_record = record
@options = options
granted? action
end
|
#default ⇒ Object
36
37
38
|
# File 'lib/portier/application_permission.rb', line 36
def default
false
end
|
#granted?(action) ⇒ Boolean
40
41
42
|
# File 'lib/portier/application_permission.rb', line 40
def granted?(action)
action_tree(action).each { |act| return self.send(act) if self.respond_to?(act) }
end
|