cancancan 1.17.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/cancancan.gemspec +4 -6
  3. data/lib/cancan.rb +2 -11
  4. data/lib/cancan/ability.rb +1 -1
  5. data/lib/cancan/controller_additions.rb +3 -24
  6. data/lib/cancan/controller_resource.rb +9 -25
  7. data/lib/cancan/matchers.rb +7 -1
  8. data/lib/cancan/model_adapters/active_record_4_adapter.rb +1 -3
  9. data/lib/cancan/model_adapters/active_record_adapter.rb +2 -2
  10. data/lib/cancan/rule.rb +2 -2
  11. data/lib/cancan/version.rb +1 -1
  12. metadata +22 -69
  13. data/.gitignore +0 -15
  14. data/.rspec +0 -1
  15. data/.rubocop.yml +0 -39
  16. data/.rubocop_todo.yml +0 -54
  17. data/.travis.yml +0 -39
  18. data/Appraisals +0 -105
  19. data/CHANGELOG.rdoc +0 -536
  20. data/CONTRIBUTING.md +0 -23
  21. data/Gemfile +0 -3
  22. data/LICENSE +0 -22
  23. data/README.md +0 -234
  24. data/Rakefile +0 -13
  25. data/gemfiles/activerecord_3.2.gemfile +0 -18
  26. data/gemfiles/activerecord_4.0.gemfile +0 -19
  27. data/gemfiles/activerecord_4.1.gemfile +0 -19
  28. data/gemfiles/activerecord_4.2.gemfile +0 -21
  29. data/gemfiles/activerecord_5.0.gemfile +0 -20
  30. data/gemfiles/mongoid_2.x.gemfile +0 -18
  31. data/gemfiles/sequel_3.x.gemfile +0 -18
  32. data/lib/cancan/inherited_resource.rb +0 -20
  33. data/lib/cancan/model_adapters/active_record_3_adapter.rb +0 -16
  34. data/lib/cancan/model_adapters/mongoid_adapter.rb +0 -80
  35. data/lib/cancan/model_adapters/sequel_adapter.rb +0 -87
  36. data/spec/README.rdoc +0 -27
  37. data/spec/cancan/ability_spec.rb +0 -553
  38. data/spec/cancan/controller_additions_spec.rb +0 -164
  39. data/spec/cancan/controller_resource_spec.rb +0 -645
  40. data/spec/cancan/exceptions_spec.rb +0 -58
  41. data/spec/cancan/inherited_resource_spec.rb +0 -71
  42. data/spec/cancan/matchers_spec.rb +0 -29
  43. data/spec/cancan/model_adapters/active_record_4_adapter_spec.rb +0 -160
  44. data/spec/cancan/model_adapters/active_record_adapter_spec.rb +0 -415
  45. data/spec/cancan/model_adapters/default_adapter_spec.rb +0 -7
  46. data/spec/cancan/model_adapters/mongoid_adapter_spec.rb +0 -246
  47. data/spec/cancan/model_adapters/sequel_adapter_spec.rb +0 -129
  48. data/spec/cancan/rule_spec.rb +0 -52
  49. data/spec/matchers.rb +0 -13
  50. data/spec/spec.opts +0 -2
  51. data/spec/spec_helper.rb +0 -27
  52. data/spec/support/ability.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 418d49100740136f143204714c01555ca5787a1e
4
- data.tar.gz: 2631fb854865b69ab8720023eb2e50289f680603
3
+ metadata.gz: cf0604650f3cc8651f5960cedd2e857a023947d6
4
+ data.tar.gz: 1c4e56a7fa9915ef901f3e042645a2064edcfcc8
5
5
  SHA512:
6
- metadata.gz: 2ac85e5511555021a0841efbdb82eb0eccf5d3145d8e53de3df189484f5a7eb34796224912556c553ead44d75aa0d496838fe73c8db25a10ede4d889c0ab115f
7
- data.tar.gz: 34dc9609930ec647cf36f7ce5fe3caa8663720ba4f8d871df3333ad41e42177aac79f383a932f6189ea05c02b2060f6a44724cd1cd27c5ecd574886742d6b303
6
+ metadata.gz: a3ec244830eb89b049fc102b85df7978b9162c52c4661b380fda28026e1af3c3edf85518f19b7eae5de528546980b61c95d4054d1c7a6d962dd4385cfe5bcfa7
7
+ data.tar.gz: 5a17a987ae0a3c8eaee50bff9b958fa66a572c88d1b460f77de7563a2a7a7ae178f587f3f790a39514a6661d9ef9f2845c90e19249197a55b6a3f7dc61c061cc
data/cancancan.gemspec CHANGED
@@ -15,16 +15,14 @@ Gem::Specification.new do |s|
15
15
  s.platform = Gem::Platform::RUBY
