action_policy 0.4.4 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +211 -175
  3. data/README.md +5 -4
  4. data/config/rubocop-rspec.yml +17 -0
  5. data/lib/.rbnext/2.7/action_policy/behaviours/policy_for.rb +62 -0
  6. data/lib/.rbnext/2.7/action_policy/i18n.rb +56 -0
  7. data/lib/.rbnext/2.7/action_policy/policy/cache.rb +101 -0
  8. data/lib/.rbnext/2.7/action_policy/policy/pre_check.rb +162 -0
  9. data/lib/.rbnext/2.7/action_policy/rspec/be_authorized_to.rb +89 -0
  10. data/lib/.rbnext/2.7/action_policy/rspec/have_authorized_scope.rb +124 -0
  11. data/lib/.rbnext/2.7/action_policy/utils/pretty_print.rb +159 -0
  12. data/lib/.rbnext/3.0/action_policy/behaviour.rb +115 -0
  13. data/lib/.rbnext/3.0/action_policy/behaviours/policy_for.rb +62 -0
  14. data/lib/.rbnext/3.0/action_policy/behaviours/scoping.rb +35 -0
  15. data/lib/.rbnext/3.0/action_policy/behaviours/thread_memoized.rb +59 -0
  16. data/lib/.rbnext/3.0/action_policy/ext/policy_cache_key.rb +72 -0
  17. data/lib/.rbnext/3.0/action_policy/policy/aliases.rb +69 -0
  18. data/lib/.rbnext/3.0/action_policy/policy/authorization.rb +87 -0
  19. data/lib/.rbnext/3.0/action_policy/policy/cache.rb +101 -0
  20. data/lib/.rbnext/3.0/action_policy/policy/core.rb +161 -0
  21. data/lib/.rbnext/3.0/action_policy/policy/defaults.rb +31 -0
  22. data/lib/.rbnext/3.0/action_policy/policy/execution_result.rb +37 -0
  23. data/lib/.rbnext/3.0/action_policy/policy/pre_check.rb +162 -0
  24. data/lib/.rbnext/3.0/action_policy/policy/reasons.rb +212 -0
  25. data/lib/.rbnext/3.0/action_policy/policy/scoping.rb +160 -0
  26. data/lib/.rbnext/3.0/action_policy/rspec/be_authorized_to.rb +89 -0
  27. data/lib/.rbnext/3.0/action_policy/rspec/have_authorized_scope.rb +124 -0
  28. data/lib/.rbnext/3.0/action_policy/utils/pretty_print.rb +159 -0
  29. data/lib/.rbnext/3.0/action_policy/utils/suggest_message.rb +19 -0
  30. data/lib/action_policy.rb +7 -1
  31. data/lib/action_policy/behaviour.rb +22 -16
  32. data/lib/action_policy/behaviours/policy_for.rb +10 -3
  33. data/lib/action_policy/behaviours/scoping.rb +2 -1
  34. data/lib/action_policy/behaviours/thread_memoized.rb +1 -3
  35. data/lib/action_policy/ext/module_namespace.rb +1 -6
  36. data/lib/action_policy/ext/policy_cache_key.rb +10 -30
  37. data/lib/action_policy/i18n.rb +1 -1
  38. data/lib/action_policy/lookup_chain.rb +26 -28
  39. data/lib/action_policy/policy/aliases.rb +7 -12
  40. data/lib/action_policy/policy/authorization.rb +8 -7
  41. data/lib/action_policy/policy/cache.rb +11 -17
  42. data/lib/action_policy/policy/core.rb +25 -12
  43. data/lib/action_policy/policy/defaults.rb +3 -9
  44. data/lib/action_policy/policy/execution_result.rb +3 -9
  45. data/lib/action_policy/policy/pre_check.rb +19 -58
  46. data/lib/action_policy/policy/reasons.rb +31 -19
  47. data/lib/action_policy/policy/scoping.rb +5 -6
  48. data/lib/action_policy/rails/controller.rb +6 -1
  49. data/lib/action_policy/rails/policy/instrumentation.rb +1 -1
  50. data/lib/action_policy/rspec/be_authorized_to.rb +5 -9
  51. data/lib/action_policy/rspec/dsl.rb +1 -1
  52. data/lib/action_policy/rspec/have_authorized_scope.rb +5 -7
  53. data/lib/action_policy/utils/pretty_print.rb +21 -24
  54. data/lib/action_policy/utils/suggest_message.rb +1 -3
  55. data/lib/action_policy/version.rb +1 -1
  56. data/lib/generators/action_policy/install/templates/{application_policy.rb → application_policy.rb.tt} +0 -0
  57. data/lib/generators/action_policy/policy/policy_generator.rb +4 -1
  58. data/lib/generators/action_policy/policy/templates/{policy.rb → policy.rb.tt} +0 -0
  59. data/lib/generators/rspec/templates/{policy_spec.rb → policy_spec.rb.tt} +0 -0
  60. data/lib/generators/test_unit/templates/{policy_test.rb → policy_test.rb.tt} +0 -0
  61. metadata +55 -119
  62. data/.gitattributes +0 -2
  63. data/.github/ISSUE_TEMPLATE.md +0 -21
  64. data/.github/PULL_REQUEST_TEMPLATE.md +0 -29
  65. data/.github/bug_report_template.rb +0 -175
  66. data/.gitignore +0 -15
  67. data/.rubocop.yml +0 -54
  68. data/.tidelift.yml +0 -6
  69. data/.travis.yml +0 -31
  70. data/Gemfile +0 -22
  71. data/Rakefile +0 -27
  72. data/action_policy.gemspec +0 -44
  73. data/benchmarks/namespaced_lookup_cache.rb +0 -74
  74. data/benchmarks/pre_checks.rb +0 -73
  75. data/bin/console +0 -14
  76. data/bin/setup +0 -8
  77. data/docs/.nojekyll +0 -0
  78. data/docs/CNAME +0 -1
  79. data/docs/README.md +0 -79
  80. data/docs/_sidebar.md +0 -27
  81. data/docs/aliases.md +0 -122
  82. data/docs/assets/docsify-search.js +0 -364
  83. data/docs/assets/docsify.min.js +0 -3
  84. data/docs/assets/fonts/FiraCode-Medium.woff +0 -0
  85. data/docs/assets/fonts/FiraCode-Regular.woff +0 -0
  86. data/docs/assets/images/banner.png +0 -0
  87. data/docs/assets/images/cache.png +0 -0
  88. data/docs/assets/images/cache.svg +0 -70
  89. data/docs/assets/images/layer.png +0 -0
  90. data/docs/assets/images/layer.svg +0 -35
  91. data/docs/assets/prism-ruby.min.js +0 -1
  92. data/docs/assets/styles.css +0 -347
  93. data/docs/assets/vue.min.css +0 -1
  94. data/docs/authorization_context.md +0 -92
  95. data/docs/behaviour.md +0 -113
  96. data/docs/caching.md +0 -291
  97. data/docs/controller_action_aliases.md +0 -109
  98. data/docs/custom_lookup_chain.md +0 -48
  99. data/docs/custom_policy.md +0 -53
  100. data/docs/debugging.md +0 -55
  101. data/docs/decorators.md +0 -27
  102. data/docs/favicon.ico +0 -0
  103. data/docs/graphql.md +0 -302
  104. data/docs/i18n.md +0 -44
  105. data/docs/index.html +0 -43
  106. data/docs/instrumentation.md +0 -84
  107. data/docs/lookup_chain.md +0 -22
  108. data/docs/namespaces.md +0 -77
  109. data/docs/non_rails.md +0 -28
  110. data/docs/pre_checks.md +0 -57
  111. data/docs/pundit_migration.md +0 -80
  112. data/docs/quick_start.md +0 -118
  113. data/docs/rails.md +0 -120
  114. data/docs/reasons.md +0 -120
  115. data/docs/scoping.md +0 -255
  116. data/docs/testing.md +0 -390
  117. data/docs/writing_policies.md +0 -107
  118. data/gemfiles/jruby.gemfile +0 -8
  119. data/gemfiles/rails42.gemfile +0 -9
  120. data/gemfiles/rails6.gemfile +0 -8
  121. data/gemfiles/railsmaster.gemfile +0 -6
  122. data/lib/action_policy/ext/string_match.rb +0 -14
  123. data/lib/action_policy/ext/yield_self_then.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa234de7b74f58df4707ec00f9f4d67bee0d89fb721f2b0e4df90627970530e6
