protector 0.7.6 → 0.7.7
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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -1
- data/lib/protector/adapters/active_record/base.rb +1 -1
- data/lib/protector/adapters/sequel/model.rb +1 -1
- data/lib/protector/dsl.rb +19 -1
- data/lib/protector/version.rb +1 -1
- data/locales/ru.yml +3 -0
- data/spec/spec_helpers/examples/model.rb +17 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 887a8a01b4826c0199726be2a4ec3375df624476
|
4
|
+
data.tar.gz: 240ab6a77289a4813f0e141d12f6dd4cb7f95fd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcec818537f70793185f37e1cf0ca1add42dc43d7de09cae213b899616f43c4516814a13fa96984e6bd1ca61f250393c06ee4b84ea5f420ea3cbf0182c331132
|
7
|
+
data.tar.gz: 2da8876bd0c678c98ab1e43903db81d47b85d3b86a5dedabe62a2bff83cd575da82828ee06d70239a47618ebd8fd8824f62c4d87a0936c2da05cf76124176421
|
data/.travis.yml
CHANGED
@@ -2,6 +2,11 @@ rvm:
|
|
2
2
|
- 1.9.3
|
3
3
|
- jruby-19mode
|
4
4
|
- 2.0.0
|
5
|
+
- 2.1.0
|
6
|
+
|
7
|
+
matrix:
|
8
|
+
allow_failures:
|
9
|
+
- gemfile: gemfiles/AR_edge.gemfile
|
5
10
|
|
6
11
|
gemfile:
|
7
12
|
- gemfiles/AR_3.2.gemfile
|
@@ -11,4 +16,4 @@ gemfile:
|
|
11
16
|
- gemfiles/Rails_4.gemfile
|
12
17
|
- gemfiles/Sequel.gemfile
|
13
18
|
|
14
|
-
script: bundle exec rspec
|
19
|
+
script: bundle exec rspec
|
@@ -58,7 +58,7 @@ module Protector
|
|
58
58
|
module ClassMethods
|
59
59
|
# Storage of {Protector::DSL::Meta}
|
60
60
|
def protector_meta
|
61
|
-
|
61
|
+
ensure_protector_meta!(Protector::Adapters::ActiveRecord) do
|
62
62
|
column_names
|
63
63
|
end
|
64
64
|
end
|
@@ -18,7 +18,7 @@ module Protector
|
|
18
18
|
module ClassMethods
|
19
19
|
# Storage of {Protector::DSL::Meta}
|
20
20
|
def protector_meta
|
21
|
-
|
21
|
+
ensure_protector_meta!(Protector::Adapters::Sequel) do
|
22
22
|
columns
|
23
23
|
end
|
24
24
|
end
|
data/lib/protector/dsl.rb
CHANGED
@@ -212,7 +212,7 @@ module Protector
|
|
212
212
|
|
213
213
|
fields.each do |k, v|
|
214
214
|
case x = @access[part][k]
|
215
|
-
when
|
215
|
+
when Enumerable
|
216
216
|
return k unless x.include?(v)
|
217
217
|
when Proc
|
218
218
|
return k unless Protector.insecurely{ x.call(v) }
|
@@ -257,11 +257,21 @@ module Protector
|
|
257
257
|
@blocks ||= []
|
258
258
|
end
|
259
259
|
|
260
|
+
def blocks=(blocks)
|
261
|
+
@blocks = blocks
|
262
|
+
end
|
263
|
+
|
260
264
|
# Register another protection block
|
261
265
|
def <<(block)
|
262
266
|
blocks << block
|
263
267
|
end
|
264
268
|
|
269
|
+
def inherit(model, &fields_proc)
|
270
|
+
clone = self.class.new(@adapter, model, &fields_proc)
|
271
|
+
clone.blocks = @blocks.clone unless @blocks.nil?
|
272
|
+
clone
|
273
|
+
end
|
274
|
+
|
265
275
|
# Calculate protection at the context of subject
|
266
276
|
#
|
267
277
|
# @param subject [Object] Restriction subject
|
@@ -317,6 +327,14 @@ module Protector
|
|
317
327
|
def protect(&block)
|
318
328
|
protector_meta << block
|
319
329
|
end
|
330
|
+
|
331
|
+
def ensure_protector_meta!(adapter, &column_names)
|
332
|
+
@protector_meta ||= if superclass && superclass.respond_to?(:protector_meta)
|
333
|
+
superclass.protector_meta.inherit(self, &column_names)
|
334
|
+
else
|
335
|
+
Protector::DSL::Meta.new(adapter, self, &column_names)
|
336
|
+
end
|
337
|
+
end
|
320
338
|
end
|
321
339
|
end
|
322
340
|
end
|
data/lib/protector/version.rb
CHANGED
data/locales/ru.yml
ADDED
@@ -21,6 +21,23 @@ shared_examples_for "a model" do
|
|
21
21
|
meta.access[:update].should == fields
|
22
22
|
end
|
23
23
|
|
24
|
+
it "respects inheritance" do
|
25
|
+
dummy.instance_eval do
|
26
|
+
protect do
|
27
|
+
can :read, :test
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
attempt = Class.new(dummy) do
|
32
|
+
protect do
|
33
|
+
can :create, :test
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
dummy.protector_meta.evaluate(nil, nil).access.should == {read: {"test"=>nil}}
|
38
|
+
attempt.protector_meta.evaluate(nil, nil).access.should == {read: {"test"=>nil}, create: {"test"=>nil}}
|
39
|
+
end
|
40
|
+
|
24
41
|
it "drops meta on restrict" do
|
25
42
|
d = Dummy.first
|
26
43
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boris Staal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/protector/engine.rb
|
82
82
|
- lib/protector/version.rb
|
83
83
|
- locales/en.yml
|
84
|
+
- locales/ru.yml
|
84
85
|
- migrations/active_record.rb
|
85
86
|
- migrations/sequel.rb
|
86
87
|
- perf/active_record_perf.rb
|
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
121
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.0.
|
122
|
+
rubygems_version: 2.0.14
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: 'Protector is a successor to the Heimdallr gem: it hits the same goals keeping
|