16
16
  s.license = 'MIT'
17
17
 
18
- s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
- s.test_files = `git ls-files -- Appraisals {spec,features,gemfiles}/*`.split($INPUT_RECORD_SEPARATOR)
20
- s.executables = `git ls-files -- bin/*`.split($INPUT_RECORD_SEPARATOR).map { |f| File.basename(f) }
18
+ s.files = `git ls-files lib init.rb cancancan.gemspec`.split($INPUT_RECORD_SEPARATOR)
21
19
  s.require_paths = ['lib']
22
20
 
23
21
  s.required_ruby_version = '>= 2.0.0'
24
22
 
25
23
  s.add_development_dependency 'bundler', '~> 1.3'
26
24
  s.add_development_dependency 'rubocop', '~> 0.46'
27
- s.add_development_dependency 'rake', '~> 10.1.1'
28
- s.add_development_dependency 'rspec', '~> 3.2.0'
29
- s.add_development_dependency 'appraisal', '>= 2.0.0'
25
+ s.add_development_dependency 'rake', '~> 10.1', '>= 10.1.1'
26
+ s.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
27
+ s.add_development_dependency 'appraisal', '~> 2.0', '>= 2.0.0'
30
28
  end
data/lib/cancan.rb CHANGED
@@ -5,20 +5,11 @@ require 'cancan/controller_resource'
5
5
  require 'cancan/controller_additions'
6
6
  require 'cancan/model_additions'
7
7
  require 'cancan/exceptions'
8
- require 'cancan/inherited_resource'
9
8
 
10
9
  require 'cancan/model_adapters/abstract_adapter'
11
10
  require 'cancan/model_adapters/default_adapter'
12
11
 
13
12
  if defined? ActiveRecord
14
- require 'cancan/model_adapters/active_record_adapter'
15
- if ActiveRecord.respond_to?(:version) &&
16
- ActiveRecord.version >= Gem::Version.new('4')
17
- require 'cancan/model_adapters/active_record_4_adapter'
18
- else
19
- require 'cancan/model_adapters/active_record_3_adapter'
20
- end
13
+ require 'cancan/model_adapters/active_record_adapter'
14
+ require 'cancan/model_adapters/active_record_4_adapter'
21
15
  end
22
-
23
- require 'cancan/model_adapters/mongoid_adapter' if defined?(Mongoid) && defined?(Mongoid::Document)
24
- require 'cancan/model_adapters/sequel_adapter' if defined? Sequel
@@ -414,7 +414,7 @@ module CanCan
414
414
 
415
415
  def default_alias_actions
416
416
  {
417
- read: [:index, :show],
417
+ read: %i[index show],
418
418
  create: [:new],
419
419
  update: [:edit]
420
420
  }
@@ -256,8 +256,6 @@ module CanCan
256
256
  # check_authorization :unless => :devise_controller?
257
257
  #
258
258
  def check_authorization(options = {})
259
- method_name = active_support_4? ? :after_action : :after_filter
260
-
261
259
  block = proc do |controller|
262
260
  next if controller.instance_variable_defined?(:@_authorized)
263
261
  next if options[:if] && !controller.send(options[:if])
@@ -267,7 +265,7 @@ module CanCan
267
265
  'Add skip_authorization_check to bypass this check.'
268
266
  end
269
267
 
270
- send(method_name, options.slice(:only, :except), &block)
268
+ send(:after_action, options.slice(:only, :except), &block)
271
269
  end
272
270
 
273
271
  # Call this in the class of a controller to skip the check_authorization behavior on the actions.
@@ -278,32 +276,17 @@ module CanCan
278
276
  #
279
277
  # Any arguments are passed to the +before_action+ it triggers.
280
278
  def skip_authorization_check(*args)
281
- method_name = active_support_4? ? :before_action : :before_filter
282
279
  block = proc { |controller| controller.instance_variable_set(:@_authorized, true) }
283
- send(method_name, *args, &block)
284
- end
285
-
286
- def skip_authorization(*_args)
287
- raise ImplementationRemoved,
288
- 'The CanCan skip_authorization method has been renamed to skip_authorization_check. '\
289
- 'Please update your code.'
280
+ send(:before_action, *args, &block)
290
281
  end
291
282
 
292
283
  def cancan_resource_class
293
- if ancestors.map(&:to_s).include? 'InheritedResources::Actions'
294
- InheritedResource
295
- else
296
- ControllerResource
297
- end
284
+ ControllerResource
298
285
  end
