cuba-api 0.6.0 → 0.6.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/lib/cuba_api/guard.rb +20 -9
- data/lib/cuba_api/input_filter.rb +2 -1
- data/lib/cuba_api/utils.rb +4 -1
- metadata +2 -2
data/lib/cuba_api/guard.rb
CHANGED
@@ -49,27 +49,30 @@ module CubaApi
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def allowed_associations
|
52
|
-
guard.associations(
|
52
|
+
guard.associations( guard_context, @_method )
|
53
53
|
end
|
54
54
|
|
55
55
|
def on_context( name, &block )
|
56
56
|
perm = guard.permissions( name )
|
57
57
|
if perm && perm.parent &&
|
58
|
-
perm.parent.resource !=
|
58
|
+
perm.parent.resource != guard_context
|
59
59
|
raise 'parent resource is not guarded'
|
60
60
|
end
|
61
61
|
on name do
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
begin
|
63
|
+
old = guard_context
|
64
|
+
guard_context( name )
|
65
|
+
yield( *captures )
|
66
|
+
ensure
|
67
|
+
guard_context( old )
|
68
|
+
end
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
69
72
|
def on_association
|
70
73
|
on :association do |association|
|
71
74
|
# TODO one method in guard
|
72
|
-
asso = guard.permissions(
|
75
|
+
asso = guard.permissions( guard_context ).associations
|
73
76
|
if asso.empty? or asso.include?( association )
|
74
77
|
yield( association )
|
75
78
|
else
|
@@ -84,9 +87,9 @@ module CubaApi
|
|
84
87
|
|
85
88
|
@_method = method
|
86
89
|
|
87
|
-
warn "[CubaApi::Guard] check #{method.to_s.upcase} #{
|
90
|
+
warn "[CubaApi::Guard] check #{method.to_s.upcase} #{guard_context}: #{guard.allow?( guard_context, method )}"
|
88
91
|
# TODO guard needs no association here
|
89
|
-
if guard.allow?(
|
92
|
+
if guard.allow?( guard_context, method, (allowed_associations || []).first )
|
90
93
|
|
91
94
|
yield( *captures )
|
92
95
|
else
|
@@ -97,6 +100,14 @@ module CubaApi
|
|
97
100
|
|
98
101
|
private
|
99
102
|
|
103
|
+
def guard_context( ctx = nil )
|
104
|
+
if ctx
|
105
|
+
@_conetxt = (req.env[ 'guard_context' ] = ctx)
|
106
|
+
else
|
107
|
+
@_context ||= req.env[ 'guard_context' ]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
100
111
|
def guard
|
101
112
|
self.class.guard.call( current_groups )
|
102
113
|
end
|
data/lib/cuba_api/utils.rb
CHANGED
@@ -58,7 +58,10 @@ module CubaApi
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def last_modified( last )
|
61
|
-
|
61
|
+
if last
|
62
|
+
res[ 'Last-Modified' ] = rfc2616( last )
|
63
|
+
res[ 'Cache-Control' ] = "private, max-age=0, must-revalidate"
|
64
|
+
end
|
62
65
|
end
|
63
66
|
|
64
67
|
def modified_since
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cuba
|