pundit 2.4.0 → 2.5.1

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -42
  3. data/README.md +31 -1
  4. data/lib/generators/pundit/install/install_generator.rb +3 -1
  5. data/lib/generators/pundit/policy/policy_generator.rb +3 -1
  6. data/lib/generators/rspec/policy_generator.rb +4 -1
  7. data/lib/generators/test_unit/policy_generator.rb +4 -1
  8. data/lib/pundit/authorization.rb +170 -77
  9. data/lib/pundit/cache_store/legacy_store.rb +10 -0
  10. data/lib/pundit/cache_store/null_store.rb +12 -0
  11. data/lib/pundit/cache_store.rb +24 -0
  12. data/lib/pundit/context.rb +89 -26
  13. data/lib/pundit/error.rb +71 -0
  14. data/lib/pundit/helper.rb +16 -0
  15. data/lib/pundit/policy_finder.rb +33 -1
  16. data/lib/pundit/railtie.rb +20 -0
  17. data/lib/pundit/rspec.rb +69 -6
  18. data/lib/pundit/version.rb +2 -1
  19. data/lib/pundit.rb +27 -61
  20. metadata +19 -179
  21. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -20
  22. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -26
  23. data/.github/PULL_REQUEST_TEMPLATE/gem_release_template.md +0 -8
  24. data/.github/pull_request_template.md +0 -9
  25. data/.github/workflows/main.yml +0 -112
  26. data/.github/workflows/push_gem.yml +0 -33
  27. data/.gitignore +0 -19
  28. data/.rubocop.yml +0 -63
  29. data/.yardopts +0 -1
  30. data/CODE_OF_CONDUCT.md +0 -28
  31. data/CONTRIBUTING.md +0 -31
  32. data/Gemfile +0 -8
  33. data/Rakefile +0 -20
  34. data/config/rubocop-rspec.yml +0 -5
  35. data/pundit.gemspec +0 -35
  36. data/spec/authorization_spec.rb +0 -274
  37. data/spec/dsl_spec.rb +0 -30
  38. data/spec/generators_spec.rb +0 -43
  39. data/spec/policies/post_policy_spec.rb +0 -49
  40. data/spec/policy_finder_spec.rb +0 -187
  41. data/spec/pundit_spec.rb +0 -448
  42. data/spec/spec_helper.rb +0 -352
  43. /data/lib/generators/pundit/install/templates/{application_policy.rb → application_policy.rb.tt} +0 -0
  44. /data/lib/generators/pundit/policy/templates/{policy.rb → policy.rb.tt} +0 -0
  45. /data/lib/generators/rspec/templates/{policy_spec.rb → policy_spec.rb.tt} +0 -0
  46. /data/lib/generators/test_unit/templates/{policy_test.rb → policy_test.rb.tt} +0 -0
