128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'app/controllers/concerns/glib/auth/policy.rb', line 128
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
|