protector 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +8 -0
- data/Gemfile +5 -1
- data/README.md +16 -7
- data/gemfiles/AR_3.2.gemfile +3 -1
- data/gemfiles/AR_3.2.gemfile.lock +33 -2
- data/gemfiles/AR_4.gemfile +3 -1
- data/gemfiles/AR_4.gemfile.lock +18 -1
- data/gemfiles/Mongoid.gemfile +17 -0
- data/gemfiles/Mongoid.gemfile.lock +112 -0
- data/gemfiles/Sequel.gemfile +18 -0
- data/gemfiles/Sequel.gemfile.lock +103 -0
- data/lib/protector/adapters/active_record/base.rb +15 -17
- data/lib/protector/adapters/active_record/relation.rb +20 -61
- data/lib/protector/adapters/sequel/dataset.rb +66 -0
- data/lib/protector/adapters/sequel/eager_graph_loader.rb +24 -0
- data/lib/protector/adapters/sequel/model.rb +99 -0
- data/lib/protector/adapters/sequel.rb +17 -0
- data/lib/protector/dsl.rb +5 -2
- data/lib/protector/version.rb +1 -1
- data/lib/protector.rb +3 -1
- data/migrations/active_record.rb +0 -1
- data/migrations/sequel.rb +49 -0
- data/perf/{active_record.rb → active_record_perf.rb} +2 -0
- data/perf/perf_helpers/boot.rb +20 -2
- data/perf/sequel_perf.rb +84 -0
- data/spec/lib/adapters/active_record_spec.rb +17 -4
- data/spec/lib/adapters/sequel_spec.rb +156 -0
- data/spec/spec_helpers/adapters/active_record.rb +34 -0
- data/spec/spec_helpers/adapters/sequel.rb +64 -0
- data/spec/spec_helpers/boot.rb +3 -13
- data/spec/spec_helpers/examples/model.rb +20 -20
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75c42dc51baa287fb4d302415f78e383687b88b0
|
4
|
+
data.tar.gz: e11a06fc1a46d40deeb04c36295e5efce4795bbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5c613251c76af90245f55031a26711a193f84474e86d68f352b2afb1d9afb3fd9c77a92faaa396816f00dcf0a579a548fc242766920e600318dd73a1d0e87f0
|
7
|
+
data.tar.gz: 14f326b243705cdfd75bf132b42c04a8d9e06db85ee6ffa69d9e955251cabe936da2d99a4ecafdd7fe6beb99e01512a84b4e705e7b80e49f1dc242a0017633e8
|
data/Appraisals
CHANGED
@@ -7,3 +7,11 @@ appraise "AR_4" do
|
|
7
7
|
gem "activerecord", "4.0.0.rc1", require: "active_record"
|
8
8
|
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby, github: "jruby/activerecord-jdbc-adapter"
|
9
9
|
end
|
10
|
+
|
11
|
+
appraise "Sequel" do
|
12
|
+
gem "sequel", "3.30.0"
|
13
|
+
end
|
14
|
+
|
15
|
+
# appraise "Mongoid" do
|
16
|
+
# gem "mongoid", ">= 3.1.4"
|
17
|
+
# end
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
# Protector
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/protector.png)](http://badge.fury.io/rb/protector)
|
3
4
|
[![Build Status](https://travis-ci.org/inossidabile/protector.png?branch=master)](https://travis-ci.org/inossidabile/protector)
|
4
5
|
[![Code Climate](https://codeclimate.com/github/inossidabile/protector.png)](https://codeclimate.com/github/inossidabile/protector)
|
6
|
+
<!-- [![Coverage Status](https://coveralls.io/repos/inossidabile/protector/badge.png?branch=master)](https://coveralls.io/r/inossidabile/protector?branch=master) -->
|
5
7
|
|
6
8
|
Protector is a Ruby ORM extension for managing security restrictions on a field level. The gem favors white-listing over black-listing (everything is disallowed by default), convention over configuration and is duck-type compatible with most of existing code.
|
7
9
|
|
8
10
|
Currently Protector supports the following ORM adapters:
|
9
11
|
|
10
12
|
* [ActiveRecord](http://guides.rubyonrails.org/active_record_querying.html) (>= 3.2.9)
|
13
|
+
* [Sequel](http://sequel.rubyforge.org/) (>= 3.30.0)
|
11
14
|
|
12
15
|
We are working hard to extend the list with:
|
13
16
|
|
14
|
-
* [Sequel](http://sequel.rubyforge.org/)
|
15
|
-
* [DataMapper](http://datamapper.org/)
|
16
17
|
* [Mongoid](http://mongoid.org/en/mongoid/index.html)
|
18
|
+
* [ROM](https://github.com/rom-rb/rom)
|
19
|
+
* [DataMapper](http://datamapper.org/) (its undead so it might be skipped)
|
17
20
|
|
18
21
|
## Basics
|
19
22
|
|
@@ -115,7 +118,7 @@ Remember however that auto-restriction is only enabled for reading. Passing a mo
|
|
115
118
|
|
116
119
|
## Eager Loading
|
117
120
|
|
118
|
-
To take a long story short: it works and you are very likely to never notice changes it introduces to the process.
|
121
|
+
To take a long story short: it works and you are very likely to never notice changes it introduces to the process. But it might behave unexpected (yet mathematically correct) in complex cases.
|
119
122
|
|
120
123
|
Eager Loading has 2 possible strategies: JOINs and additional requests. Whenever you mark an association to preload and at the same time use this relation among `where` clause – ORMs prefer JOIN. Otherwise it goes with additional requests.
|
121
124
|
|
@@ -124,15 +127,21 @@ Foo.includes(:bars) # This will make 2 queries
|
|
124
127
|
Foo.includes(:bars).where(bars: {absolute: true}) # This will make 1 big JOINfull query
|
125
128
|
```
|
126
129
|
|
127
|
-
The problem here is that JOIN strategy
|
130
|
+
The problem here is that JOIN strategy makes restriction scopes overlap. With the following query:
|
128
131
|
|
129
132
|
```ruby
|
130
|
-
Foo.restrict(current_user).includes(:bars).where(bars: {absolute: true})
|
133
|
+
Foo.restrict!(current_user).includes(:bars).where(bars: {absolute: true})
|
131
134
|
```
|
132
135
|
|
133
|
-
we can appear in the situation where `foos` and `bars` relations are having different restrictions scopes. In this case JOIN
|
136
|
+
we can appear in the situation where `foos` and `bars` relations are having different restrictions scopes. In this case JOIN will filter by an intersection of scopes which is important to understand. You might not get all `Foo` entries you expect with such where clause since they might appear filtered out by the restriction scope of `Bar`.
|
134
137
|
|
135
|
-
|
138
|
+
If you don't want `Bar` scope to affect `Foo` selection, you can modify the query as follows:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
Foo.restrict!(current_user).preload(:bars).join(:bars).where(bars: {absolute: true})
|
142
|
+
```
|
143
|
+
|
144
|
+
Such chain will force the usage of an additional request so the first query will not be scoped with `Bar` restriction.
|
136
145
|
|
137
146
|
## Ideology
|
138
147
|
|
data/gemfiles/AR_3.2.gemfile
CHANGED
@@ -10,7 +10,9 @@ gem "guard"
|
|
10
10
|
gem "guard-rspec"
|
11
11
|
gem "appraisal"
|
12
12
|
gem "sqlite3", :platform=>:ruby
|
13
|
-
gem "jdbc-sqlite3", :platform=>:jruby
|
13
|
+
gem "jdbc-sqlite3", :platform=>:jruby, :require=>"jdbc/sqlite3"
|
14
|
+
gem "coveralls", :require=>false
|
15
|
+
gem "ruby-prof", :platform=>:ruby
|
14
16
|
gem "activerecord", "3.2.9", :require=>"active_record"
|
15
17
|
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby, :github=>"jruby/activerecord-jdbc-adapter"
|
16
18
|
|
@@ -1,12 +1,16 @@
|
|
1
1
|
GIT
|
2
2
|
remote: git://github.com/jruby/activerecord-jdbc-adapter.git
|
3
|
-
revision:
|
3
|
+
revision: a77ac76d2adda35d01aa9d66cafa324b2953e5ea
|
4
4
|
specs:
|
5
|
+
activerecord-jdbc-adapter (1.3.0.beta2)
|
6
|
+
activerecord-jdbcsqlite3-adapter (1.3.0.beta2)
|
7
|
+
activerecord-jdbc-adapter (~> 1.3.0.beta2)
|
8
|
+
jdbc-sqlite3 (~> 3.7.2)
|
5
9
|
|
6
10
|
PATH
|
7
11
|
remote: /Users/inossidabile/Repos/protector
|
8
12
|
specs:
|
9
|
-
protector (0.1
|
13
|
+
protector (0.2.1)
|
10
14
|
activesupport
|
11
15
|
i18n
|
12
16
|
|
@@ -31,8 +35,16 @@ GEM
|
|
31
35
|
builder (3.0.4)
|
32
36
|
coderay (1.0.9)
|
33
37
|
colored (1.2)
|
38
|
+
colorize (0.5.8)
|
39
|
+
coveralls (0.6.7)
|
40
|
+
colorize
|
41
|
+
multi_json (~> 1.3)
|
42
|
+
rest-client
|
43
|
+
simplecov (>= 0.7)
|
44
|
+
thor
|
34
45
|
diff-lcs (1.2.4)
|
35
46
|
ffi (1.8.1)
|
47
|
+
ffi (1.8.1-java)
|
36
48
|
formatador (0.2.4)
|
37
49
|
guard (1.8.0)
|
38
50
|
formatador (>= 0.2.4)
|
@@ -44,23 +56,32 @@ GEM
|
|
44
56
|
guard (>= 1.8)
|
45
57
|
rspec (~> 2.13)
|
46
58
|
i18n (0.6.4)
|
59
|
+
jdbc-sqlite3 (3.7.2)
|
47
60
|
listen (1.1.3)
|
48
61
|
rb-fsevent (>= 0.9.3)
|
49
62
|
rb-inotify (>= 0.9)
|
50
63
|
rb-kqueue (>= 0.2)
|
51
64
|
lumberjack (1.0.3)
|
52
65
|
method_source (0.8.1)
|
66
|
+
mime-types (1.23)
|
53
67
|
multi_json (1.7.4)
|
54
68
|
pry (0.9.12.2)
|
55
69
|
coderay (~> 1.0.5)
|
56
70
|
method_source (~> 0.8)
|
57
71
|
slop (~> 3.4)
|
72
|
+
pry (0.9.12.2-java)
|
73
|
+
coderay (~> 1.0.5)
|
74
|
+
method_source (~> 0.8)
|
75
|
+
slop (~> 3.4)
|
76
|
+
spoon (~> 0.0)
|
58
77
|
rake (10.0.4)
|
59
78
|
rb-fsevent (0.9.3)
|
60
79
|
rb-inotify (0.9.0)
|
61
80
|
ffi (>= 0.5.0)
|
62
81
|
rb-kqueue (0.2.0)
|
63
82
|
ffi (>= 0.5.0)
|
83
|
+
rest-client (1.6.7)
|
84
|
+
mime-types (>= 1.16)
|
64
85
|
rspec (2.13.0)
|
65
86
|
rspec-core (~> 2.13.0)
|
66
87
|
rspec-expectations (~> 2.13.0)
|
@@ -69,12 +90,20 @@ GEM
|
|
69
90
|
rspec-expectations (2.13.0)
|
70
91
|
diff-lcs (>= 1.1.3, < 2.0)
|
71
92
|
rspec-mocks (2.13.1)
|
93
|
+
ruby-prof (0.13.0)
|
94
|
+
simplecov (0.7.1)
|
95
|
+
multi_json (~> 1.0)
|
96
|
+
simplecov-html (~> 0.7.1)
|
97
|
+
simplecov-html (0.7.1)
|
72
98
|
slop (3.4.5)
|
99
|
+
spoon (0.0.4)
|
100
|
+
ffi
|
73
101
|
sqlite3 (1.3.7)
|
74
102
|
thor (0.18.1)
|
75
103
|
tzinfo (0.3.37)
|
76
104
|
|
77
105
|
PLATFORMS
|
106
|
+
java
|
78
107
|
ruby
|
79
108
|
|
80
109
|
DEPENDENCIES
|
@@ -82,6 +111,7 @@ DEPENDENCIES
|
|
82
111
|
activerecord-jdbcsqlite3-adapter!
|
83
112
|
appraisal
|
84
113
|
colored
|
114
|
+
coveralls
|
85
115
|
guard
|
86
116
|
guard-rspec
|
87
117
|
jdbc-sqlite3
|
@@ -89,4 +119,5 @@ DEPENDENCIES
|
|
89
119
|
pry
|
90
120
|
rake
|
91
121
|
rspec
|
122
|
+
ruby-prof
|
92
123
|
sqlite3
|
data/gemfiles/AR_4.gemfile
CHANGED
@@ -10,7 +10,9 @@ gem "guard"
|
|
10
10
|
gem "guard-rspec"
|
11
11
|
gem "appraisal"
|
12
12
|
gem "sqlite3", :platform=>:ruby
|
13
|
-
gem "jdbc-sqlite3", :platform=>:jruby
|
13
|
+
gem "jdbc-sqlite3", :platform=>:jruby, :require=>"jdbc/sqlite3"
|
14
|
+
gem "coveralls", :require=>false
|
15
|
+
gem "ruby-prof", :platform=>:ruby
|
14
16
|
gem "activerecord", "4.0.0.rc1", :require=>"active_record"
|
15
17
|
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby, :github=>"jruby/activerecord-jdbc-adapter"
|
16
18
|
|
data/gemfiles/AR_4.gemfile.lock
CHANGED
@@ -9,7 +9,7 @@ GIT
|
|
9
9
|
PATH
|
10
10
|
remote: /Users/inossidabile/Repos/protector
|
11
11
|
specs:
|
12
|
-
protector (0.1
|
12
|
+
protector (0.2.1)
|
13
13
|
activesupport
|
14
14
|
i18n
|
15
15
|
|
@@ -41,6 +41,13 @@ GEM
|
|
41
41
|
builder (3.1.4)
|
42
42
|
coderay (1.0.9)
|
43
43
|
colored (1.2)
|
44
|
+
colorize (0.5.8)
|
45
|
+
coveralls (0.6.7)
|
46
|
+
colorize
|
47
|
+
multi_json (~> 1.3)
|
48
|
+
rest-client
|
49
|
+
simplecov (>= 0.7)
|
50
|
+
thor
|
44
51
|
diff-lcs (1.2.4)
|
45
52
|
ffi (1.8.1)
|
46
53
|
ffi (1.8.1-java)
|
@@ -62,6 +69,7 @@ GEM
|
|
62
69
|
rb-kqueue (>= 0.2)
|
63
70
|
lumberjack (1.0.3)
|
64
71
|
method_source (0.8.1)
|
72
|
+
mime-types (1.23)
|
65
73
|
minitest (4.7.4)
|
66
74
|
multi_json (1.7.3)
|
67
75
|
pry (0.9.12.2)
|
@@ -79,6 +87,8 @@ GEM
|
|
79
87
|
ffi (>= 0.5.0)
|
80
88
|
rb-kqueue (0.2.0)
|
81
89
|
ffi (>= 0.5.0)
|
90
|
+
rest-client (1.6.7)
|
91
|
+
mime-types (>= 1.16)
|
82
92
|
rspec (2.13.0)
|
83
93
|
rspec-core (~> 2.13.0)
|
84
94
|
rspec-expectations (~> 2.13.0)
|
@@ -87,6 +97,11 @@ GEM
|
|
87
97
|
rspec-expectations (2.13.0)
|
88
98
|
diff-lcs (>= 1.1.3, < 2.0)
|
89
99
|
rspec-mocks (2.13.1)
|
100
|
+
ruby-prof (0.13.0)
|
101
|
+
simplecov (0.7.1)
|
102
|
+
multi_json (~> 1.0)
|
103
|
+
simplecov-html (~> 0.7.1)
|
104
|
+
simplecov-html (0.7.1)
|
90
105
|
slop (3.4.5)
|
91
106
|
spoon (0.0.4)
|
92
107
|
ffi
|
@@ -105,6 +120,7 @@ DEPENDENCIES
|
|
105
120
|
activerecord-jdbcsqlite3-adapter!
|
106
121
|
appraisal
|
107
122
|
colored
|
123
|
+
coveralls
|
108
124
|
guard
|
109
125
|
guard-rspec
|
110
126
|
jdbc-sqlite3
|
@@ -112,4 +128,5 @@ DEPENDENCIES
|
|
112
128
|
pry
|
113
129
|
rake
|
114
130
|
rspec
|
131
|
+
ruby-prof
|
115
132
|
sqlite3
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rake"
|
6
|
+
gem "colored"
|
7
|
+
gem "pry"
|
8
|
+
gem "rspec"
|
9
|
+
gem "guard"
|
10
|
+
gem "guard-rspec"
|
11
|
+
gem "appraisal"
|
12
|
+
gem "sqlite3", :platform=>:ruby
|
13
|
+
gem "jdbc-sqlite3", :platform=>:jruby
|
14
|
+
gem "coveralls", :require=>false
|
15
|
+
gem "mongoid", ">= 3.1.4"
|
16
|
+
|
17
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,112 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/inossidabile/Repos/protector
|
3
|
+
specs:
|
4
|
+
protector (0.1.1)
|
5
|
+
activesupport
|
6
|
+
i18n
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (3.2.13)
|
12
|
+
activesupport (= 3.2.13)
|
13
|
+
builder (~> 3.0.0)
|
14
|
+
activesupport (3.2.13)
|
15
|
+
i18n (= 0.6.1)
|
16
|
+
multi_json (~> 1.0)
|
17
|
+
appraisal (0.5.2)
|
18
|
+
bundler
|
19
|
+
rake
|
20
|
+
builder (3.0.4)
|
21
|
+
coderay (1.0.9)
|
22
|
+
colored (1.2)
|
23
|
+
colorize (0.5.8)
|
24
|
+
coveralls (0.6.7)
|
25
|
+
colorize
|
26
|
+
multi_json (~> 1.3)
|
27
|
+
rest-client
|
28
|
+
simplecov (>= 0.7)
|
29
|
+
thor
|
30
|
+
diff-lcs (1.2.4)
|
31
|
+
ffi (1.8.1)
|
32
|
+
ffi (1.8.1-java)
|
33
|
+
formatador (0.2.4)
|
34
|
+
guard (1.8.0)
|
35
|
+
formatador (>= 0.2.4)
|
36
|
+
listen (>= 1.0.0)
|
37
|
+
lumberjack (>= 1.0.2)
|
38
|
+
pry (>= 0.9.10)
|
39
|
+
thor (>= 0.14.6)
|
40
|
+
guard-rspec (3.0.1)
|
41
|
+
guard (>= 1.8)
|
42
|
+
rspec (~> 2.13)
|
43
|
+
i18n (0.6.1)
|
44
|
+
jdbc-sqlite3 (3.7.2.1)
|
45
|
+
listen (1.1.4)
|
46
|
+
rb-fsevent (>= 0.9.3)
|
47
|
+
rb-inotify (>= 0.9)
|
48
|
+
rb-kqueue (>= 0.2)
|
49
|
+
lumberjack (1.0.3)
|
50
|
+
method_source (0.8.1)
|
51
|
+
mime-types (1.23)
|
52
|
+
mongoid (3.1.4)
|
53
|
+
activemodel (~> 3.2)
|
54
|
+
moped (~> 1.4)
|
55
|
+
origin (~> 1.0)
|
56
|
+
tzinfo (~> 0.3.22)
|
57
|
+
moped (1.5.0)
|
58
|
+
multi_json (1.7.5)
|
59
|
+
origin (1.1.0)
|
60
|
+
pry (0.9.12.2)
|
61
|
+
coderay (~> 1.0.5)
|
62
|
+
method_source (~> 0.8)
|
63
|
+
slop (~> 3.4)
|
64
|
+
pry (0.9.12.2-java)
|
65
|
+
coderay (~> 1.0.5)
|
66
|
+
method_source (~> 0.8)
|
67
|
+
slop (~> 3.4)
|
68
|
+
spoon (~> 0.0)
|
69
|
+
rake (10.0.4)
|
70
|
+
rb-fsevent (0.9.3)
|
71
|
+
rb-inotify (0.9.0)
|
72
|
+
ffi (>= 0.5.0)
|
73
|
+
rb-kqueue (0.2.0)
|
74
|
+
ffi (>= 0.5.0)
|
75
|
+
rest-client (1.6.7)
|
76
|
+
mime-types (>= 1.16)
|
77
|
+
rspec (2.13.0)
|
78
|
+
rspec-core (~> 2.13.0)
|
79
|
+
rspec-expectations (~> 2.13.0)
|
80
|
+
rspec-mocks (~> 2.13.0)
|
81
|
+
rspec-core (2.13.1)
|
82
|
+
rspec-expectations (2.13.0)
|
83
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
84
|
+
rspec-mocks (2.13.1)
|
85
|
+
simplecov (0.7.1)
|
86
|
+
multi_json (~> 1.0)
|
87
|
+
simplecov-html (~> 0.7.1)
|
88
|
+
simplecov-html (0.7.1)
|
89
|
+
slop (3.4.5)
|
90
|
+
spoon (0.0.4)
|
91
|
+
ffi
|
92
|
+
sqlite3 (1.3.7)
|
93
|
+
thor (0.18.1)
|
94
|
+
tzinfo (0.3.37)
|
95
|
+
|
96
|
+
PLATFORMS
|
97
|
+
java
|
98
|
+
ruby
|
99
|
+
|
100
|
+
DEPENDENCIES
|
101
|
+
appraisal
|
102
|
+
colored
|
103
|
+
coveralls
|
104
|
+
guard
|
105
|
+
guard-rspec
|
106
|
+
jdbc-sqlite3
|
107
|
+
mongoid (>= 3.1.4)
|
108
|
+
protector!
|
109
|
+
pry
|
110
|
+
rake
|
111
|
+
rspec
|
112
|
+
sqlite3
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rake"
|
6
|
+
gem "colored"
|
7
|
+
gem "pry"
|
8
|
+
gem "rspec"
|
9
|
+
gem "guard"
|
10
|
+
gem "guard-rspec"
|
11
|
+
gem "appraisal"
|
12
|
+
gem "sqlite3", :platform=>:ruby
|
13
|
+
gem "jdbc-sqlite3", :platform=>:jruby, :require=>"jdbc/sqlite3"
|
14
|
+
gem "coveralls", :require=>false
|
15
|
+
gem "ruby-prof", :platform=>:ruby
|
16
|
+
gem "sequel", "3.30.0"
|
17
|
+
|
18
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,103 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/inossidabile/Repos/protector
|
3
|
+
specs:
|
4
|
+
protector (0.2.1)
|
5
|
+
activesupport
|
6
|
+
i18n
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (3.2.12)
|
12
|
+
i18n (~> 0.6)
|
13
|
+
multi_json (~> 1.0)
|
14
|
+
appraisal (0.5.2)
|
15
|
+
bundler
|
16
|
+
rake
|
17
|
+
coderay (1.0.9)
|
18
|
+
colored (1.2)
|
19
|
+
colorize (0.5.8)
|
20
|
+
coveralls (0.6.7)
|
21
|
+
colorize
|
22
|
+
multi_json (~> 1.3)
|
23
|
+
rest-client
|
24
|
+
simplecov (>= 0.7)
|
25
|
+
thor
|
26
|
+
diff-lcs (1.2.4)
|
27
|
+
ffi (1.8.1)
|
28
|
+
ffi (1.8.1-java)
|
29
|
+
formatador (0.2.4)
|
30
|
+
guard (1.8.0)
|
31
|
+
formatador (>= 0.2.4)
|
32
|
+
listen (>= 1.0.0)
|
33
|
+
lumberjack (>= 1.0.2)
|
34
|
+
pry (>= 0.9.10)
|
35
|
+
thor (>= 0.14.6)
|
36
|
+
guard-rspec (3.0.1)
|
37
|
+
guard (>= 1.8)
|
38
|
+
rspec (~> 2.13)
|
39
|
+
i18n (0.6.4)
|
40
|
+
jdbc-sqlite3 (3.7.2.1)
|
41
|
+
listen (1.1.4)
|
42
|
+
rb-fsevent (>= 0.9.3)
|
43
|
+
rb-inotify (>= 0.9)
|
44
|
+
rb-kqueue (>= 0.2)
|
45
|
+
lumberjack (1.0.3)
|
46
|
+
method_source (0.8.1)
|
47
|
+
mime-types (1.23)
|
48
|
+
multi_json (1.7.5)
|
49
|
+
pry (0.9.12.2)
|
50
|
+
coderay (~> 1.0.5)
|
51
|
+
method_source (~> 0.8)
|
52
|
+
slop (~> 3.4)
|
53
|
+
pry (0.9.12.2-java)
|
54
|
+
coderay (~> 1.0.5)
|
55
|
+
method_source (~> 0.8)
|
56
|
+
slop (~> 3.4)
|
57
|
+
spoon (~> 0.0)
|
58
|
+
rake (10.0.4)
|
59
|
+
rb-fsevent (0.9.3)
|
60
|
+
rb-inotify (0.9.0)
|
61
|
+
ffi (>= 0.5.0)
|
62
|
+
rb-kqueue (0.2.0)
|
63
|
+
ffi (>= 0.5.0)
|
64
|
+
rest-client (1.6.7)
|
65
|
+
mime-types (>= 1.16)
|
66
|
+
rspec (2.13.0)
|
67
|
+
rspec-core (~> 2.13.0)
|
68
|
+
rspec-expectations (~> 2.13.0)
|
69
|
+
rspec-mocks (~> 2.13.0)
|
70
|
+
rspec-core (2.13.1)
|
71
|
+
rspec-expectations (2.13.0)
|
72
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
73
|
+
rspec-mocks (2.13.1)
|
74
|
+
ruby-prof (0.13.0)
|
75
|
+
sequel (3.30.0)
|
76
|
+
simplecov (0.7.1)
|
77
|
+
multi_json (~> 1.0)
|
78
|
+
simplecov-html (~> 0.7.1)
|
79
|
+
simplecov-html (0.7.1)
|
80
|
+
slop (3.4.5)
|
81
|
+
spoon (0.0.4)
|
82
|
+
ffi
|
83
|
+
sqlite3 (1.3.7)
|
84
|
+
thor (0.18.1)
|
85
|
+
|
86
|
+
PLATFORMS
|
87
|
+
java
|
88
|
+
ruby
|
89
|
+
|
90
|
+
DEPENDENCIES
|
91
|
+
appraisal
|
92
|
+
colored
|
93
|
+
coveralls
|
94
|
+
guard
|
95
|
+
guard-rspec
|
96
|
+
jdbc-sqlite3
|
97
|
+
protector!
|
98
|
+
pry
|
99
|
+
rake
|
100
|
+
rspec
|
101
|
+
ruby-prof
|
102
|
+
sequel (= 3.30.0)
|
103
|
+
sqlite3
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Protector
|
2
2
|
module Adapters
|
3
3
|
module ActiveRecord
|
4
|
-
#
|
4
|
+
# Patches `ActiveRecord::Base`
|
5
5
|
module Base
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
@@ -9,18 +9,15 @@ module Protector
|
|
9
9
|
include Protector::DSL::Base
|
10
10
|
include Protector::DSL::Entry
|
11
11
|
|
12
|
-
ObjectSpace.each_object(Class).each do |
|
13
|
-
|
12
|
+
ObjectSpace.each_object(Class).each do |klass|
|
13
|
+
klass.undefine_attribute_methods if klass < self
|
14
14
|
end
|
15
15
|
|
16
|
-
validate
|
16
|
+
validate do
|
17
17
|
return unless @protector_subject
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
validate(on: :update) do
|
22
|
-
return unless @protector_subject
|
23
|
-
errors[:base] << I18n.t('protector.invalid') unless updatable?
|
18
|
+
if (new_record? && !creatable?) || (!new_record? && !updatable?)
|
19
|
+
errors[:base] << I18n.t('protector.invalid')
|
20
|
+
end
|
24
21
|
end
|
25
22
|
|
26
23
|
before_destroy do
|
@@ -45,7 +42,12 @@ module Protector
|
|
45
42
|
end
|
46
43
|
|
47
44
|
def [](name)
|
48
|
-
if
|
45
|
+
if (
|
46
|
+
!@protector_subject ||
|
47
|
+
name == self.class.primary_key ||
|
48
|
+
(self.class.primary_key.is_a?(Array) && self.class.primary_key.include?(name)) ||
|
49
|
+
protector_meta.readable?(name)
|
50
|
+
)
|
49
51
|
read_attribute(name)
|
50
52
|
else
|
51
53
|
nil
|
@@ -77,10 +79,6 @@ module Protector
|
|
77
79
|
|
78
80
|
# Storage for {Protector::DSL::Meta::Box}
|
79
81
|
def protector_meta
|
80
|
-
unless @protector_subject
|
81
|
-
raise "Unprotected entity detected: use `restrict` method to protect it."
|
82
|
-
end
|
83
|
-
|
84
82
|
@protector_meta ||= self.class.protector_meta.evaluate(
|
85
83
|
self.class,
|
86
84
|
@protector_subject,
|
@@ -98,13 +96,13 @@ module Protector
|
|
98
96
|
|
99
97
|
# Checks if current model can be created in the context of current subject
|
100
98
|
def creatable?
|
101
|
-
fields = HashWithIndifferentAccess[changed.map{|
|
99
|
+
fields = HashWithIndifferentAccess[changed.map{|field| [field, read_attribute(field)]}]
|
102
100
|
protector_meta.creatable?(fields)
|
103
101
|
end
|
104
102
|
|
105
103
|
# Checks if current model can be updated in the context of current subject
|
106
104
|
def updatable?
|
107
|
-
fields = HashWithIndifferentAccess[changed.map{|
|
105
|
+
fields = HashWithIndifferentAccess[changed.map{|field| [field, read_attribute(field)]}]
|
108
106
|
protector_meta.updatable?(fields)
|
109
107
|
end
|
110
108
|
|