10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/restful_acl_controller.rb', line 10
def has_permission?
return true if administrator?
begin
klass = self.controller_name.classify.constantize
if params[:id]
object = klass.find(params[:id])
parent = object.get_mom rescue nil
else
object = nil
parent = get_parent_from_request_uri(klass) if klass.has_parent?
end
permission_denied unless case params[:action]
when "index" then klass.is_indexable_by(current_user, parent)
when "new", "create" then klass.is_creatable_by(current_user, parent)
when "show" then object.is_readable_by(current_user, parent)
when "edit", "update" then object.is_updatable_by(current_user, parent)
when "destroy" then object.is_deletable_by(current_user, parent)
else check_non_restful_route(current_user, klass, object, parent)
end
rescue NoMethodError => e
raise_error(klass, e)
rescue
routing_error
end
end
|