data/spec/spec_helper.rb DELETED
@@ -1,352 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if ENV["COVERAGE"]
4
- require "simplecov"
5
- SimpleCov.start do
6
- add_filter "/spec/"
7
- end
8
- end
9
-
10
- require "pundit"
11
- require "pundit/rspec"
12
-
13
- require "rack"
14
- require "rack/test"
15
- require "pry"
16
- require "active_support"
17
- require "active_support/core_ext"
18
- require "active_model/naming"
19
- require "action_controller/metal/strong_parameters"
20
-
21
- module InstanceTracking
22
- module ClassMethods
23
- def instances
24
- @instances || 0
25
- end
26
-
27
- attr_writer :instances
28
- end
29
-
30
- def self.prepended(other)
31
- other.extend(ClassMethods)
32
- end
33
-
34
- def initialize(*args, **kwargs, &block)
35
- self.class.instances += 1
36
- super(*args, **kwargs, &block)
37
- end
38
- end
39
-
40
- class BasePolicy
41
- prepend InstanceTracking
42
-
43
- class BaseScope
44
- prepend InstanceTracking
45
-
46
- def initialize(user, scope)
47
- @user = user
48
- @scope = scope
49
- end
50
-
51
- attr_reader :user, :scope
52
- end
53
-
54
- def initialize(user, record)
55
- @user = user
56
- @record = record
57
- end
58
-
59
- attr_reader :user, :record
60
- end
61
-
62
- class PostPolicy < BasePolicy
63
- class Scope < BaseScope
64
- def resolve
65
- scope.published
66
- end
67
- end
68
-
69
- alias post record
70
-
71
- def update?
72
- post.user == user
73
- end
74
-
75
- def destroy?
76
- false
77
- end
78
-
79
- def show?
80
- true
81
- end
82
-
83
- def permitted_attributes
84
- if post.user == user
85
- %i[title votes]
86
- else
87
- [:votes]
88
- end
89
- end
90
-
91
- def permitted_attributes_for_revise
92
- [:body]
93
- end
94
- end
95
-
96
- class Post
97
- def initialize(user = nil)
98
- @user = user
99
- end
100
-
101
- attr_reader :user
102
-
103
- def self.published
104
- :published
105
- end
106
-
107
- def self.read
108
- :read
109
- end
110
-
111
- def to_s
112
- "Post"
113
- end
114
-
115
- def inspect
116
- "#<Post>"
117
- end
118
- end
119
-
120
- module Customer
121
- class Post < ::Post
122
- def model_name
123
- OpenStruct.new(param_key: "customer_post")
124
- end
125
-
126
- def self.policy_class
127
- PostPolicy
128
- end
129
- end
130
- end
131
-
132
- class CommentScope
133
- attr_reader :original_object
134
-
135
- def initialize(original_object)
136
- @original_object = original_object
137
- end
138
-
139
- def ==(other)
140
- original_object == other.original_object
141
- end
142
- end
143
-
144
- class CommentPolicy < BasePolicy
145
- class Scope < BaseScope
146
- def resolve
147
- CommentScope.new(scope)
148
- end
149
- end
150
-
151
- alias comment record
152
- end
153
-
154
- class PublicationPolicy < BasePolicy
155
- class Scope < BaseScope
156
- def resolve
157
- scope.published
158
- end
159
- end
160
-
161
- def create?
162
- true
163
- end
164
- end
165
-
166
- class Comment
167
- extend ActiveModel::Naming
168
- end
169
-
170
- class CommentsRelation
171
- def initialize(empty: false)
172
- @empty = empty
173
- end
174
-
175
- def blank?
176
- @empty
177
- end
178
-
179
- def self.model_name
180
- Comment.model_name
181
- end
182
- end
183
-
184
- class Article; end
185
-
186
- class BlogPolicy < BasePolicy
187
- alias blog record
188
- end
189
-
190
- class Blog; end
191
-
192
- class ArtificialBlog < Blog
193
- def self.policy_class
194
- BlogPolicy
195
- end
196
- end
197
-
198
- class ArticleTagOtherNamePolicy < BasePolicy
199
- def show?
200
- true
201
- end
202
-
203
- def destroy?
204
- false
205
- end
206
-
207
- alias tag record
208
- end
209
-
210
- class ArticleTag
211
- def self.policy_class
212
- ArticleTagOtherNamePolicy
213
- end
214
- end
215
-
216
- class CriteriaPolicy < BasePolicy
217
- alias criteria record
218
- end
219
-
220
- module Project
221
- class CommentPolicy < BasePolicy
222
- class Scope < BaseScope
223
- def resolve
224
- scope
225
- end
226
- end
227
-
228
- def update?
229
- true
230
- end
231
-
232
- alias comment record
233
- end
234
-
235
- class CriteriaPolicy < BasePolicy
236
- alias criteria record
237
- end
238
-
239
- class PostPolicy < BasePolicy
240
- class Scope < BaseScope
241
- def resolve
242
- scope.read
243
- end
244
- end
245
-
246
- alias post record
247
- end
248
-
249
- module Admin
250
- class CommentPolicy < BasePolicy
251
- def update?
252
- true
253
- end
254
-
255
- def destroy?
256
- false
257
- end
258
- end
259
- end
260
- end
261
-
262
- class DenierPolicy < BasePolicy
263
- def update?
264
- false
265
- end
266
- end
267
-
268
- class Controller
269
- include Pundit::Authorization
270
- # Mark protected methods public so they may be called in test
271
- # rubocop:disable Style/AccessModifierDeclarations
272
- public(*Pundit::Authorization.protected_instance_methods)
273
- # rubocop:enable Style/AccessModifierDeclarations
274
-
275
- attr_reader :current_user, :action_name, :params
276
-
277
- def initialize(current_user, action_name, params)
278
- @current_user = current_user
279
- @action_name = action_name
280
- @params = params
281
- end
282
- end
283
-
284
- class NilClassPolicy < BasePolicy
285
- class Scope
286
- def initialize(*)
287
- raise Pundit::NotDefinedError, "Cannot scope NilClass"
288
- end
289
- end
290
-
291
- def show?
292
- false
293
- end
294
-
295
- def destroy?
296
- false
297
- end
298
- end
299
-
300
- class Wiki; end
301
-
302
- class WikiPolicy
303
- class Scope
304
- # deliberate typo method
305
- def initalize; end
306
- end
307
- end
308
-
309
- class Thread
310
- def self.all; end
311
- end
312
-
313
- class ThreadPolicy < BasePolicy
314
- class Scope < BaseScope
315
- def resolve
316
- # deliberate wrong usage of the method
317
- scope.all(:unvalid, :parameters)
318
- end
319
- end
320
- end
321
-
322
- class PostFourFiveSix
323
- def initialize(user)
324
- @user = user
325
- end
326
-
327
- attr_reader(:user)
328
- end
329
-
330
- class CommentFourFiveSix; extend ActiveModel::Naming; end
331
-
332
- module ProjectOneTwoThree
333
- class CommentFourFiveSixPolicy < BasePolicy; end
334
-
335
- class CriteriaFourFiveSixPolicy < BasePolicy; end
336
-
337
- class PostFourFiveSixPolicy < BasePolicy; end
338
-
339
- class TagFourFiveSix
340
- def initialize(user)
341
- @user = user
342
- end
343
-
344
- attr_reader(:user)
345
- end
346
-
347
- class TagFourFiveSixPolicy < BasePolicy; end
348
-
349
- class AvatarFourFiveSix; extend ActiveModel::Naming; end
350
-
351
- class AvatarFourFiveSixPolicy < BasePolicy; end
352
- end