299
286
 
300
287
  def cancan_skipper
301
288
  @_cancan_skipper ||= { authorize: {}, load: {} }
302
289
  end
303
-
304
- def active_support_4?
305
- ActiveSupport.respond_to?(:version) && ActiveSupport.version >= Gem::Version.new('4')
306
- end
307
290
  end
308
291
 
309
292
  def self.included(base)
@@ -352,10 +335,6 @@ module CanCan
352
335
  current_ability.authorize!(*args)
353
336
  end
354
337
 
355
- def unauthorized!(_message = nil)
356
- raise ImplementationRemoved, 'The unauthorized! method has been removed from CanCan, use authorize! instead.'
357
- end
358
-
359
338
  # Creates and returns the current user's ability and caches it. If you
360
339
  # want to override how the Ability is defined then this is the place.
361
340
  # Just define the method in the controller to change behavior.
@@ -14,11 +14,7 @@ module CanCan
14
14
  end
15
15
 
16
16
  def self.before_callback_name(options)
17
- if ActiveSupport.respond_to?(:version) && ActiveSupport.version >= Gem::Version.new('4')
18
- options.delete(:prepend) ? :prepend_before_action : :before_action
19
- else
20
- options.delete(:prepend) ? :prepend_before_filter : :before_filter
21
- end
17
+ options.delete(:prepend) ? :prepend_before_action : :before_action
22
18
  end
23
19
 
24
20
  def initialize(controller, *args)
@@ -26,12 +22,6 @@ module CanCan
26
22
  @params = controller.params
27
23
  @options = args.extract_options!
28
24
  @name = args.first
29
- nested_err = 'The :nested option is no longer supported, instead use :through with separate load/authorize call.'
30
- raise CanCan::ImplementationRemoved, nested_err if @options[:nested]
31
- name_err = 'The :name option is no longer supported, instead pass the name as the first argument.'
32
- raise CanCan::ImplementationRemoved, name_err if @options[:name]
33
- resource_err = 'The :resource option has been renamed back to :class, use false if no class.'
34
- raise CanCan::ImplementationRemoved, resource_err if @options[:resource]
35
25
  end
36
26
 
37
27
  def load_and_authorize_resource
@@ -138,7 +128,7 @@ module CanCan
138
128
  end
139
129
 
140
130
  def id_param
141
- @params[id_param_key].to_s if @params[id_param_key]
131
+ @params[id_param_key].to_s if @params[id_param_key].present?
142
132
  end
143
133
 
144
134
  def id_param_key
@@ -205,13 +195,11 @@ module CanCan
205
195
 
206
196
  def resource_base_through
207
197
  if parent_resource
208
- base = if @options[:singleton]
209
- resource_class
210
- else
211
- parent_resource.send(@options[:through_association] || name.to_s.pluralize)
212
- end
213
- base = base.scoped if base.respond_to?(:scoped) && active_record_3?
214
- base
198
+ if @options[:singleton]
199
+ resource_class
200
+ else
201
+ parent_resource.send(@options[:through_association] || name.to_s.pluralize)
202
+ end
215
203
  elsif @options[:shallow]
216
204
  resource_class
217
205
  else
@@ -220,10 +208,6 @@ module CanCan
220
208
  end
221
209
  end
222
210
 
223
- def active_record_3?
224
- defined?(ActiveRecord) && ActiveRecord::VERSION::MAJOR == 3
225
- end
226
-
227
211
  def parent_name
228
212
  @options[:through] && [@options[:through]].flatten.detect { |i| fetch_parent(i) }
229
213
  end
@@ -313,11 +297,11 @@ module CanCan
313
297
  end
314
298
 
315
299
  def new_actions
316
- [:new, :create] + Array(@options[:new])
300
+ %i[new create] + Array(@options[:new])
317
301
  end
318
302
 
319
303
  def save_actions
320
- [:create, :update]
304
+ %i[create update]
321
305
  end
322
306
 
323
307
  private
@@ -9,7 +9,13 @@ end
9
9
 
10
10
  Kernel.const_get(rspec_module)::Matchers.define :be_able_to do |*args|
11
11
  match do |ability|
12
- ability.can?(*args)
12
+ actions = args.first
13
+ if actions.is_a? Array
14
+ break false if actions.empty?
15
+ actions.all? { |action| ability.can?(action, *args[1..-1]) }
16
+ else
17
+ ability.can?(*args)
18
+ end
13
19
  end
14
20
 
15
21
  # Check that RSpec is < 2.99
