resource_policy 1.0.0 → 1.2.0
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/.github/workflows/ruby.yml +16 -15
- data/.ruby-version +1 -1
- data/CHANGELOG.md +9 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +224 -168
- data/docs/README.md +12 -11
- data/docs/_sidebar.md +2 -1
- data/docs/components/action_validator.md +28 -2
- data/docs/components/actions_policy.md +4 -4
- data/docs/components/attributes_policy.md +1 -1
- data/docs/components/attributes_validator.md +75 -0
- data/docs/components/policy.md +43 -15
- data/lib/resource_policy/policy/actions_policy/actions_policy_model.rb +8 -0
- data/lib/resource_policy/policy/attributes_policy/attributes_policy_model.rb +7 -11
- data/lib/resource_policy/policy/policy_configuration.rb +6 -0
- data/lib/resource_policy/protected_resource.rb +4 -8
- data/lib/resource_policy/rails.rb +2 -1
- data/lib/resource_policy/validators/action_validator.rb +71 -0
- data/lib/resource_policy/validators/attributes_validator.rb +79 -0
- data/lib/resource_policy/version.rb +1 -1
- data/resource_policy.gemspec +2 -2
- metadata +11 -14
- data/.travis.yml +0 -7
- data/lib/resource_policy/validators/action_policy_validator.rb +0 -54
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63bbda72581f4db59a3a27f33616db5480c90a39baff857f4886a89338c5b3c9
|
|
4
|
+
data.tar.gz: 139231ccbac6d84cb8d697be8c34f46fded3ff66e46ce65b7fc4ee5397631f1a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e81553c1ec0c7dd0e00ec063ceef818a34f70a24084f515cc9d32302d8b8f628398def7ebe04c42bfc1c33174b970a4c6ab76d31f7f1e2ef1048fe4ae3dae151
|
|
7
|
+
data.tar.gz: 394f96baaba9120f15fc6b25465a230e4b89961faef05bcfc9f885d7ee6ba763501e9576cce16f0ac5557225a42fbaa678478ceff2c8b5ce159a7616d38741d7
|
data/.github/workflows/ruby.yml
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
name: Ruby
|
|
2
|
-
|
|
3
|
-
on: [push]
|
|
4
|
-
|
|
2
|
+
on: [push, pull_request]
|
|
5
3
|
jobs:
|
|
6
|
-
|
|
4
|
+
specs:
|
|
5
|
+
strategy:
|
|
6
|
+
matrix:
|
|
7
|
+
ruby-version: ['3.2', '3.3', '3.4', '4.0']
|
|
7
8
|
|
|
8
9
|
runs-on: ubuntu-latest
|
|
9
|
-
|
|
10
10
|
steps:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
- uses: ruby/setup-ruby@v1
|
|
13
|
+
with:
|
|
14
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
15
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
16
|
+
- run: bundle exec rake
|
|
17
|
+
- name: Upload coverage to Codecov
|
|
18
|
+
uses: codecov/codecov-action@v5
|
|
19
|
+
with:
|
|
20
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
21
|
+
files: ./coverage/lcov.info
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
4.0.6
|
data/CHANGELOG.md
CHANGED
|
@@ -7,8 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
* Removed: support for Ruby < 3.2 (CI now tests Ruby 3.2–4.0)
|
|
11
|
+
* Added: short-hand method for getting allowed actions
|
|
12
|
+
* Added: support for proc type validator options
|
|
13
|
+
* Added: `PolicyConfiguration#configured_attribute` for looking up one configured attribute
|
|
14
|
+
* Changed: protected resource and attributes policy reads look the attribute up directly instead of rebuilding the attributes hash on every read. These lookups now use `PolicyConfiguration#configured_attribute` and no longer go through `PolicyConfiguration#attributes`; if you override `#attributes` in a custom configuration, override `#configured_attribute` as well
|
|
10
15
|
* Added/Changed/Deprecated/Removed/Fixed/Security: YOUR CHANGE HERE
|
|
11
16
|
|
|
17
|
+
## [1.1.0]
|
|
18
|
+
|
|
19
|
+
* Added AttributesValidator
|
|
20
|
+
|
|
12
21
|
## [1.0.0]
|
|
13
22
|
|
|
14
23
|
* Added Ruby on Rails validator
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,224 +1,279 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
resource_policy (1.
|
|
4
|
+
resource_policy (1.2.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
actioncable (
|
|
10
|
-
actionpack (=
|
|
11
|
-
activesupport (=
|
|
9
|
+
actioncable (8.0.5.1)
|
|
10
|
+
actionpack (= 8.0.5.1)
|
|
11
|
+
activesupport (= 8.0.5.1)
|
|
12
12
|
nio4r (~> 2.0)
|
|
13
13
|
websocket-driver (>= 0.6.1)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
actionview (= 7.0.4.2)
|
|
36
|
-
activesupport (= 7.0.4.2)
|
|
37
|
-
rack (~> 2.0, >= 2.2.0)
|
|
14
|
+
zeitwerk (~> 2.6)
|
|
15
|
+
actionmailbox (8.0.5.1)
|
|
16
|
+
actionpack (= 8.0.5.1)
|
|
17
|
+
activejob (= 8.0.5.1)
|
|
18
|
+
activerecord (= 8.0.5.1)
|
|
19
|
+
activestorage (= 8.0.5.1)
|
|
20
|
+
activesupport (= 8.0.5.1)
|
|
21
|
+
mail (>= 2.8.0)
|
|
22
|
+
actionmailer (8.0.5.1)
|
|
23
|
+
actionpack (= 8.0.5.1)
|
|
24
|
+
actionview (= 8.0.5.1)
|
|
25
|
+
activejob (= 8.0.5.1)
|
|
26
|
+
activesupport (= 8.0.5.1)
|
|
27
|
+
mail (>= 2.8.0)
|
|
28
|
+
rails-dom-testing (~> 2.2)
|
|
29
|
+
actionpack (8.0.5.1)
|
|
30
|
+
actionview (= 8.0.5.1)
|
|
31
|
+
activesupport (= 8.0.5.1)
|
|
32
|
+
nokogiri (>= 1.8.5)
|
|
33
|
+
rack (>= 2.2.4)
|
|
34
|
+
rack-session (>= 1.0.1)
|
|
38
35
|
rack-test (>= 0.6.3)
|
|
39
|
-
rails-dom-testing (~> 2.
|
|
40
|
-
rails-html-sanitizer (~> 1.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
rails-dom-testing (~> 2.2)
|
|
37
|
+
rails-html-sanitizer (~> 1.6)
|
|
38
|
+
useragent (~> 0.16)
|
|
39
|
+
actiontext (8.0.5.1)
|
|
40
|
+
actionpack (= 8.0.5.1)
|
|
41
|
+
activerecord (= 8.0.5.1)
|
|
42
|
+
activestorage (= 8.0.5.1)
|
|
43
|
+
activesupport (= 8.0.5.1)
|
|
46
44
|
globalid (>= 0.6.0)
|
|
47
45
|
nokogiri (>= 1.8.5)
|
|
48
|
-
actionview (
|
|
49
|
-
activesupport (=
|
|
46
|
+
actionview (8.0.5.1)
|
|
47
|
+
activesupport (= 8.0.5.1)
|
|
50
48
|
builder (~> 3.1)
|
|
51
|
-
erubi (~> 1.
|
|
52
|
-
rails-dom-testing (~> 2.
|
|
53
|
-
rails-html-sanitizer (~> 1.
|
|
54
|
-
activejob (
|
|
55
|
-
activesupport (=
|
|
49
|
+
erubi (~> 1.11)
|
|
50
|
+
rails-dom-testing (~> 2.2)
|
|
51
|
+
rails-html-sanitizer (~> 1.6)
|
|
52
|
+
activejob (8.0.5.1)
|
|
53
|
+
activesupport (= 8.0.5.1)
|
|
56
54
|
globalid (>= 0.3.6)
|
|
57
|
-
activemodel (
|
|
58
|
-
activesupport (=
|
|
59
|
-
activerecord (
|
|
60
|
-
activemodel (=
|
|
61
|
-
activesupport (=
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
activemodel (8.0.5.1)
|
|
56
|
+
activesupport (= 8.0.5.1)
|
|
57
|
+
activerecord (8.0.5.1)
|
|
58
|
+
activemodel (= 8.0.5.1)
|
|
59
|
+
activesupport (= 8.0.5.1)
|
|
60
|
+
timeout (>= 0.4.0)
|
|
61
|
+
activestorage (8.0.5.1)
|
|
62
|
+
actionpack (= 8.0.5.1)
|
|
63
|
+
activejob (= 8.0.5.1)
|
|
64
|
+
activerecord (= 8.0.5.1)
|
|
65
|
+
activesupport (= 8.0.5.1)
|
|
67
66
|
marcel (~> 1.0)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
activesupport (8.0.5.1)
|
|
68
|
+
base64
|
|
69
|
+
benchmark (>= 0.3)
|
|
70
|
+
bigdecimal
|
|
71
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
72
|
+
connection_pool (>= 2.2.5)
|
|
73
|
+
drb
|
|
71
74
|
i18n (>= 1.6, < 2)
|
|
75
|
+
logger (>= 1.4.2)
|
|
72
76
|
minitest (>= 5.1)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
securerandom (>= 0.3)
|
|
78
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
79
|
+
uri (>= 0.13.1)
|
|
80
|
+
ast (2.4.3)
|
|
81
|
+
base64 (0.3.0)
|
|
82
|
+
benchmark (0.5.0)
|
|
83
|
+
bigdecimal (4.1.3)
|
|
84
|
+
builder (3.3.0)
|
|
85
|
+
byebug (13.0.0)
|
|
86
|
+
reline (>= 0.6.0)
|
|
79
87
|
coderay (1.1.3)
|
|
80
|
-
concurrent-ruby (1.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
concurrent-ruby (1.3.8)
|
|
89
|
+
connection_pool (3.0.2)
|
|
90
|
+
crass (1.0.7)
|
|
91
|
+
date (3.5.1)
|
|
92
|
+
diff-lcs (1.6.2)
|
|
93
|
+
drb (2.2.3)
|
|
94
|
+
erb (6.0.7)
|
|
95
|
+
erubi (1.13.1)
|
|
96
|
+
globalid (1.4.0)
|
|
97
|
+
activesupport (>= 6.1)
|
|
98
|
+
i18n (1.15.2)
|
|
89
99
|
concurrent-ruby (~> 1.0)
|
|
90
|
-
|
|
91
|
-
|
|
100
|
+
io-console (0.9.4)
|
|
101
|
+
irb (1.18.0)
|
|
102
|
+
pp (>= 0.6.0)
|
|
103
|
+
prism (>= 1.3.0)
|
|
104
|
+
rdoc (>= 4.0.0)
|
|
105
|
+
reline (>= 0.4.2)
|
|
106
|
+
json (3.0.2)
|
|
107
|
+
language_server-protocol (3.17.0.6)
|
|
108
|
+
lint_roller (1.1.0)
|
|
109
|
+
logger (1.7.0)
|
|
110
|
+
loofah (2.25.2)
|
|
92
111
|
crass (~> 1.0.2)
|
|
93
|
-
nokogiri (>= 1.
|
|
94
|
-
mail (2.
|
|
112
|
+
nokogiri (>= 1.12.0)
|
|
113
|
+
mail (2.9.1)
|
|
114
|
+
logger
|
|
95
115
|
mini_mime (>= 0.1.1)
|
|
96
116
|
net-imap
|
|
97
117
|
net-pop
|
|
98
118
|
net-smtp
|
|
99
|
-
marcel (1.
|
|
100
|
-
method_source (1.
|
|
101
|
-
mini_mime (1.1.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
119
|
+
marcel (1.2.1)
|
|
120
|
+
method_source (1.1.0)
|
|
121
|
+
mini_mime (1.1.5)
|
|
122
|
+
minitest (6.0.6)
|
|
123
|
+
drb (~> 2.0)
|
|
124
|
+
prism (~> 1.5)
|
|
125
|
+
net-imap (0.6.7)
|
|
105
126
|
date
|
|
106
127
|
net-protocol
|
|
107
128
|
net-pop (0.1.2)
|
|
108
129
|
net-protocol
|
|
109
|
-
net-protocol (0.
|
|
130
|
+
net-protocol (0.4.0)
|
|
110
131
|
timeout
|
|
111
|
-
net-smtp (0.
|
|
132
|
+
net-smtp (0.5.1)
|
|
112
133
|
net-protocol
|
|
113
|
-
nio4r (2.5
|
|
114
|
-
nokogiri (1.
|
|
115
|
-
mini_portile2 (~> 2.8.0)
|
|
134
|
+
nio4r (2.7.5)
|
|
135
|
+
nokogiri (1.19.4-arm64-darwin)
|
|
116
136
|
racc (~> 1.4)
|
|
117
|
-
|
|
118
|
-
|
|
137
|
+
nokogiri (1.19.4-x86_64-linux-gnu)
|
|
138
|
+
racc (~> 1.4)
|
|
139
|
+
parallel (1.28.0)
|
|
140
|
+
parser (3.3.12.0)
|
|
119
141
|
ast (~> 2.4.1)
|
|
120
|
-
|
|
142
|
+
racc
|
|
143
|
+
pp (0.6.4)
|
|
144
|
+
prettyprint
|
|
145
|
+
prettyprint (0.2.0)
|
|
146
|
+
prism (1.9.0)
|
|
147
|
+
pry (0.16.0)
|
|
121
148
|
coderay (~> 1.1)
|
|
122
149
|
method_source (~> 1.0)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
rack
|
|
150
|
+
reline (>= 0.6.0)
|
|
151
|
+
pry-byebug (3.12.0)
|
|
152
|
+
byebug (~> 13.0)
|
|
153
|
+
pry (>= 0.13, < 0.17)
|
|
154
|
+
racc (1.8.1)
|
|
155
|
+
rack (3.2.7)
|
|
156
|
+
rack-session (2.1.2)
|
|
157
|
+
base64 (>= 0.1.0)
|
|
158
|
+
rack (>= 3.0.0)
|
|
159
|
+
rack-test (2.2.0)
|
|
129
160
|
rack (>= 1.3)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
161
|
+
rackup (2.3.1)
|
|
162
|
+
rack (>= 3)
|
|
163
|
+
rails (8.0.5.1)
|
|
164
|
+
actioncable (= 8.0.5.1)
|
|
165
|
+
actionmailbox (= 8.0.5.1)
|
|
166
|
+
actionmailer (= 8.0.5.1)
|
|
167
|
+
actionpack (= 8.0.5.1)
|
|
168
|
+
actiontext (= 8.0.5.1)
|
|
169
|
+
actionview (= 8.0.5.1)
|
|
170
|
+
activejob (= 8.0.5.1)
|
|
171
|
+
activemodel (= 8.0.5.1)
|
|
172
|
+
activerecord (= 8.0.5.1)
|
|
173
|
+
activestorage (= 8.0.5.1)
|
|
174
|
+
activesupport (= 8.0.5.1)
|
|
142
175
|
bundler (>= 1.15.0)
|
|
143
|
-
railties (=
|
|
144
|
-
rails-dom-testing (2.0
|
|
145
|
-
activesupport (>=
|
|
176
|
+
railties (= 8.0.5.1)
|
|
177
|
+
rails-dom-testing (2.3.0)
|
|
178
|
+
activesupport (>= 5.0.0)
|
|
179
|
+
minitest
|
|
146
180
|
nokogiri (>= 1.6)
|
|
147
|
-
rails-html-sanitizer (1.
|
|
148
|
-
loofah (~> 2.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
181
|
+
rails-html-sanitizer (1.7.1)
|
|
182
|
+
loofah (~> 2.25, >= 2.25.2)
|
|
183
|
+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
184
|
+
railties (8.0.5.1)
|
|
185
|
+
actionpack (= 8.0.5.1)
|
|
186
|
+
activesupport (= 8.0.5.1)
|
|
187
|
+
irb (~> 1.13)
|
|
188
|
+
rackup (>= 1.0.0)
|
|
153
189
|
rake (>= 12.2)
|
|
154
|
-
thor (~> 1.0)
|
|
155
|
-
|
|
190
|
+
thor (~> 1.0, >= 1.2.2)
|
|
191
|
+
tsort (>= 0.2)
|
|
192
|
+
zeitwerk (~> 2.6)
|
|
156
193
|
rainbow (3.1.1)
|
|
157
|
-
rake (13.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
194
|
+
rake (13.4.2)
|
|
195
|
+
rbs (4.1.3)
|
|
196
|
+
logger
|
|
197
|
+
prism (>= 1.6.0)
|
|
198
|
+
tsort
|
|
199
|
+
rdoc (8.0.0)
|
|
200
|
+
erb
|
|
201
|
+
prism (>= 1.6.0)
|
|
202
|
+
rbs (>= 4.0.0)
|
|
203
|
+
tsort
|
|
204
|
+
regexp_parser (2.13.0)
|
|
205
|
+
reline (0.7.0)
|
|
206
|
+
io-console (~> 0.5)
|
|
207
|
+
rspec (3.13.2)
|
|
208
|
+
rspec-core (~> 3.13.0)
|
|
209
|
+
rspec-expectations (~> 3.13.0)
|
|
210
|
+
rspec-mocks (~> 3.13.0)
|
|
211
|
+
rspec-core (3.13.6)
|
|
212
|
+
rspec-support (~> 3.13.0)
|
|
213
|
+
rspec-expectations (3.13.5)
|
|
167
214
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
168
|
-
rspec-support (~> 3.
|
|
169
|
-
rspec-mocks (3.
|
|
215
|
+
rspec-support (~> 3.13.0)
|
|
216
|
+
rspec-mocks (3.13.8)
|
|
170
217
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
171
|
-
rspec-support (~> 3.
|
|
172
|
-
rspec-support (3.
|
|
173
|
-
rubocop (1.
|
|
174
|
-
json (
|
|
175
|
-
|
|
176
|
-
|
|
218
|
+
rspec-support (~> 3.13.0)
|
|
219
|
+
rspec-support (3.13.7)
|
|
220
|
+
rubocop (1.91.0)
|
|
221
|
+
json (>= 2.3)
|
|
222
|
+
language_server-protocol (~> 3.17.0.2)
|
|
223
|
+
lint_roller (~> 1.1.0)
|
|
224
|
+
parallel (>= 1.10)
|
|
225
|
+
parser (>= 3.3.0.2)
|
|
177
226
|
rainbow (>= 2.2.2, < 4.0)
|
|
178
|
-
regexp_parser (>=
|
|
179
|
-
|
|
180
|
-
rubocop-ast (>= 1.24.1, < 2.0)
|
|
227
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
228
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
181
229
|
ruby-progressbar (~> 1.7)
|
|
182
|
-
unicode-display_width (>= 2.4.0, <
|
|
183
|
-
rubocop-ast (1.
|
|
184
|
-
parser (>= 3.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
rubocop (>= 1.
|
|
189
|
-
rubocop-ast (>=
|
|
190
|
-
rubocop-rails (2.
|
|
230
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
231
|
+
rubocop-ast (1.50.0)
|
|
232
|
+
parser (>= 3.3.7.2)
|
|
233
|
+
prism (~> 1.7)
|
|
234
|
+
rubocop-performance (1.27.0)
|
|
235
|
+
lint_roller (~> 1.1)
|
|
236
|
+
rubocop (>= 1.89.0, < 2.0)
|
|
237
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
238
|
+
rubocop-rails (2.38.0)
|
|
191
239
|
activesupport (>= 4.2.0)
|
|
240
|
+
lint_roller (~> 1.1)
|
|
192
241
|
rack (>= 1.1)
|
|
193
|
-
rubocop (>= 1.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
simplecov-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
242
|
+
rubocop (>= 1.89.0, < 2.0)
|
|
243
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
|
244
|
+
rubocop-rspec (3.10.2)
|
|
245
|
+
lint_roller (~> 1.1)
|
|
246
|
+
regexp_parser (>= 2.0)
|
|
247
|
+
rubocop (~> 1.86, >= 1.86.2)
|
|
248
|
+
ruby-progressbar (1.13.0)
|
|
249
|
+
securerandom (0.4.1)
|
|
250
|
+
simplecov (1.2.0)
|
|
251
|
+
simplecov-lcov (0.9.0)
|
|
252
|
+
thor (1.5.0)
|
|
253
|
+
timeout (0.6.1)
|
|
254
|
+
tsort (0.2.0)
|
|
206
255
|
tzinfo (2.0.6)
|
|
207
256
|
concurrent-ruby (~> 1.0)
|
|
208
|
-
unicode-display_width (
|
|
209
|
-
|
|
257
|
+
unicode-display_width (3.3.0)
|
|
258
|
+
unicode-emoji (~> 4.3)
|
|
259
|
+
unicode-emoji (4.3.0)
|
|
260
|
+
uri (1.1.1)
|
|
261
|
+
useragent (0.16.11)
|
|
262
|
+
websocket-driver (0.8.2)
|
|
263
|
+
base64
|
|
210
264
|
websocket-extensions (>= 0.1.0)
|
|
211
265
|
websocket-extensions (0.1.5)
|
|
212
|
-
zeitwerk (2.
|
|
266
|
+
zeitwerk (2.8.3)
|
|
213
267
|
|
|
214
268
|
PLATFORMS
|
|
215
|
-
|
|
269
|
+
arm64-darwin-23
|
|
270
|
+
arm64-darwin-25
|
|
271
|
+
x86_64-linux
|
|
216
272
|
|
|
217
273
|
DEPENDENCIES
|
|
218
|
-
bundler (~>
|
|
219
|
-
codecov
|
|
274
|
+
bundler (~> 4.0)
|
|
220
275
|
pry-byebug
|
|
221
|
-
rails (~>
|
|
276
|
+
rails (~> 8.0.0)
|
|
222
277
|
rake (~> 13.0)
|
|
223
278
|
resource_policy!
|
|
224
279
|
rspec (~> 3.0)
|
|
@@ -227,6 +282,7 @@ DEPENDENCIES
|
|
|
227
282
|
rubocop-rails
|
|
228
283
|
rubocop-rspec
|
|
229
284
|
simplecov
|
|
285
|
+
simplecov-lcov
|
|
230
286
|
|
|
231
287
|
BUNDLED WITH
|
|
232
|
-
|
|
288
|
+
4.0.21
|
data/docs/README.md
CHANGED
|
@@ -51,11 +51,11 @@ class UserPolicy
|
|
|
51
51
|
include ResourcePolicy::Policy
|
|
52
52
|
|
|
53
53
|
policy do |c|
|
|
54
|
-
c.action(:
|
|
55
|
-
c.action(:
|
|
54
|
+
c.action(:show).allowed # current_user can always see user
|
|
55
|
+
c.action(:update).allowed(if: :admin?) # only admin current_user can update user
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
def initialize(user, current_user
|
|
58
|
+
def initialize(user, current_user)
|
|
59
59
|
@user = user
|
|
60
60
|
@current_user = current_user
|
|
61
61
|
end
|
|
@@ -71,9 +71,9 @@ end
|
|
|
71
71
|
#### Using action policy
|
|
72
72
|
|
|
73
73
|
```ruby
|
|
74
|
-
policy = UserPolicy.new(user, current_user
|
|
75
|
-
policy.action(:
|
|
76
|
-
policy.action(:
|
|
74
|
+
policy = UserPolicy.new(user, current_user)
|
|
75
|
+
policy.action(:show).allowed? # => true
|
|
76
|
+
policy.action(:update).allowed? # ... depends on `admin?` result
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
### Attributes policy
|
|
@@ -92,7 +92,7 @@ class UserPolicy
|
|
|
92
92
|
.allowed(:write, if: :admin?) # only admin current_user can change email
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
def initialize(user, current_user
|
|
95
|
+
def initialize(user, current_user)
|
|
96
96
|
@user = user
|
|
97
97
|
@current_user = current_user
|
|
98
98
|
end
|
|
@@ -108,9 +108,9 @@ end
|
|
|
108
108
|
#### Using attributes policy
|
|
109
109
|
|
|
110
110
|
```ruby
|
|
111
|
-
policy = UserPolicy.new(user, current_user
|
|
111
|
+
policy = UserPolicy.new(user, current_user)
|
|
112
112
|
policy.attribute(:email).readable? # => true
|
|
113
|
-
policy.
|
|
113
|
+
policy.attribute(:email).writable? # ... depends on `admin?` result
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
#### Using protector
|
|
@@ -123,7 +123,7 @@ class UserPolicy
|
|
|
123
123
|
|
|
124
124
|
policy do |c|
|
|
125
125
|
c.attribute(:id).allowed(:read)
|
|
126
|
-
c.attribute(:
|
|
126
|
+
c.attribute(:email).allowed(:read, if: :admin?)
|
|
127
127
|
end
|
|
128
128
|
|
|
129
129
|
...
|
|
@@ -139,7 +139,8 @@ user = User.find(1337)
|
|
|
139
139
|
user.id #=> 1337
|
|
140
140
|
user.email #=> "john.doe@example.com"
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
policy = UserPolicy.new(user, current_user)
|
|
143
|
+
protected_user = policy.protected_resource
|
|
143
144
|
protected_user.id #=> 1337
|
|
144
145
|
protected_user.email # nil
|
|
145
146
|
```
|
data/docs/_sidebar.md
CHANGED
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
* Components
|
|
3
3
|
* [Policy](components/policy)
|
|
4
4
|
* [ActionsPolicy](components/actions_policy)
|
|
5
|
-
* [
|
|
5
|
+
* [ActionValidator](components/action_validator)
|
|
6
6
|
* [AttributesPolicy](components/attributes_policy)
|
|
7
|
+
* [AttributesValidator](components/attributes_validator)
|
|
@@ -6,7 +6,7 @@ The `ResourcePolicy::ActionValidator` is a validator used to check the policy of
|
|
|
6
6
|
|
|
7
7
|
The `ResourcePolicy::ActionValidator` accepts two options:
|
|
8
8
|
|
|
9
|
-
- `:allowed_to` (required) - Specifies the action type that needs to be checked. This can be a symbol or
|
|
9
|
+
- `:allowed_to` (required) - Specifies the action type that needs to be checked. This can be a symbol, string or proc.
|
|
10
10
|
- `:as` (optional) - Specifies the key that will be used to display errors. This is useful if you want to rename the attribute being validated.
|
|
11
11
|
|
|
12
12
|
## Usage Example
|
|
@@ -31,4 +31,30 @@ else
|
|
|
31
31
|
end
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
## Usage Example with proc
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
require 'resource_policy/action_validator'
|
|
38
|
+
|
|
39
|
+
class SomeClass < ActiveRecord::Base
|
|
40
|
+
validates :some_policy, 'resource_policy/action': { allowed_to: -> { custom_allowed_to }, as: :some_item }
|
|
41
|
+
|
|
42
|
+
def some_policy
|
|
43
|
+
SomePolicy.new
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def custom_allowed_to
|
|
47
|
+
new_record? ? :create : :update
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
new_object = SomeClass.new
|
|
52
|
+
new_object.valid?
|
|
53
|
+
new_object.errors.messages # => { some_item: ['action "create" is not allowed'] }
|
|
54
|
+
|
|
55
|
+
existing_object = SomeClass.find(1)
|
|
56
|
+
existing_object.valid?
|
|
57
|
+
existing_object.errors.messages # => { some_item: ['action "update" is not allowed'] }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
In this example, the `SomeClass` has an attribute named `some_policy` which is validated using the `ResourcePolicy::ActionValidator`. The validator calls `custom_allowed_to` method on our model to determine which action to use. If record is new, it will check policy for the `create` action. If the record saved, it will check policy for `update` action. When the action is not allowed, an error message will be added to the `record.errors` object with the key `:some_item`. If the `:as` option is not provided, the key used to display the error will be the name of the attribute being validated.
|