mdarby-restful_acl 2.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +1 -1
- data/lib/restful_acl_controller.rb +20 -2
- metadata +1 -1
data/README.textile
CHANGED
@@ -73,7 +73,7 @@ Define a parent resource (if one exists) by using the <b>my_mom</b> method, and
|
|
73
73
|
end
|
74
74
|
</pre>
|
75
75
|
|
76
|
-
|
76
|
+
h4. View Helpers
|
77
77
|
|
78
78
|
There are five view helpers also included in RESTful_ACL: #indexable, #creatable, #readable, #updatable, and #deletable. These enable you to do nifty things like:
|
79
79
|
<pre>
|
@@ -19,6 +19,7 @@ module RestfulAclController
|
|
19
19
|
object = klass.find(params[:id])
|
20
20
|
parent = object.get_mom rescue nil
|
21
21
|
else
|
22
|
+
# No object was requested, so we need to go to the URI to figure out the parent
|
22
23
|
object = nil
|
23
24
|
parent = get_parent_from_request_uri(klass) if klass.has_parent?
|
24
25
|
end
|
@@ -33,6 +34,9 @@ module RestfulAclController
|
|
33
34
|
else object.is_readable_by(current_user, parent)
|
34
35
|
end
|
35
36
|
|
37
|
+
rescue NoMethodError => e
|
38
|
+
# Misconfiguration: A RESTful_ACL specific method is missing.
|
39
|
+
raise_error(klass, e)
|
36
40
|
rescue
|
37
41
|
# Failsafe: If any funny business is going on, log and redirect
|
38
42
|
routing_error
|
@@ -41,6 +45,20 @@ module RestfulAclController
|
|
41
45
|
|
42
46
|
private
|
43
47
|
|
48
|
+
def get_method_from_error(error)
|
49
|
+
error.message.gsub('`', "'").split("'").at(1)
|
50
|
+
end
|
51
|
+
|
52
|
+
def raise_error(klass, error)
|
53
|
+
method = get_method_from_error(error)
|
54
|
+
message = (is_class_method?(method)) ? "#{klass}#self.#{method}" : "#{klass}##{method}"
|
55
|
+
raise NoMethodError, "[RESTful_ACL] #{message}(user, parent = nil) seems to be missing?"
|
56
|
+
end
|
57
|
+
|
58
|
+
def is_class_method?(method)
|
59
|
+
method =~ /(indexable|creatable)/
|
60
|
+
end
|
61
|
+
|
44
62
|
def get_parent_from_request_uri(child_klass)
|
45
63
|
parent_klass = child_klass.mom.to_s
|
46
64
|
bits = request.request_uri.split('/')
|
@@ -54,14 +72,14 @@ module RestfulAclController
|
|
54
72
|
end
|
55
73
|
|
56
74
|
def permission_denied
|
57
|
-
logger.info("[
|
75
|
+
logger.info("[RESTful_ACL] Permission denied to %s at %s for %s" %
|
58
76
|
[(logged_in? ? current_user.login : 'guest'), Time.now, request.request_uri])
|
59
77
|
|
60
78
|
redirect_to denied_url
|
61
79
|
end
|
62
80
|
|
63
81
|
def routing_error
|
64
|
-
logger.info("[
|
82
|
+
logger.info("[RESTful_ACL] Routing error by %s at %s for %s" %
|
65
83
|
[(logged_in? ? current_user.login : 'guest'), Time.now, request.request_uri])
|
66
84
|
|
67
85
|
redirect_to error_url
|