@@ -8,9 +8,7 @@ module CanCan
8
8
 
9
9
  # TODO: this should be private
10
10
  def self.override_condition_matching?(subject, name, _value)
11
- # ActiveRecord introduced enums in version 4.1.
12
- (ActiveRecord::VERSION::MAJOR > 4 || ActiveRecord::VERSION::MINOR >= 1) &&
13
- subject.class.defined_enums.include?(name.to_s)
11
+ subject.class.defined_enums.include?(name.to_s)
14
12
  end
15
13
 
16
14
  # TODO: this should be private
@@ -144,6 +144,6 @@ module CanCan
144
144
  end
145
145
  end
146
146
 
147
- ActiveRecord::Base.class_eval do
148
- include CanCan::ModelAdditions
147
+ ActiveSupport.on_load(:active_record) do
148
+ send :include, CanCan::ModelAdditions
149
149
  end
data/lib/cancan/rule.rb CHANGED
@@ -16,8 +16,8 @@ module CanCan
16
16
  raise Error, both_block_and_hash_error if conditions.is_a?(Hash) && block
17
17
  @match_all = action.nil? && subject.nil?
18
18
  @base_behavior = base_behavior
19
- @actions = [action].flatten
20
- @subjects = [subject].flatten
19
+ @actions = Array(action)
20
+ @subjects = Array(subject)
21
21
  @conditions = conditions || {}
22
22
  @block = block
23
23
  end
@@ -1,3 +1,3 @@
1
1
  module CanCan
2
- VERSION = '1.17.0'.freeze
2
+ VERSION = '2.0.0.rc1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cancancan
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.0
4
+ version: 2.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi (Renuo AG)
@@ -46,6 +46,9 @@ dependencies:
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '10.1'
51
+ - - ">="
49
52
  - !ruby/object:Gem::Version
50
53
  version: 10.1.1
51
54
  type: :development
@@ -53,6 +56,9 @@ dependencies:
53
56
  version_requirements: !ruby/object:Gem::Requirement
54
57
  requirements:
55
58
  - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.1'
61
+ - - ">="
56
62
  - !ruby/object:Gem::Version
57
63
  version: 10.1.1
58
64
  - !ruby/object:Gem::Dependency
@@ -60,6 +66,9 @@ dependencies:
60
66
  requirement: !ruby/object:Gem::Requirement
61
67
  requirements:
62
68
  - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.2'
71
+ - - ">="
63
72
  - !ruby/object:Gem::Version
64
73
  version: 3.2.0
65
74
  type: :development
@@ -67,12 +76,18 @@ dependencies:
67
76
  version_requirements: !ruby/object:Gem::Requirement
68
77
  requirements:
69
78
  - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '3.2'
81
+ - - ">="
70
82
  - !ruby/object:Gem::Version
71
83
  version: 3.2.0
72
84
  - !ruby/object:Gem::Dependency
73
85
  name: appraisal
74
86
  requirement: !ruby/object:Gem::Requirement
75
87
  requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '2.0'
76
91
  - - ">="
77
92
  - !ruby/object:Gem::Version
78
93
  version: 2.0.0
@@ -80,6 +95,9 @@ dependencies:
80
95
  prerelease: false
81
96
  version_requirements: !ruby/object:Gem::Requirement
82
97
  requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '2.0'
83
101
  - - ">="
84
102
  - !ruby/object:Gem::Version
85
103
  version: 2.0.0
@@ -90,41 +108,18 @@ executables: []
90
108
  extensions: []
91
109
  extra_rdoc_files: []
92
110
  files:
93
- - ".gitignore"
94
- - ".rspec"
95
- - ".rubocop.yml"
96
- - ".rubocop_todo.yml"
97
- - ".travis.yml"
98
- - Appraisals
99
- - CHANGELOG.rdoc
100
- - CONTRIBUTING.md
101
- - Gemfile
102
- - LICENSE
103
- - README.md
104
- - Rakefile
105
111
  - cancancan.gemspec
106
- - gemfiles/activerecord_3.2.gemfile
107
- - gemfiles/activerecord_4.0.gemfile
108
- - gemfiles/activerecord_4.1.gemfile
109
- - gemfiles/activerecord_4.2.gemfile
110
- - gemfiles/activerecord_5.0.gemfile
111
- - gemfiles/mongoid_2.x.gemfile
112
- - gemfiles/sequel_3.x.gemfile
113
112
  - init.rb
114
113
  - lib/cancan.rb
115
114
  - lib/cancan/ability.rb
116
115
  - lib/cancan/controller_additions.rb
117
116
  - lib/cancan/controller_resource.rb
