action_policy 0.4.3 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +221 -174
  3. data/LICENSE.txt +1 -1
  4. data/README.md +7 -11
  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/ext/{symbol_classify.rb → symbol_camelize.rb} +6 -6
  38. data/lib/action_policy/i18n.rb +1 -1
  39. data/lib/action_policy/lookup_chain.rb +41 -21
  40. data/lib/action_policy/policy/aliases.rb +7 -12
  41. data/lib/action_policy/policy/authorization.rb +8 -7
  42. data/lib/action_policy/policy/cache.rb +11 -17
  43. data/lib/action_policy/policy/core.rb +25 -12
  44. data/lib/action_policy/policy/defaults.rb +3 -9
  45. data/lib/action_policy/policy/execution_result.rb +3 -9
  46. data/lib/action_policy/policy/pre_check.rb +19 -58
  47. data/lib/action_policy/policy/reasons.rb +32 -20
  48. data/lib/action_policy/policy/scoping.rb +5 -6
  49. data/lib/action_policy/rails/controller.rb +6 -1
  50. data/lib/action_policy/rails/ext/active_record.rb +7 -0
  51. data/lib/action_policy/rails/policy/instrumentation.rb +1 -1
  52. data/lib/action_policy/rspec/be_authorized_to.rb +5 -9
  53. data/lib/action_policy/rspec/dsl.rb +3 -3
  54. data/lib/action_policy/rspec/have_authorized_scope.rb +5 -7
  55. data/lib/action_policy/utils/pretty_print.rb +21 -24
  56. data/lib/action_policy/utils/suggest_message.rb +1 -3
  57. data/lib/action_policy/version.rb +1 -1
  58. data/lib/generators/action_policy/install/templates/{application_policy.rb → application_policy.rb.tt} +1 -1
  59. data/lib/generators/action_policy/policy/policy_generator.rb +4 -1
  60. data/lib/generators/action_policy/policy/templates/{policy.rb → policy.rb.tt} +0 -0
  61. data/lib/generators/rspec/templates/{policy_spec.rb → policy_spec.rb.tt} +0 -0
  62. data/lib/generators/test_unit/templates/{policy_test.rb → policy_test.rb.tt} +0 -0
  63. metadata +55 -119
  64. data/.gitattributes +0 -2
  65. data/.github/FUNDING.yml +0 -1
  66. data/.github/ISSUE_TEMPLATE.md +0 -18
  67. data/.github/PULL_REQUEST_TEMPLATE.md +0 -29
  68. data/.gitignore +0 -15
  69. data/.rubocop.yml +0 -54
  70. data/.tidelift.yml +0 -6
  71. data/.travis.yml +0 -31
  72. data/Gemfile +0 -22
  73. data/Rakefile +0 -27
  74. data/action_policy.gemspec +0 -44
  75. data/benchmarks/namespaced_lookup_cache.rb +0 -71
  76. data/bin/console +0 -14
  77. data/bin/setup +0 -8
  78. data/docs/.nojekyll +0 -0
  79. data/docs/CNAME +0 -1
  80. data/docs/README.md +0 -79
  81. data/docs/_sidebar.md +0 -27
  82. data/docs/aliases.md +0 -122
  83. data/docs/assets/docsify-search.js +0 -364
  84. data/docs/assets/docsify.min.js +0 -3
  85. data/docs/assets/fonts/FiraCode-Medium.woff +0 -0
  86. data/docs/assets/fonts/FiraCode-Regular.woff +0 -0
  87. data/docs/assets/images/banner.png +0 -0
  88. data/docs/assets/images/cache.png +0 -0
  89. data/docs/assets/images/cache.svg +0 -70
  90. data/docs/assets/images/layer.png +0 -0
  91. data/docs/assets/images/layer.svg +0 -35
  92. data/docs/assets/prism-ruby.min.js +0 -1
  93. data/docs/assets/styles.css +0 -347
  94. data/docs/assets/vue.min.css +0 -1
  95. data/docs/authorization_context.md +0 -92
  96. data/docs/behaviour.md +0 -113
  97. data/docs/caching.md +0 -291
  98. data/docs/controller_action_aliases.md +0 -109
  99. data/docs/custom_lookup_chain.md +0 -48
  100. data/docs/custom_policy.md +0 -53
  101. data/docs/debugging.md +0 -55
  102. data/docs/decorators.md +0 -27
  103. data/docs/favicon.ico +0 -0
  104. data/docs/graphql.md +0 -302
  105. data/docs/i18n.md +0 -44
  106. data/docs/index.html +0 -43
  107. data/docs/instrumentation.md +0 -84
  108. data/docs/lookup_chain.md +0 -17
  109. data/docs/namespaces.md +0 -77
  110. data/docs/non_rails.md +0 -28
  111. data/docs/pre_checks.md +0 -57
  112. data/docs/pundit_migration.md +0 -80
  113. data/docs/quick_start.md +0 -118
  114. data/docs/rails.md +0 -120
  115. data/docs/reasons.md +0 -120
  116. data/docs/scoping.md +0 -255
  117. data/docs/testing.md +0 -333
  118. data/docs/writing_policies.md +0 -107
  119. data/gemfiles/jruby.gemfile +0 -8
  120. data/gemfiles/rails42.gemfile +0 -9
  121. data/gemfiles/rails6.gemfile +0 -8
  122. data/gemfiles/railsmaster.gemfile +0 -6
  123. data/lib/action_policy/ext/string_match.rb +0 -14
  124. data/lib/action_policy/ext/yield_self_then.rb +0 -25
