112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'app/controllers/concerns/glib/auth/policy.rb', line 112
def authorize_resource(*args)
options = args.
resource_name = args.first
self.before_action(options.slice(:only, :except, :if, :unless)) do |controller|
resource_name ||= resource_name_from_controller
begin
if !(resource_key = options[:class]).nil?
resource = case resource_key
when false
resource_name.to_sym
when Symbol, Class
resource_key
else
raise "Invalid resource class: #{resource_key}"
end
authorize resource
elsif (resource_instance = controller.instance_variable_get("@#{resource_name}"))
authorize resource_instance
else
authorize resource_name.camelize.constantize
end
rescue Pundit::NotAuthorizedError => e
raise_access_denied(e.record, e.policy)
end
verify_authorized
end
end
|