118
117
  - lib/cancan/exceptions.rb
119
- - lib/cancan/inherited_resource.rb
120
118
  - lib/cancan/matchers.rb
121
119
  - lib/cancan/model_adapters/abstract_adapter.rb
122
- - lib/cancan/model_adapters/active_record_3_adapter.rb
123
120
  - lib/cancan/model_adapters/active_record_4_adapter.rb
124
121
  - lib/cancan/model_adapters/active_record_adapter.rb
125
122
  - lib/cancan/model_adapters/default_adapter.rb
126
- - lib/cancan/model_adapters/mongoid_adapter.rb
127
- - lib/cancan/model_adapters/sequel_adapter.rb
128
123
  - lib/cancan/model_additions.rb
129
124
  - lib/cancan/rule.rb
130
125
  - lib/cancan/version.rb
@@ -132,23 +127,6 @@ files:
132
127
  - lib/generators/cancan/ability/USAGE
133
128
  - lib/generators/cancan/ability/ability_generator.rb
134
129
  - lib/generators/cancan/ability/templates/ability.rb
135
- - spec/README.rdoc
136
- - spec/cancan/ability_spec.rb
137
- - spec/cancan/controller_additions_spec.rb
138
- - spec/cancan/controller_resource_spec.rb
139
- - spec/cancan/exceptions_spec.rb
140
- - spec/cancan/inherited_resource_spec.rb
141
- - spec/cancan/matchers_spec.rb
142
- - spec/cancan/model_adapters/active_record_4_adapter_spec.rb
143
- - spec/cancan/model_adapters/active_record_adapter_spec.rb
144
- - spec/cancan/model_adapters/default_adapter_spec.rb
145
- - spec/cancan/model_adapters/mongoid_adapter_spec.rb
146
- - spec/cancan/model_adapters/sequel_adapter_spec.rb
147
- - spec/cancan/rule_spec.rb
148
- - spec/matchers.rb
149
- - spec/spec.opts
150
- - spec/spec_helper.rb
151
- - spec/support/ability.rb
152
130
  homepage: https://github.com/CanCanCommunity/cancancan
153
131
  licenses:
154
132
  - MIT
@@ -164,38 +142,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
142
  version: 2.0.0
165
143
  required_rubygems_version: !ruby/object:Gem::Requirement
166
144
  requirements:
167
- - - ">="
145
+ - - ">"
168
146
  - !ruby/object:Gem::Version
169
- version: '0'
147
+ version: 1.3.1
170
148
  requirements: []
171
149
  rubyforge_project:
172
150
  rubygems_version: 2.5.2
173
151
  signing_key:
174
152
  specification_version: 4
175
153
  summary: Simple authorization solution for Rails.
176
- test_files:
177
- - Appraisals
178
- - gemfiles/activerecord_3.2.gemfile
179
- - gemfiles/activerecord_4.0.gemfile
180
- - gemfiles/activerecord_4.1.gemfile
181
- - gemfiles/activerecord_4.2.gemfile
182
- - gemfiles/activerecord_5.0.gemfile
183
- - gemfiles/mongoid_2.x.gemfile
184
- - gemfiles/sequel_3.x.gemfile
185
- - spec/README.rdoc
186
- - spec/cancan/ability_spec.rb
187
- - spec/cancan/controller_additions_spec.rb
188
- - spec/cancan/controller_resource_spec.rb
189
- - spec/cancan/exceptions_spec.rb
190
- - spec/cancan/inherited_resource_spec.rb
191
- - spec/cancan/matchers_spec.rb
192
- - spec/cancan/model_adapters/active_record_4_adapter_spec.rb
193
- - spec/cancan/model_adapters/active_record_adapter_spec.rb
194
- - spec/cancan/model_adapters/default_adapter_spec.rb
195
- - spec/cancan/model_adapters/mongoid_adapter_spec.rb
196
- - spec/cancan/model_adapters/sequel_adapter_spec.rb
197
- - spec/cancan/rule_spec.rb
198
- - spec/matchers.rb
199
- - spec/spec.opts
200
- - spec/spec_helper.rb
201
- - spec/support/ability.rb
154
+ test_files: []
data/.gitignore DELETED
@@ -1,15 +0,0 @@
1
- .DS_Store
2
- .idea/*
3
- *.swp
4
- **/*.swp
5
- *.gem
6
- .bundle
7
-
8
- gemfiles/*.lock
9
- Gemfile.lock
10
-
11
- .rvmrc
12
- .rbenv-version
13
- .ruby-version
14
- .ruby-gemset
15
- /tmp