@@ -1 +0,0 @@
1
- !function(e){e.languages.ruby=e.languages.extend("clike",{comment:[/#(?!\{[^\r\n]*?\}).*/,/^=begin(?:\r?\n|\r)(?:.*(?:\r?\n|\r))*?=end/m],keyword:/\b(?:alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|protected|private|public|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/});var n={pattern:/#\{[^}]+\}/,inside:{delimiter:{pattern:/^#\{|\}$/,alias:"tag"},rest:e.languages.ruby}};e.languages.insertBefore("ruby","keyword",{regex:[{pattern:/%r([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[gim]{0,3}/,greedy:!0,inside:{interpolation:n}},{pattern:/%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,greedy:!0,inside:{interpolation:n}},{pattern:/%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,greedy:!0,inside:{interpolation:n}},{pattern:/%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,greedy:!0,inside:{interpolation:n}},{pattern:/%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,greedy:!0,inside:{interpolation:n}},{pattern:/(^|[^\/])\/(?!\/)(\[.+?]|\\.|[^\/\\\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,lookbehind:!0,greedy:!0}],variable:/[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,symbol:{pattern:/(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/,lookbehind:!0}}),e.languages.insertBefore("ruby","number",{builtin:/\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|Fixnum|Float|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,constant:/\b[A-Z]\w*(?:[?!]|\b)/}),e.languages.ruby.string=[{pattern:/%[qQiIwWxs]?([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/,greedy:!0,inside:{interpolation:n}},{pattern:/%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,greedy:!0,inside:{interpolation:n}},{pattern:/%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,greedy:!0,inside:{interpolation:n}},{pattern:/%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,greedy:!0,inside:{interpolation:n}},{pattern:/%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,greedy:!0,inside:{interpolation:n}},{pattern:/("|')(?:#\{[^}]+\}|\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0,inside:{interpolation:n}}]}(Prism);
@@ -1,347 +0,0 @@
1
- @font-face {
2
- font-weight: 400;
3
- font-style: normal;
4
- font-family: "Stem Text";
5
- src: url("//cdn.evilmartians.com/front/fonts/subset-StemText-Regular.woff") format("woff");
6
- }
7
- @font-face {
8
- font-weight: 700;
9
- font-style: normal;
10
- font-family: "Stem Text";
11
- src: url("//cdn.evilmartians.com/front/fonts/subset-StemText-Bold.woff") format("woff");
12
- }
13
-
14
- @font-face {
15
- font-family: "Fira Code";
16
- src: url("./fonts/FiraCode-Regular.woff") format("woff");
17
- }
18
-
19
- :root {
20
- --theme-color: #9FA628;
21
- --theme-color-light: rgb(196, 202, 75);
22
- --theme-color-dark: rgba(159, 166, 40, .8);
23
- --theme-color-secondary: #c52f24;
24
- --theme-color-secondary-dark: #980905;
25
- --theme-color-secondary-light: #f64242;
26
-
27
- --text-color-base: #363636;
28
- --text-color-secondary: #646473;
29
- }
30
-
31
- ::selection {
32
- background: var(--theme-color-light);
33
- }
34
-
35
- body {
36
- font-size: 100%;
37
- font: 18px/30px "Stem Text", "Arial", sans-serif;
38
- color: var(--text-color-base);
39
- }
40
-
41
- * {
42
- text-decoration: none !important;
43
- }
44
-
45
- a {
46
- transition: all 0.3s linear;
47
- border-bottom: none !important;
48
- }
49
-
50
- .github-corner svg {
51
- fill: var(--theme-color-secondary);
52
- }
53
-
54
- .chart-container {
55
- padding: 1em 0;
56
- text-align: center;
57
- }
58
-
59
- .sidebar {
60
- border: none;
61
- background-color: var(--theme-color-secondary);
62
- color: #fff;
63
- width: 20%;
64
- display: flex;
65
- flex-direction: column;
66
- }
67
-
68
- body.close .sidebar {
69
- transform: translateX(-100%);
70
- }
71
-
72
- .sidebar .sidebar-nav {
73
- order: 3;
74
- }
75
-
76
- .sidebar ul li a {
77
- color: rgba(255,255,255,0.8);
78
- color: var(--theme-color-light);
79
- font-size: 1rem;
80
- }
81
-
82
- .sidebar ul li.active>a {
83
- border-width: 0.1rem;
84
- }
85
-
86
- .sidebar ul li a:hover {
87
- text-decoration: none;
88
- color: rgba(255,255,255,1);
89
- }
90
-
91
- .sidebar .sidebar-nav ul li.active>a {
92
- color: #fff;
93
- border-right: 0.2rem solid var(--theme-color-secondary-light);
94
- }
95
-
96
- .sidebar > h1 {
97
- order: 1;
98
- font-size: 2rem;
99
- margin-top: 1.5rem;
100
- }
101
-
102
- /* search plugin related */
103
-
104
- .sidebar .search {
105
- order: 2;
106
- margin: 1.5rem 0 0 0;
107
- border: none;
108
- margin-top: 20px;
109
- margin-bottom: 20px;
110
- padding: 6px;
111
- }
112
-
113
- .sidebar .search .input-wrap {
114
- border: none;
115
- position: relative;
116
- }
117
-
118
- .sidebar .search .clear-button.show {
119
- display: block;
120
- position: absolute;
121
- right: 4px;
122
- top: 8px;
123
- }
124
-
125
- body .sidebar-toggle {
126
- background: none;
127
- bottom: 1rem;
128
- left: 1rem;
129
- cursor: pointer;
130
- width: 1.5rem;
131
- height: 1.5rem;
132
- padding: 0;
133
- }
134
-
135
- body .sidebar-toggle span {
136
- transition: all 0.3s linear;
137
- background-color: white;
138
- height: 0.25rem;
139
- width: 1.5rem;
140
- position: absolute;
141
- left: 0;
142
- margin: 0;
143
- transform-origin: 0;
144
- }
145
-
146
- body.close .sidebar-toggle {
147
- width: 1.5rem;
148
- height: 1.5rem;
149
- }
150
-
151
- body.close .sidebar-toggle span {
152
- transform-origin: center;
153
- background-color: var(--theme-color-secondary);
154
- }
155
-
156
- body .sidebar-toggle span:nth-child(1) { top:0; }
157
- body .sidebar-toggle span:nth-child(2) { top:0.65rem; }
158
- body .sidebar-toggle span:nth-child(3) { top:1.25rem; }
159
-
160
- .sidebar-toggle .sidebar-toggle-button:hover { opacity: 1; }
161
-
162
- .sidebar-toggle:hover span:nth-child(1) { transform: rotate(45deg); width: 1.75rem; }
163
- .sidebar-toggle:hover span:nth-child(2) { opacity: 0; }
164
- .sidebar-toggle:hover span:nth-child(3) { transform: rotate(-45deg); width: 1.75rem; }
165
-
166
- .close .sidebar-toggle:hover span:nth-child(1) { transform:rotate(0); width:1.5rem; top:0.65rem; }
167
- .close .sidebar-toggle:hover span:nth-child(2) { opacity: 1; transform:rotate(90deg); }
168
- .close .sidebar-toggle:hover span:nth-child(3) { transform:rotate(0); width:1.5rem; top:0.65rem; }
169
-
170
- th {
171
- text-align: left;
172
- }
173
-
174
- .markdown-section blockquote {
175
- margin: 1em 0;
176
- }
177
-
178
- .markdown-section em,
179
- .markdown-section blockquote {
180
- color: var(--text-color-tertiary);
181
- }
182
-
183
- .anchor {
184
- position: relative;
185
- }
186
-
187
- section.cover .cover-main {
188
- margin: 20vh 20vw;
189
- }
190
-
191
- .app-name-link {
192
- white-space: nowrap;
193
- }
194
-
195
- .app-sub-sidebar li:before {
196
- display: none;
197
- }
198
-
199
- .markdown-section pre,
200
- .markdown-section pre > code {
201
- background-color: #2E2E46;
202
- color: rgba(255,255,255,0.75);
203
- font-size: 1em;
204
- line-height: 1.5;
205
- }
206
-
207
- .markdown-section code {
208
- display: inline-block;
209
- font-family: 'Fira Code', monospace;
210
- }
211
-
212
- .markdown-section pre {
213
- padding: 2rem;
214
- }
215
-
216
- .markdown-section pre > code {
217
- padding: 0;
218
- }
219
-
220
- .markdown-section hr {
221
- border-bottom: 5px solid transparent;
222
- }
223
-
224
-
225
- .markdown-section {
226
- max-width: 75rem;
227
- padding: 1rem 3rem;
228
- }
229
-
230
- .markdown-section ol, .markdown-section p, .markdown-section ul {
231
- line-height: inherit;
232
- }
233
-
234
- .markdown-section code {
235
- color: inherit;
236
- border-radius: 0;
237
- font-size: 0.9em;
238
- padding: 6px 10px;
239
- /* color: #111; */
240
- }
241
-
242
- .markdown-section table {
243
- display: table;
244
- }
245
-
246
- .markdown-section table tr {
247
- border-width: 0.2rem 0;
248
- border-style: solid;
249
- border-color: #F1F1F2;
250
- }
251
-
252
- .markdown-section table tr:nth-child(2n) {
253
- background-color: transparent;
254
- }
255
-
256
- .markdown-section table td,
257
- .markdown-section table th {
258
- border: none;
259
- padding: 1.5rem 0.5rem;
260
- text-align: left;
261
- }
262
-
263
- .markdown-section table td p {
264
- margin: 0;
265
- }
266
-
267
- .markdown-section a {
268
- text-decoration: none;
269
- border-bottom: 0.1rem solid var(--theme-color-light);
270
- transition: all 0.3s ease;
271
- }
272
-
273
- .markdown-section a:hover {
274
- border-color: var(--theme-color);
275
- color: var(--theme-color-dark);
276
- }
277
-
278
-
279
- /* Badges */
280
- .markdown-section > p:first-child > a {
281
- border: none;
282
- }
283
-
284
- .docsify-copy-code-button {
285
- background: var(--theme-color);
286
- }
287
-
288
- .sidebar::-webkit-scrollbar {
289
- width:0;
290
- }
291
-
292
- @media (max-width: 768px) {
293
- aside.sidebar {
294
- width: 300px;
295
- }
296
-
297
- body.close .sidebar {
298
- transform: translateX(300px);
299
- }
300
-
301
- body .sidebar-toggle span {
302
- background-color: var(--theme-color-secondary);
303
- }
304
-
305
-
306
- body.close .sidebar-toggle span {
307
- background-color: white;
308
- }
309
-
310
- .sidebar-toggle:hover span:nth-child(1), .sidebar-toggle:hover span:nth-child(2), .sidebar-toggle:hover span:nth-child(3) {
311
- transform: none;
312
- width: 1.5rem;
313
- opacity: 1;
314
- }
315
-
316
- .close .sidebar-toggle span:nth-child(1), .close .sidebar-toggle:hover span:nth-child(1) {
317
- transform: rotate(45deg);
318
- width: 1.75rem;
319
- top: 0.65rem;
320
- }
321
-
322
- .close .sidebar-toggle span:nth-child(2), .close .sidebar-toggle:hover span:nth-child(2) {
323
- opacity: 0;
324
- }
325
-
326
- .close .sidebar-toggle span:nth-child(3), .close .sidebar-toggle:hover span:nth-child(3) {
327
- transform: rotate(-45deg);
328
- width: 1.75rem;
329
- top: 0.65rem;
330
- }
331
-
332
- body.close .sidebar-toggle {
333
- background: none;
334
- }
335
- }
336
-
337
- @media (min-width: 1200px) {
338
- body {
339
- font-size: 112.5%;
340
- }
341
- }
342
-
343
- @media (min-width: 1400px) {
344
- body {
345
- font-size: 125%;
346
- }
347
- }
@@ -1 +0,0 @@
1
- @import url("https://fonts.googleapis.com/css?family=Roboto+Mono|Source+Sans+Pro:300,400,600");*{-webkit-font-smoothing:antialiased;-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:rgba(0,0,0,0);-webkit-text-size-adjust:none;-webkit-touch-callout:none;box-sizing:border-box}body:not(.ready){overflow:hidden}body:not(.ready) .app-nav,body:not(.ready)>nav,body:not(.ready) [data-cloak]{display:none}div#app{font-size:30px;font-weight:lighter;margin:40vh auto;text-align:center}div#app:empty:before{content:"Loading..."}.emoji{height:1.2rem;vertical-align:middle}.progress{background-color:var(--theme-color,#42b983);height:2px;left:0;position:fixed;right:0;top:0;transition:width .2s,opacity .4s;width:0;z-index:5}.search .search-keyword,.search a:hover{color:var(--theme-color,#42b983)}.search .search-keyword{font-style:normal;font-weight:700}body,html{height:100%}body{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;color:#34495e;font-family:Source Sans Pro,Helvetica Neue,Arial,sans-serif;font-size:15px;letter-spacing:0;margin:0;overflow-x:hidden}img{max-width:100%}a[disabled]{cursor:not-allowed;opacity:.6}kbd{border:1px solid #ccc;border-radius:3px;display:inline-block;font-size:12px!important;line-height:12px;margin-bottom:3px;padding:3px 5px;vertical-align:middle}.task-list-item{list-style-type:none}li input[type=checkbox]{margin:0 .2em .25em -1.6em;vertical-align:middle}.app-nav{margin:25px 60px 0 0;position:absolute;right:0;text-align:right;z-index:2}.app-nav.no-badge{margin-right:25px}.app-nav p{margin:0}.app-nav>a{margin:0 1rem;padding:5px 0}.app-nav li,.app-nav ul{display:inline-block;list-style:none;margin:0}.app-nav a{color:inherit;font-size:16px;text-decoration:none;transition:color .3s}.app-nav a.active,.app-nav a:hover{color:var(--theme-color,#42b983)}.app-nav a.active{border-bottom:2px solid var(--theme-color,#42b983)}.app-nav li{display:inline-block;margin:0 1rem;padding:5px 0;position:relative}.app-nav li ul{background-color:#fff;border:1px solid #ddd;border-bottom-color:#ccc;border-radius:4px;box-sizing:border-box;display:none;max-height:calc(100vh - 61px);overflow-y:auto;padding:10px 0;position:absolute;right:-15px;text-align:left;top:100%;white-space:nowrap}.app-nav li ul li{display:block;font-size:14px;line-height:1rem;margin:0;margin:8px 14px;white-space:nowrap}.app-nav li ul a{display:block;font-size:inherit;margin:0;padding:0}.app-nav li ul a.active{border-bottom:0}.app-nav li:hover ul{display:block}.github-corner{border-bottom:0;position:fixed;right:0;text-decoration:none;top:0;z-index:1}.github-corner:hover .octo-arm{animation:a .56s ease-in-out}.github-corner svg{color:#fff;fill:var(--theme-color,#42b983);height:80px;width:80px}main{display:block;position:relative;width:100vw;height:100%;z-index:0}main.hidden{display:none}.anchor{display:inline-block;text-decoration:none;transition:all .3s}.anchor span{color:#34495e}.anchor:hover{text-decoration:underline}.sidebar{border-right:1px solid rgba(0,0,0,.07);overflow-y:auto;padding:40px 0 0;position:absolute;top:0;bottom:0;left:0;transition:transform .25s ease-out;width:300px;z-index:3}.sidebar>h1{margin:0 auto 1rem;font-size:1.5rem;font-weight:300;text-align:center}.sidebar>h1 a{color:inherit;text-decoration:none}.sidebar>h1 .app-nav{display:block;position:static}.sidebar .sidebar-nav{line-height:2em;padding-bottom:40px}.sidebar li.collapse .app-sub-sidebar{display:none}.sidebar ul{margin:0;padding:0}.sidebar li>p{font-weight:700;margin:0}.sidebar ul,.sidebar ul li{list-style:none}.sidebar ul li a{border-bottom:none;display:block}.sidebar ul li ul{padding-left:20px}.sidebar::-webkit-scrollbar{width:4px}.sidebar::-webkit-scrollbar-thumb{background:transparent;border-radius:4px}.sidebar:hover::-webkit-scrollbar-thumb{background:hsla(0,0%,53%,.4)}.sidebar:hover::-webkit-scrollbar-track{background:hsla(0,0%,53%,.1)}.sidebar-toggle{background-color:transparent;background-color:hsla(0,0%,100%,.8);border:0;outline:none;padding:10px;position:absolute;bottom:0;left:0;text-align:center;transition:opacity .3s;width:284px;z-index:4}.sidebar-toggle .sidebar-toggle-button:hover{opacity:.4}.sidebar-toggle span{background-color:var(--theme-color,#42b983);display:block;margin-bottom:4px;width:16px;height:2px}body.sticky .sidebar,body.sticky .sidebar-toggle{position:fixed}.content{padding-top:60px;position:absolute;top:0;right:0;bottom:0;left:300px;transition:left .25s ease}.markdown-section{margin:0 auto;max-width:800px;padding:30px 15px 40px;position:relative}.markdown-section>*{box-sizing:border-box;font-size:inherit}.markdown-section>:first-child{margin-top:0!important}.markdown-section hr{border:none;border-bottom:1px solid #eee;margin:2em 0}.markdown-section iframe{border:1px solid #eee}.markdown-section table{border-collapse:collapse;border-spacing:0;display:block;margin-bottom:1rem;overflow:auto;width:100%}.markdown-section th{font-weight:700}.markdown-section td,.markdown-section th{border:1px solid #ddd;padding:6px 13px}.markdown-section tr{border-top:1px solid #ccc}.markdown-section p.tip,.markdown-section tr:nth-child(2n){background-color:#f8f8f8}.markdown-section p.tip{border-bottom-right-radius:2px;border-left:4px solid #f66;border-top-right-radius:2px;margin:2em 0;padding:12px 24px 12px 30px;position:relative}.markdown-section p.tip:before{background-color:#f66;border-radius:100%;color:#fff;content:"!";font-family:Dosis,Source Sans Pro,Helvetica Neue,Arial,sans-serif;font-size:14px;font-weight:700;left:-12px;line-height:20px;position:absolute;height:20px;width:20px;text-align:center;top:14px}.markdown-section p.tip code{background-color:#efefef}.markdown-section p.tip em{color:#34495e}.markdown-section p.warn{background:rgba(66,185,131,.1);border-radius:2px;padding:1rem}body.close .sidebar{transform:translateX(-300px)}body.close .sidebar-toggle{width:auto}body.close .content{left:0}@media print{.app-nav,.github-corner,.sidebar,.sidebar-toggle{display:none}}@media screen and (max-width:768px){.github-corner,.sidebar,.sidebar-toggle{position:fixed}.app-nav{margin-top:16px}.app-nav li ul{top:30px}main{height:auto;overflow-x:hidden}.sidebar{left:-300px;transition:transform .25s ease-out}.content{left:0;max-width:100vw;position:static;padding-top:20px;transition:transform .25s ease}.app-nav,.github-corner{transition:transform .25s ease-out}.sidebar-toggle{background-color:transparent;width:auto;padding:30px 30px 10px 10px}body.close .sidebar{transform:translateX(300px)}body.close .sidebar-toggle{background-color:hsla(0,0%,100%,.8);transition:background-color 1s;width:284px;padding:10px}body.close .content{transform:translateX(300px)}body.close .app-nav,body.close .github-corner{display:none}.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:a .56s ease-in-out}}@keyframes a{0%,to{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}section.cover{-ms-flex-align:center;align-items:center;background-position:50%;background-repeat:no-repeat;background-size:cover;height:100vh;display:none}section.cover.show{display:-ms-flexbox;display:flex}section.cover.has-mask .mask{background-color:#fff;opacity:.8;position:absolute;top:0;height:100%;width:100%}section.cover .cover-main{-ms-flex:1;flex:1;margin:-20px 16px 0;text-align:center;z-index:1}section.cover a{color:inherit}section.cover a,section.cover a:hover{text-decoration:none}section.cover p{line-height:1.5rem;margin:1em 0}section.cover h1{color:inherit;font-size:2.5rem;font-weight:300;margin:.625rem 0 2.5rem;position:relative;text-align:center}section.cover h1 a{display:block}section.cover h1 small{bottom:-.4375rem;font-size:1rem;position:absolute}section.cover blockquote{font-size:1.5rem;text-align:center}section.cover ul{line-height:1.8;list-style-type:none;margin:1em auto;max-width:500px;padding:0}section.cover .cover-main>p:last-child a{border:1px solid var(--theme-color,#42b983);border-radius:2rem;box-sizing:border-box;color:var(--theme-color,#42b983);display:inline-block;font-size:1.05rem;letter-spacing:.1rem;margin:.5rem 1rem;padding:.75em 2rem;text-decoration:none;transition:all .15s ease}section.cover .cover-main>p:last-child a:last-child{background-color:var(--theme-color,#42b983);color:#fff}section.cover .cover-main>p:last-child a:last-child:hover{color:inherit;opacity:.8}section.cover .cover-main>p:last-child a:hover{color:inherit}section.cover blockquote>p>a{border-bottom:2px solid var(--theme-color,#42b983);transition:color .3s}section.cover blockquote>p>a:hover{color:var(--theme-color,#42b983)}.sidebar,body{background-color:#fff}.sidebar{color:#364149}.sidebar li{margin:6px 0 6px 15px}.sidebar ul li a{color:#505d6b;font-size:14px;font-weight:400;overflow:hidden;text-decoration:none;text-overflow:ellipsis;white-space:nowrap}.sidebar ul li a:hover{text-decoration:underline}.sidebar ul li ul{padding:0}.sidebar ul li.active>a{border-right:2px solid;color:var(--theme-color,#42b983);font-weight:600}.app-sub-sidebar li:before{content:"-";padding-right:4px;float:left}.markdown-section h1,.markdown-section h2,.markdown-section h3,.markdown-section h4,.markdown-section strong{color:#2c3e50;font-weight:600}.markdown-section a{color:var(--theme-color,#42b983);font-weight:600}.markdown-section h1{font-size:2rem;margin:0 0 1rem}.markdown-section h2{font-size:1.75rem;margin:45px 0 .8rem}.markdown-section h3{font-size:1.5rem;margin:40px 0 .6rem}.markdown-section h4{font-size:1.25rem}.markdown-section h5{font-size:1rem}.markdown-section h6{color:#777;font-size:1rem}.markdown-section figure,.markdown-section p{margin:1.2em 0}.markdown-section ol,.markdown-section p,.markdown-section ul{line-height:1.6rem;word-spacing:.05rem}.markdown-section ol,.markdown-section ul{padding-left:1.5rem}.markdown-section blockquote{border-left:4px solid var(--theme-color,#42b983);color:#858585;margin:2em 0;padding-left:20px}.markdown-section blockquote p{font-weight:600;margin-left:0}.markdown-section iframe{margin:1em 0}.markdown-section em{color:#7f8c8d}.markdown-section code{border-radius:2px;color:#e96900;font-size:.8rem;margin:0 2px;padding:3px 5px;white-space:pre-wrap}.markdown-section code,.markdown-section pre{background-color:#f8f8f8;font-family:Roboto Mono,Monaco,courier,monospace}.markdown-section pre{-moz-osx-font-smoothing:initial;-webkit-font-smoothing:initial;line-height:1.5rem;margin:1.2em 0;overflow:auto;padding:0 1.4rem;position:relative;word-wrap:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#8e908c}.token.namespace{opacity:.7}.token.boolean,.token.number{color:#c76b29}.token.punctuation{color:#525252}.token.property{color:#c08b30}.token.tag{color:#2973b7}.token.string{color:var(--theme-color,#42b983)}.token.selector{color:#6679cc}.token.attr-name{color:#2973b7}.language-css .token.string,.style .token.string,.token.entity,.token.url{color:#22a2c9}.token.attr-value,.token.control,.token.directive,.token.unit{color:var(--theme-color,#42b983)}.token.keyword{color:#e96900}.token.atrule,.token.regex,.token.statement{color:#22a2c9}.token.placeholder,.token.variable{color:#3d8fd1}.token.deleted{text-decoration:line-through}.token.inserted{border-bottom:1px dotted #202746;text-decoration:none}.token.italic{font-style:italic}.token.bold,.token.important{font-weight:700}.token.important{color:#c94922}.token.entity{cursor:help}.markdown-section pre>code{-moz-osx-font-smoothing:initial;-webkit-font-smoothing:initial;background-color:#f8f8f8;border-radius:2px;color:#525252;display:block;font-family:Roboto Mono,Monaco,courier,monospace;font-size:.8rem;line-height:inherit;margin:0 2px;max-width:inherit;overflow:inherit;padding:2.2em 5px;white-space:inherit}.markdown-section code:after,.markdown-section code:before{letter-spacing:.05rem}code .token{-moz-osx-font-smoothing:initial;-webkit-font-smoothing:initial;min-height:1.5rem}pre:after{color:#ccc;content:attr(data-lang);font-size:.6rem;font-weight:600;height:15px;line-height:15px;padding:5px 10px 0;position:absolute;right:0;text-align:right;top:0}
@@ -1,92 +0,0 @@
1
- # Authorization Context
2
-
3
- _Authorization context_ contains information about the acting subject.
4
-
5
- In most cases, it is just a _user_, but sometimes it could be a composition of subjects.
6
-
7
- You must configure authorization context in **two places**: in the policy itself and in the place where you perform the authorization (e.g., controllers).
8
-
9
- By default, `ActionPolicy::Base` includes `user` as authorization context. If you don't need it, you have to [build your own base policy](custom_policy.md).
10
-
11
- To specify additional contexts, you should use the `authorize` method:
12
-
13
- ```ruby
14
- class ApplicationPolicy < ActionPolicy::Base
15
- authorize :account
16
- end
17
- ```
18
-
19
- Now you must provide `account` during policy initialization. When authorization key is missing or equals to `nil`, `ActionPolicy::AuthorizationContextMissing` error is raised.
20
-
21
- **NOTE:** if you want to allow passing `nil` as `account` value, you must add `allow_nil: true` option to `authorize`.
22
- If you want to be able not to pass `account` at all, you must add `optional: true`
23
-
24
- To do that automatically in your `authorize!` and `allowed_to?` calls, you must also configure authorization context. For example, in your controller:
25
-
26
- ```ruby
27
- class ApplicationController < ActionController::Base
28
- # First argument should be the same as in the policy.
29
- # `through` specifies the method name to be called to
30
- # get the required context object
31
- # (equals to the context name itself by default, i.e. `account`)
32
- authorize :account, through: :current_account
33
- end
34
- ```
35
-
36
- ## Nested Policies vs Contexts
37
-
38
- See also: [action_policy#36](https://github.com/palkan/action_policy/issues/36) and [action_policy#37](https://github.com/palkan/action_policy/pull/37)
39
-
40
- When you call another policy from the policy object (e.g. via `allowed_to?` method),
41
- the context of the current policy is passed to the _nested_ policy.
42
-
43
- That means that if the nested policy has a different authorization context, we won't be able
44
- to build it (event if you configure all the required keys in the controller).
45
-
46
- For example:
47
-
48
- ```ruby
49
- class UserPolicy < ActionPolicy::Base
50
- authorize :user
51
-
52
- def show?
53
- allowed_to?(:show?, record.profile)
54
- end
55
- end
56
-
57
- class ProfilePolicy < ActionPolicy::Base
58
- authorize :user, :account
59
- end
60
-
61
- class ApplicationController < ActionController::Base
62
- authorize :user, through: :current_user
63
- authorize :account, through: :current_account
64
- end
65
-
66
- class UsersController < ApplicationController
67
- def show
68
- user = User.find(params[:id])
69
-
70
- authorize! user #=> raises "Missing policy authorization context: account"
71
- end
72
- end
73
- ```
74
-
75
- That means that **all the policies that could be used together MUST share the same set of authorization contexts** (or at least the _parent_ policies contexts must be subsets of the nested policies contexts).
76
-
77
-
78
- ## Explicit context
79
-
80
- You can override the _implicit_ authorization context (generated with `authorize` method) in-place
81
- by passing the `context` option:
82
-
83
- ```ruby
84
- def show
85
- user = User.find(params[:id])
86
-
87
- authorize! user, context: {account: user.account}
88
- end
89
- ```
90
-
91
- **NOTE:** the explictly provided context is merged with the implicit one (i.e. you can specify
92
- only the keys you want to override).
@@ -1,113 +0,0 @@
1
- # Action Policy Behaviour
2
-
3
- Action Policy provides a mixin called `ActionPolicy::Behaviour` which adds authorization methods to your classes.
4
-
5
- ## Usage
6
-
7
- Let's make our custom _service_ object aware of authorization:
8
-
9
- ```ruby
10
- class PostUpdateAction
11
- # First, we should include the behaviour
12
- include ActionPolicy::Behaviour
13
-
14
- # Secondly, provide authorization subject (performer)
15
- authorize :user
16
-
17
- attr_reader :user
18
-
19
- def initialize(user)
20
- @user = user
21
- end
22
-
23
- def call(post, params)
24
- # Now we can use authorization methods
25
- authorize! post, to: :update?
26
-
27
- post.update!(params)
28
- end
29
- end
30
- ```
31
-
32
- `ActionPolicy::Behaviour` provides `authorize` class-level method to configure [authorization context](authorization_context.md) and the instance-level methods: `authorize!`, `allowed_to?` and `authorized`:
33
-
34
- ### `authorize!`
35
-
36
- This is a _guard-method_ which raises an `ActionPolicy::Unauthorized` exception
37
- if authorization failed (i.e. policy rule returns false):
38
-
39
- ```ruby
40
- # `to` is a name of the policy rule to apply
41
- authorize! post, to: :update?
42
- ```
43
-
44
- ### `allowed_to?`
45
-
46
- This is a _predicate_ version of `authorize!`: it returns true if authorization succeed and false otherwise:
47
-
48
- ```ruby
49
- # the first argument is the rule to apply
50
- # the second one is the target
51
- if allowed_to?(:edit?, post)
52
- # ...
53
- end
54
- ```
55
-
56
- ### `authorized`
57
-
58
- See [scoping](./scoping.md) docs.
59
-
60
- ## Policy lookup
61
-
62
- All three instance methods (`authorize!`, `allowed_to?`, `authorized`) uses the same
63
- `policy_for` to lookup a policy class for authorization target. So, you can provide additional options to control the policy lookup process:
64
-
65
- - Explicitly specify policy class using `with` option:
66
-
67
- ```ruby
68
- allowed_to?(:edit?, post, with: SpecialPostPolicy)
69
- ```
70
-
71
- - Provide a [namespace](./namespaces.md):
72
-
73
- ```ruby
74
- # Would try to lookup Admin::PostPolicy first
75
- authorize! post, to: :destroy?, namespace: Admin
76
- ```
77
-
78
- ## Implicit authorization target
79
-
80
- You can omit the authorization target for all the methods by defining an _implicit authorization target_:
81
-
82
- ```ruby
83
- class PostActions
84
- include ActionPolicy::Behaviour
85
-
86
- authorize :user
87
-
88
- attr_reader :user, :post
89
-
90
- def initialize(user, post)
91
- @user = user
92
- @post = post
93
- end
94
-
95
- def update(params)
96
- # post is used here implicitly as a target
97
- authorize! to: :update
98
-
99
- post.update!(params)
100
- end
101
-
102
- def destroy
103
- # post is used here implicitly as a target
104
- authorize! to: :destroy
105
-
106
- post.destroy!
107
- end
108
-
109
- def implicit_authorization_target
110
- post
111
- end
112
- end
113
- ```