4
- data.tar.gz: e6e4ba56d3be720b8ddac3a236f42c84eec2472d04b95213914d89e23d291bf7
3
+ metadata.gz: 911b1f7b929d458ae0bb95eb22fa11ff2a17925d9c797b626664bdad82b7abbc
4
+ data.tar.gz: 69bc6ead609db7cbcdc3d31455e7e17b88bf9037a51a8b1722e414a7e50c41e4
5
5
  SHA512:
6
- metadata.gz: 450572c0987f8d4174ff6c51fdd188d62bd5dfd288b381a593030ee9ef8575df74852b1600706f6dfb1c115fddb9a45e518f03b2dd0a118e653c0a13c0efc05a
7
- data.tar.gz: 1fa6dac85f5fe5f014026d23357c08e9dba0101b68a07a96315275a1ce2aa28762ab82abffbf0ae985a9a277d942de23c521223d485b7acfe1fdceeae9c4179d
6
+ metadata.gz: e3cf8e4bd9347f052a34cee11fad004030ee80d9281c6bbbb9fe99b8f6665b0c611661d6ce3be8578345ef3171ad35d2c38fff8936bdd47efef48bb137a5a415
7
+ data.tar.gz: 63c4444667971ee445b60e2d9ffee89402021151ac730f00063f2066984c1ca75c15ae40b45fbce60ce9c4201826116bb417f6e62dbfd91f96a3f3974e26a458
@@ -2,13 +2,48 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.5.4 (2020-12-09)
6
+
7
+ - Add support for RSpec aliases detection when linting policy specs with `rubocop-rspec` 2.0 ([@pirj][])
8
+
9
+ - Fix `strict_namespace: true` lookup option not finding policies in global namespace ([@Be-ngt-oH][])
10
+
11
+ ## 0.5.0 (2020-09-29)
12
+
13
+ - Move `deny!` / `allow!` to core. ([@palkan][])
14
+
15
+ Now you can call `deny!` and `allow!` in policy rules to fail- or pass-fast.
16
+
17
+ **BREAKING.** Pre-check name is no longer added automatically to failure reasons. You should specify the reason
18
+ explicitly: `deny!(:my_reason)`.
19
+
20
+ - Add `Result#all_details` to return all collected details in a single hash. ([@palkan][])
21
+
22
+ - Add `default` option to lookup and `default_authorization_policy_class` callback to behaviour. ([@palkan][])
23
+
24
+ - Add `skip_verify_authorized!` to Rails controllers integration. ([@palkan][])
25
+
26
+ This method allows you to skip the `verify_authorized` callback dynamically.
27
+
28
+ - **Drop Ruby 2.4 support**. ([@palkan][])
29
+
30
+ - Add `allowance_to` method to authorization behaviour. ([@palkan][])
31
+
32
+ This method is similar to `allowed_to?` but returns an authorization result object.
33
+
34
+ - Support aliases in `allowed_to?` / `check?` calls within policies. ([@palkan][])
35
+
36
+ ## 0.4.5 (2020-07-29)
37
+
38
+ - Add strict_namespace option to lookup chain. (@rainerborene)
39
+
5
40
  ## 0.4.4 (2020-07-07)
