heimdallr 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +18 -16
- data/README.md +10 -20
- data/heimdallr.gemspec +1 -1
- data/lib/heimdallr/proxy/collection.rb +14 -8
- data/lib/heimdallr/proxy/record.rb +14 -8
- metadata +10 -10
data/LICENSE
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License
|
2
2
|
|
3
|
-
|
4
|
-
this software and associated documentation files (the "Software"), to deal in
|
5
|
-
the Software without restriction, including without limitation the rights to
|
6
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
-
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
-
so, subject to the following conditions:
|
3
|
+
Copyright (c) 2012 Round Lake, inc.
|
9
4
|
|
10
|
-
|
11
|
-
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -32,6 +32,7 @@ class Article < ActiveRecord::Base
|
|
32
32
|
if record.try(:owner) == user
|
33
33
|
can :view
|
34
34
|
can :update, {
|
35
|
+
# each field may have validators that will allow update
|
35
36
|
secrecy_level: { inclusion: { in: 0..4 } }
|
36
37
|
}
|
37
38
|
else
|
@@ -42,6 +43,7 @@ class Article < ActiveRecord::Base
|
|
42
43
|
# ... and can create them with certain restrictions.
|
43
44
|
can :create, %w(content)
|
44
45
|
can :create, {
|
46
|
+
# each field may have fixed value that cannot be overridden
|
45
47
|
owner_id: user.id,
|
46
48
|
secrecy_level: { inclusion: { in: 0..4 } }
|
47
49
|
}
|
@@ -121,27 +123,15 @@ Compatibility
|
|
121
123
|
|
122
124
|
Ruby 1.8 and ActiveRecord versions prior to 3.0 are not supported.
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
+
Credits
|
127
|
+
-------
|
126
128
|
|
127
|
-
|
129
|
+
<img src="http://roundlake.ru/assets/logo.png" align="right" />
|
128
130
|
|
129
|
-
|
131
|
+
* Peter Zotov ([@whitequark](http://twitter.com/#!/whitequark))
|
132
|
+
* Boris Staal ([@_inossidabile](http://twitter.com/#!/_inossidabile))
|
130
133
|
|
131
|
-
|
132
|
-
|
133
|
-
the Software without restriction, including without limitation the rights to
|
134
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
135
|
-
of the Software, and to permit persons to whom the Software is furnished to do
|
136
|
-
so, subject to the following conditions:
|
134
|
+
LICENSE
|
135
|
+
-------
|
137
136
|
|
138
|
-
|
139
|
-
copies or substantial portions of the Software.
|
140
|
-
|
141
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
142
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
143
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
144
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
145
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
146
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
147
|
-
SOFTWARE.
|
137
|
+
It is free software, and may be redistributed under the terms of MIT license.
|
data/heimdallr.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "heimdallr"
|
6
|
-
s.version = "1.0.
|
6
|
+
s.version = "1.0.2"
|
7
7
|
s.authors = ["Peter Zotov", "Boris Staal"]
|
8
8
|
s.email = ["whitequark@whitequark.org", "boris@roundlake.ru"]
|
9
9
|
s.homepage = "http://github.com/roundlake/heimdallr"
|
@@ -21,11 +21,16 @@ module Heimdallr
|
|
21
21
|
@restrictions = @scope.restrictions(context)
|
22
22
|
end
|
23
23
|
|
24
|
-
# Collections cannot be restricted
|
24
|
+
# Collections cannot be restricted with different context or options.
|
25
25
|
#
|
26
|
+
# @return self
|
26
27
|
# @raise [RuntimeError]
|
27
|
-
def restrict(
|
28
|
-
|
28
|
+
def restrict(context, options=nil)
|
29
|
+
if @context == context && options.nil?
|
30
|
+
self
|
31
|
+
else
|
32
|
+
raise RuntimeError, "Heimdallr proxies cannot be restricted with nonmatching context or options"
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
# @private
|
@@ -208,7 +213,7 @@ module Heimdallr
|
|
208
213
|
|
209
214
|
# Return the associated security metadata. The returned hash will contain keys
|
210
215
|
# +:context+, +:scope+ and +:options+, corresponding to the parameters in
|
211
|
-
# {#initialize}, and +:
|
216
|
+
# {#initialize}, +:model+ and +:restrictions+, representing the model class.
|
212
217
|
#
|
213
218
|
# Such a name was deliberately selected for this method in order to reduce namespace
|
214
219
|
# pollution.
|
@@ -216,10 +221,11 @@ module Heimdallr
|
|
216
221
|
# @return [Hash]
|
217
222
|
def reflect_on_security
|
218
223
|
{
|
219
|
-
model:
|
220
|
-
context:
|
221
|
-
scope:
|
222
|
-
options:
|
224
|
+
model: @scope,
|
225
|
+
context: @context,
|
226
|
+
scope: @scope,
|
227
|
+
options: @options,
|
228
|
+
restrictions: @restrictions,
|
223
229
|
}.merge(@restrictions.reflection)
|
224
230
|
end
|
225
231
|
|
@@ -140,11 +140,16 @@ module Heimdallr
|
|
140
140
|
@record.class.name
|
141
141
|
end
|
142
142
|
|
143
|
-
# Records cannot be restricted
|
143
|
+
# Records cannot be restricted with different context or options.
|
144
144
|
#
|
145
|
+
# @return self
|
145
146
|
# @raise [RuntimeError]
|
146
|
-
def restrict(context)
|
147
|
-
|
147
|
+
def restrict(context, options=nil)
|
148
|
+
if @context == context && options.nil?
|
149
|
+
self
|
150
|
+
else
|
151
|
+
raise RuntimeError, "Heimdallr proxies cannot be restricted with nonmatching context or options"
|
152
|
+
end
|
148
153
|
end
|
149
154
|
|
150
155
|
# A whitelisting dispatcher for attribute-related method calls.
|
@@ -237,7 +242,7 @@ module Heimdallr
|
|
237
242
|
|
238
243
|
# Return the associated security metadata. The returned hash will contain keys
|
239
244
|
# +:context+, +:record+, +:options+, corresponding to the parameters in
|
240
|
-
# {#initialize}, and +:
|
245
|
+
# {#initialize}, +:model+ and +:restrictions+, representing the model class.
|
241
246
|
#
|
242
247
|
# Such a name was deliberately selected for this method in order to reduce namespace
|
243
248
|
# pollution.
|
@@ -245,10 +250,11 @@ module Heimdallr
|
|
245
250
|
# @return [Hash]
|
246
251
|
def reflect_on_security
|
247
252
|
{
|
248
|
-
model:
|
249
|
-
context:
|
250
|
-
record:
|
251
|
-
options:
|
253
|
+
model: @record.class,
|
254
|
+
context: @context,
|
255
|
+
record: @record,
|
256
|
+
options: @options,
|
257
|
+
restrictions: @restrictions,
|
252
258
|
}.merge(@restrictions.reflection)
|
253
259
|
end
|
254
260
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heimdallr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-04-
|
13
|
+
date: 2012-04-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
17
|
-
requirement: &
|
17
|
+
requirement: &70206639185180 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 3.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70206639185180
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activemodel
|
28
|
-
requirement: &
|
28
|
+
requirement: &70206639184300 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 3.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70206639184300
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70206639183840 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70206639183840
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: activerecord
|
50
|
-
requirement: &
|
50
|
+
requirement: &70206639183200 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70206639183200
|
59
59
|
description: ! "Heimdallr aims to provide an easy to configure and efficient object-
|
60
60
|
and field-level access\n control solution, reusing proven patterns from gems like
|
61
61
|
CanCan and allowing one to manage permissions in a very\n fine-grained manner."
|