6
41
 
7
42
  - Fix symbol lookup with namespaces. ([@palkan][])
8
43
 
9
44
  Fixes [#122](https://github.com/palkan/action_policy/issues/122).
10
45
 
11
- - Separated `#classify`-based and `#camelize`-based symbol lookups. ([Be-ngt-oH][])
46
+ - Separated `#classify`-based and `#camelize`-based symbol lookups. ([@Be-ngt-oH][])
12
47
 
13
48
  Only affects Rails apps. Now lookup for `:users` tries to find `UsersPolicy` first (camelize),
14
49
  and only then search for `UserPolicy` (classify).
@@ -23,12 +58,12 @@ See [PR#118](https://github.com/palkan/action_policy/pull/118).
23
58
 
24
59
  - Add `#cache(*parts, **options) { ... }` method. ([@palkan][])
25
60
 
26
- Allows you to cache anything in policy classes using the Action Policy
27
- cache key generation mechanism.
61
+ Allows you to cache anything in policy classes using the Action Policy
62
+ cache key generation mechanism.
28
63
 
29
64
  - Handle versioned Rails cache keys. ([@palkan][])
30
65
 
31
- Use `#cache_with_version` as a cache key if defined.
66
+ Use `#cache_with_version` as a cache key if defined.
32
67
 
33
68
  ## 0.4.2 (2019-12-13)
34
69
 
@@ -38,274 +73,275 @@ See [PR#118](https://github.com/palkan/action_policy/pull/118).
38
73
 
39
74
  - Add `action_policy.init` instrumentation event. ([@palkan][])
40
75
 
41
- Triggered every time a new policy object is initialized.
76
+ Triggered every time a new policy object is initialized.
42
77
 
43
78
  - Fix policy memoization with explicit context. ([@palkan][])
44
79
 
45
- Explicit context (`authorize! context: {}`) wasn't considered during
46
- policies memoization. Not this is fixed.
80
+ Explicit context (`authorize! context: {}`) wasn't considered during
81
+ policies memoization. Not this is fixed.
47
82
 
48
83
  - Support composed matchers for authorization target testing. ([@palkan][])
49
84
 
50
- Now you can write tests like this:
85
+ Now you can write tests like this:
51
86
 
52
- ```ruby
53
- expect { subject }.to be_authorized_to(:show?, an_instance_of(User))
54
- ```
87
+ ```ruby
88
+ expect { subject }.to be_authorized_to(:show?, an_instance_of(User))
89
+ ```
55
90
 
56
91
  ## 0.3.4 (2019-11-27)
57
92
 
58
93
  - Fix Rails generators. ([@palkan][])
59
94
 
60
- Only invoke install generator if `application_policy.rb` is missing.
61
- Fix hooking into test frameworks.
95
+ Only invoke install generator if `application_policy.rb` is missing.
96
+ Fix hooking into test frameworks.
62
97
 
63
98
  ## 0.3.3 (2019-11-27)
64
99
 
65
100
  - Improve pretty print functionality. ([@palkan][])
66
101
 
67
- Colorize true/false values.
68
- Handle multiline expressions and debug statements (i.e., `binding.pry`).
102
+ Colorize true/false values.
103
+ Handle multiline expressions and debug statements (i.e., `binding.pry`).
69
104
 
70
105
  - Add Rails generators. ([@nicolas-brousse][])
71
106
 
72
- Adds `action_policy:install` and `action_policy:policy MODEL` Rails generators.
107
+ Adds `action_policy:install` and `action_policy:policy MODEL` Rails generators.
73
108
 
74
109
  - Optional authorization target. ([@somenugget][])
75
110
 
76
- Allows making authorization context optional:
111
+ Allows making authorization context optional:
77
112
 
78
- ```ruby
79
- class OptionalRolePolicy < ActionPolicy::Base
80
- authorize :role, optional: true
81
- end
113
+ ```ruby
114
+ class OptionalRolePolicy < ActionPolicy::Base
115
+ authorize :role, optional: true
116
+ end
82
117
 
83
- policy = OptionalRolePolicy.new
84
- policy.role #=> nil
85
- ```
118
+ policy = OptionalRolePolicy.new
119
+ policy.role #=> nil
120
+ ```
86
121
 
87
122
  ## 0.3.2 (2019-05-26) 👶
88
123
 
89
124
  - Fixed thread-safety issues with scoping configs. ([@palkan][])
90
125
 
91
- Fixes [#75](https://github.com/palkan/action_policy/issues/75).
126
+ Fixes [#75](https://github.com/palkan/action_policy/issues/75).
92
127
 
93
128
  ## 0.3.1 (2019-05-30)
94
129
 
95
130
  - Fixed bug with missing implicit target and hash like scoping data. ([@palkan][])
96
131
 
97
- Fixes [#70](https://github.com/palkan/action_policy/issues/70).
132
+ Fixes [#70](https://github.com/palkan/action_policy/issues/70).
98
133
 
99
134
  ## 0.3.0 (2019-04-02)
100
135
 
101
136
  - Added ActiveSupport-based instrumentation. ([@palkan][])
102
137
 
103
- See [PR#4](https://github.com/palkan/action_policy/pull/4)
138
+ See [PR#4](https://github.com/palkan/action_policy/pull/4)
104
139
 
105
140
  - Allow passing authorization context explicitly. ([@palkan][])
106
141
 
107
- Closes [#3](https://github.com/palkan/action_policy/issues/3).
142
+ Closes [#3](https://github.com/palkan/action_policy/issues/3).
108
143
 
109
- Now it's possible to override implicit authorization context
110
- via `context` option:
144
+ Now it's possible to override implicit authorization context
145
+ via `context` option:
111
146
 
112
- ```ruby
113
- authorize! target, to: :show?, context: {user: another_user}
114
- authorized_scope User.all, context: {user: another_user}
115
- ```
147
+ ```ruby
148
+ authorize! target, to: :show?, context: {user: another_user}
149
+ authorized_scope User.all, context: {user: another_user}
150
+ ```
116
151
 
117
152
  - Renamed `#authorized` to `#authorized_scope`. ([@palkan][])
118
153
 
119
- **NOTE:** `#authorized` alias is also available.
154
+ **NOTE:** `#authorized` alias is also available.
120
155
 
121
156
  - Added `Policy#pp(rule)` method to print annotated rule source code. ([@palkan][])
122
157
 
123
- Example (debugging):
158
+ Example (debugging):
124
159
 
125
- ```ruby
126
- def edit?
127
- binding.pry # rubocop:disable Lint/Debugger
128
- (user.name == "John") && (admin? || access_feed?)
129
- end
130
- ```
131
-
132
- ```sh
133
- pry> pp :edit?
134
- MyPolicy#edit?
135
- ↳ (
136
- user.name == "John" #=> false
137
- )
138
- AND
139
- (
140
- admin? #=> false
141
- OR
142
- access_feed? #=> true
143
- )
160
+ ```ruby
161
+ def edit?
162
+ binding.pry # rubocop:disable Lint/Debugger
163
+ (user.name == "John") && (admin? || access_feed?)
164
+ end
165
+ ```
166
+
167
+ ```sh
168
+ pry> pp :edit?
169
+ MyPolicy#edit?
170
+ ↳ (
171
+ user.name == "John" #=> false
172
+ )
173
+ AND
174
+ (
175
+ admin? #=> false
176
+ OR
177
+ access_feed? #=> true
144
178
  )
145
- ```
179
+ )
180
+ ```
146
181
 
147
- See [PR#63](https://github.com/palkan/action_policy/pull/63)
182
+ See [PR#63](https://github.com/palkan/action_policy/pull/63)
148
183
 
149
184
  - Added ability to provide additional failure reasons details. ([@palkan][])
150
185
 
151
- Example:
186
+ Example:
152
187
 
153
- ```ruby
154
- class ApplicantPolicy < ApplicationPolicy
155
- def show?
156
- allowed_to?(:show?, object.stage)
157
- end
188
+ ```ruby
189
+ class ApplicantPolicy < ApplicationPolicy
190
+ def show?
191
+ allowed_to?(:show?, object.stage)
158
192
  end
159
-
160
- class StagePolicy < ApplicationPolicy
161
- def show?
162
- # Add stage title to the failure reason (if any)
163
- # (could be used by client to show more descriptive message)
164
- details[:title] = record.title
165
- # then perform the checks
166
- user.stages.where(id: record.id).exists?
167
- end
193
+ end
194
+
195
+ class StagePolicy < ApplicationPolicy
196
+ def show?
197
+ # Add stage title to the failure reason (if any)
198
+ # (could be used by client to show more descriptive message)
199
+ details[:title] = record.title
200
+ # then perform the checks
201
+ user.stages.where(id: record.id).exists?
168
202
  end
203
+ end
169
204
 
170
- # when accessing the reasons
171
- p ex.result.reasons.details #=> { stage: [{show?: {title: "Onboarding"}] }
172
- ```
205
+ # when accessing the reasons
206
+ p ex.result.reasons.details #=> { stage: [{show?: {title: "Onboarding"}] }
207
+ ```
173
208
 
174
- See https://github.com/palkan/action_policy/pull/58
209
+ See https://github.com/palkan/action_policy/pull/58
175
210
 
176
211
  - Ruby 2.4+ is required. ([@palkan][])
177
212
 
178
213
  - Added RSpec DSL for writing policy specs. ([@palkan])
179
214
 
180
- The goal of this DSL is to reduce the boilerplate when writing
181
- policies specs.
215
+ The goal of this DSL is to reduce the boilerplate when writing
216
+ policies specs.
182
217
 
183
- Example:
218
+ Example:
184
219
 
185
- ```ruby
186
- describe PostPolicy do
187
- let(:user) { build_stubbed :user }
188
- let(:record) { build_stubbed :post, draft: false }
220
+ ```ruby
221
+ describe PostPolicy do
222
+ let(:user) { build_stubbed :user }
223
+ let(:record) { build_stubbed :post, draft: false }
189
224
 
190
- let(:context) { {user: user} }
225
+ let(:context) { {user: user} }
191
226
 
192
- describe_rule :show? do
193
- succeed "when post is published"
227
+ describe_rule :show? do
228
+ succeed "when post is published"
194
229
 
195
- failed "when post is draft" do
196
- before { post.draft = false }
230
+ failed "when post is draft" do
231
+ before { post.draft = false }
197
232
 
198
- succeed "when user is a manager" do
199
- before { user.role = "manager" }
200
- end
233
+ succeed "when user is a manager" do
234
+ before { user.role = "manager" }
201
235
  end
202
236
  end
203
237
  end
204
- ```
238
+ end
239
+ ```
205
240
 
206
241
  - Added I18n support ([@DmitryTsepelev][])
207
242
 
208
- Example:
243
+ Example:
209
244
 
210
- ```ruby
211
- class ApplicationController < ActionController::Base
212
- rescue_from ActionPolicy::Unauthorized do |ex|
213
- p ex.result.message #=> "You do not have access to the stage"
214
- p ex.result.reasons.full_messages #=> ["You do not have access to the stage"]
215
- end
245
+ ```ruby
246
+ class ApplicationController < ActionController::Base
247
+ rescue_from ActionPolicy::Unauthorized do |ex|
248
+ p ex.result.message #=> "You do not have access to the stage"
249
+ p ex.result.reasons.full_messages #=> ["You do not have access to the stage"]
216
250
  end
217
- ```
251
+ end
252
+ ```
218
253
 
219
254
  - Added scope options to scopes. ([@korolvs][])
220
255
 
221
- See [#47](https://github.com/palkan/action_policy/pull/47).
256
+ See [#47](https://github.com/palkan/action_policy/pull/47).
222
257
 
223
- Example:
224
- ```ruby
225
- # users_controller.rb
226
- class UsersController < ApplicationController
227
- def index
228
- @user = authorized(User.all, scope_options: {with_deleted: true})
229
- end
258
+ Example:
259
+
260
+ ```ruby
261
+ # users_controller.rb
262
+ class UsersController < ApplicationController
263
+ def index
264
+ @user = authorized(User.all, scope_options: {with_deleted: true})
230
265
  end
266
+ end
231
267
 
232
- # user_policy.rb
233
- describe UserPolicy < Application do
234
- relation_scope do |relation, with_deleted: false|
235
- rel = some_logic(relation)
236
- with_deleted ? rel.with_deleted : rel
237
- end
268
+ # user_policy.rb
269
+ describe UserPolicy < Application do
270
+ relation_scope do |relation, with_deleted: false|
271
+ rel = some_logic(relation)
272
+ with_deleted ? rel.with_deleted : rel
238
273
  end
239
- ```
274
+ end
275
+ ```
240
276
 
241
277
  - Added Symbol lookup to the lookup chain ([@DmitryTsepelev][])
242
278
 
243
- For instance, lookup will implicitly use `AdminPolicy` in a following case:
279
+ For instance, lookup will implicitly use `AdminPolicy` in a following case:
244
280
 
245
- ```ruby
246
- # admin_controller.rb
247
- class AdminController < ApplicationController
248
- authorize! :admin, to: :update_settings
249
- end
250
- ```
281
+ ```ruby
282
+ # admin_controller.rb
283
+ class AdminController < ApplicationController
284
+ authorize! :admin, to: :update_settings
285
+ end
286
+ ```
251
287
 
252
288
  - Added testing for scopes. ([@palkan][])
253
289
 
254
- Example:
290
+ Example:
255
291
 
256
- ```ruby
257
- # users_controller.rb
258
- class UsersController < ApplicationController
259
- def index
260
- @user = authorized(User.all)
261
- end
292
+ ```ruby
293
+ # users_controller.rb
294
+ class UsersController < ApplicationController
295
+ def index
296
+ @user = authorized(User.all)
262
297
  end
263
-
264
- # users_controller_spec.rb
265
- describe UsersController do
266
- subject { get :index }
267
- it "has authorized scope" do
268
- expect { subject }.to have_authorized_scope(:active_record_relation)
269
- .with(PostPolicy)
270
- end
298
+ end
299
+
300
+ # users_controller_spec.rb
301
+ describe UsersController do
302
+ subject { get :index }
303
+ it "has authorized scope" do
304
+ expect { subject }.to have_authorized_scope(:active_record_relation)
305
+ .with(PostPolicy)
271
306
  end
272
- ```
307
+ end
308
+ ```
273
309
 
274
310
  - Added scoping support. ([@palkan][])
275
311
 
276
- See [#5](https://github.com/palkan/action_policy/issues/5).
312
+ See [#5](https://github.com/palkan/action_policy/issues/5).
277
313
 
278
- By "scoping" we mean an ability to use policies to _scope data_.
314
+ By "scoping" we mean an ability to use policies to _scope data_.
279
315
 
280
- For example, when you want to _scope_ Active Record collections depending
281
- on the current user permissions:
316
+ For example, when you want to _scope_ Active Record collections depending
317
+ on the current user permissions:
282
318
 
283
- ```ruby
284
- class PostsController < ApplicationController
285
- def index
286
- @posts = authorized(Post.all)
287
- end
319
+ ```ruby
320
+ class PostsController < ApplicationController
321
+ def index
322
+ @posts = authorized(Post.all)
288
323
  end
324
+ end
289
325
 
290
- class PostPolicy < ApplicationPolicy
291
- relation_scope do |relation|
292
- next relation if user.admin?
293
- relation.where(user: user)
294
- end
326
+ class PostPolicy < ApplicationPolicy
327
+ relation_scope do |relation|
328
+ next relation if user.admin?
329
+ relation.where(user: user)
295
330
  end
296
- ```
331
+ end
332
+ ```
297
333
 
298
- Action Policy provides a flexible mechanism to apply scopes to anything you want.
334
+ Action Policy provides a flexible mechanism to apply scopes to anything you want.
299
335
 
300
- Read more in [docs](https://actionpolicy.evilmartians.io/).
336
+ Read more in [docs](https://actionpolicy.evilmartians.io/).
301
337
 
302
338
  - Added `#implicit_authorization_target`. ([@palkan][]).
303
339
 
304
- See [#35](https://github.com/palkan/action_policy/issues/35).
340
+ See [#35](https://github.com/palkan/action_policy/issues/35).
305
341
 
306
- Implicit authorization target (defined by `implicit_authorization_target`) is used when no target specified for `authorize!` call.
342
+ Implicit authorization target (defined by `implicit_authorization_target`) is used when no target specified for `authorize!` call.
307
343
 
308
- For example, for Rails controllers integration it's just `controller_name.classify.safe_constantize`.
344
+ For example, for Rails controllers integration it's just `controller_name.classify.safe_constantize`.
309
345
 
310
346
  - Consider `record#policy_name` when looking up for a policy class. ([@palkan][])
311
347
 
@@ -319,21 +355,21 @@ See [PR#118](https://github.com/palkan/action_policy/pull/118).
319
355
 
320
356
  - Add ability to disable per-thread cache and disable it in test env by default. ([@palkan][])
321
357
 
322
- You can control per-thread cache by setting:
358
+ You can control per-thread cache by setting:
323
359
 
324
- ```ruby
325
- ActionPolicy::PerThreadCache.enabled = true # or false
326
- ```
360
+ ```ruby
361
+ ActionPolicy::PerThreadCache.enabled = true # or false
362
+ ```
327
363
 
328
364
  ## 0.2.3 (2018-07-03)
329
365
 
330
366
  - [Fix [#16](https://github.com/palkan/action_policy/issues/16)] Add ability to disable namespace resolution cache. ([@palkan][])
331
367
 
332
- We cache namespaced policy resolution for better performance (it could affect performance when we look up a policy from a deeply nested module context).
368
+ We cache namespaced policy resolution for better performance (it could affect performance when we look up a policy from a deeply nested module context).
333
369
 
334
- It could be disabled by setting `ActionPolicy::LookupChain.namespace_cache_enabled = false`. It's enabled by default unless `RACK_ENV` env var is specified and is not equal to `"production"` (e.g. when `RACK_ENV=test` the cache is disabled).
370
+ It could be disabled by setting `ActionPolicy::LookupChain.namespace_cache_enabled = false`. It's enabled by default unless `RACK_ENV` env var is specified and is not equal to `"production"` (e.g. when `RACK_ENV=test` the cache is disabled).
335
371
 
336
- When using Rails it's enabled only in production mode but could be configured through setting the `config.action_policy.namespace_cache_enabled` parameter.
372
+ When using Rails it's enabled only in production mode but could be configured through setting the `config.action_policy.namespace_cache_enabled` parameter.
337
373
 
338
374
  - [Fix [#18](https://github.com/palkan/action_policy/issues/18)] Clarify documentation around, and fix the way `resolve_rule` resolves rules and rule aliases when subclasses are involved. ([@brendon][])
339
375
 
@@ -341,11 +377,10 @@ See [PR#118](https://github.com/palkan/action_policy/pull/118).
341
377
 
342
378
  - [Fix [#29](https://github.com/palkan/action_policy/issues/29)] Fix loading cache middleware. ([@palkan][])
343
379
 
344
-
345
380
  - Use `send` instead of `public_send` to get the `authorization_context` so that contexts such as
346
381
  `current_user` can be `private` in the controller. ([@brendon][])
347
382
 
348
- - Fix railtie initialisation for Rails < 5. ([@brendon][])
383
+ - Fix railtie initialization for Rails < 5. ([@brendon][])
349
384
 
350
385
  ## 0.2.1 (yanked)
351
386
 
@@ -355,18 +390,18 @@ See [PR#118](https://github.com/palkan/action_policy/pull/118).
355
390
 
356
391
  - Add `reasons.details`. ([@palkan][])
357
392
 
358
- ```ruby
359
- rescue_from ActionPolicy::Unauthorized do |ex|
360
- ex.result.reasons.details #=> { stage: [:show?] }
361
- end
362
- ```
393
+ ```ruby
394
+ rescue_from ActionPolicy::Unauthorized do |ex|
395
+ ex.result.reasons.details #=> { stage: [:show?] }
396
+ end
397
+ ```
363
398
 
364
399
  - Add `ExecutionResult`. ([@palkan][])
365
400
 
366
- ExecutionResult contains all the rule application artifacts: the result (`true` / `false`),
367
- failures reasons.
401
+ ExecutionResult contains all the rule application artifacts: the result (`true` / `false`),
402
+ failures reasons.
368
403
 
369
- This value is now stored in a cache (if any) instead of just the call result (`true` / `false`).
404
+ This value is now stored in a cache (if any) instead of just the call result (`true` / `false`).
370
405
 
371
406
  - Add `Policy.identifier`. ([@palkan][])
372
407
 
@@ -400,3 +435,4 @@ See [PR#118](https://github.com/palkan/action_policy/pull/118).
400
435
  [@nicolas-brousse]: https://github.com/nicolas-brousse
401
436
  [@somenugget]: https://github.com/somenugget
402
437
  [@Be-ngt-oH]: https://github.com/Be-ngt-oH
438
+ [@pirj]: https://github.com/pirj