cancancan 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f912e7e8ba7143a52b467949b374103edb0aae0b8b3dcbea4157400b6a70e7d6
4
- data.tar.gz: 604a95ca8d9a794386810ad68a98eec86d1b6a8b73c07d64c0b8706ec5c52fa6
3
+ metadata.gz: d109d94a089119e1183b6ed77e78316e212b3d78506b8ed10aabb1e8e0e090ce
4
+ data.tar.gz: '09d6acb72b55c2892be6d7c614bbf9a55b4f60ca3eee1e6aa898e1213e0e807d'
5
5
  SHA512:
6
- metadata.gz: 5988dd5e020a13b020769f632a4c780f2b3a401c6064f9d4b1da7f4d3570cf18d52be603ed2fd55059b88f5b06e4dd6fb6708e893ff899e2ffbd793eddfec07a
7
- data.tar.gz: 5c2338a84835d7d828739984925bd2906f044d8b0c0355a0a62a8fe763e2f203e579e4909ba37fdbf8f30bce26e36790a47793ab056fb39e7a6c1e683ce9e486
6
+ metadata.gz: c708dbbefc7a0d120cf9dbacb3d478e2a6155dbb72800563be83b2fced563118b79454a6d9f6eb372bad88f7c4835ebefa636058d055f161b395a6076d154781
7
+ data.tar.gz: 269ff0d42f16aff0db8882473364fee508504c5f8dd5e4e8d271810d7420e76bebf3c64a16b58a81ed2754e9b1c7fdb9f576c5bc3804c6d26d5b19386e3e9f8e
@@ -302,7 +302,7 @@ module CanCan
302
302
 
303
303
  def alternative_subjects(subject)
304
304
  subject = subject.class unless subject.is_a?(Module)
305
- if subject.respond_to?(:subclasses) && subject < ActiveRecord::Base
305
+ if subject.respond_to?(:subclasses) && defined?(ActiveRecord::Base) && subject < ActiveRecord::Base
306
306
  [:all, *(subject.ancestors + subject.subclasses), subject.class.to_s]
307
307
  else
308
308
  [:all, *subject.ancestors, subject.class.to_s]
@@ -3,7 +3,7 @@
3
3
  module CanCan
4
4
  def self.valid_accessible_by_strategies
5
5
  strategies = [:left_join]
6
- strategies << :subquery unless CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0')
6
+ strategies << :subquery unless does_not_support_subquery_strategy?
7
7
  strategies
8
8
  end
9
9
 
@@ -25,7 +25,7 @@ module CanCan
25
25
  end
26
26
 
27
27
  def self.default_accessible_by_strategy
28
- if CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0')
28
+ if does_not_support_subquery_strategy?
29
29
  # see https://github.com/CanCanCommunity/cancancan/pull/655 for where this was added
30
30
  # the `subquery` strategy (from https://github.com/CanCanCommunity/cancancan/pull/619
31
31
  # only works in Rails 5 and higher
@@ -40,10 +40,15 @@ module CanCan
40
40
  raise ArgumentError, "accessible_by_strategy must be one of #{valid_accessible_by_strategies.join(', ')}"
41
41
  end
42
42
 
43
- if value == :subquery && CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0')
43
+ if value == :subquery && does_not_support_subquery_strategy?
44
44
  raise ArgumentError, 'accessible_by_strategy = :subquery requires ActiveRecord 5 or newer'
45
45
  end
46
46
 
47
47
  @accessible_by_strategy = value
48
48
  end
49
+
50
+ def self.does_not_support_subquery_strategy?
51
+ !defined?(CanCan::ModelAdapters::ActiveRecordAdapter) ||
52
+ CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0')
53
+ end
49
54
  end
@@ -6,12 +6,11 @@ module CanCan
6
6
  class << self
7
7
  def normalize(rules)
8
8
  rules_cache = []
9
- rules.delete_if.with_index do |rule, _index|
10
- subjects = rule.subjects.select do |subject|
11
- next if subject == :all || subject.descends_from_active_record?
9
+ return unless defined?(ActiveRecord::Base)
12
10
 
13
- rules_cache.push(build_rule_for_subclass(rule, subject))
14
- true
11
+ rules.delete_if do |rule|
12
+ subjects = rule.subjects.select do |subject|
13
+ update_rule(subject, rule, rules_cache)
15
14
  end
16
15
  subjects.length == rule.subjects.length
17
16
  end
@@ -20,6 +19,15 @@ module CanCan
20
19
 
21
20
  private
22
21
 
22
+ def update_rule(subject, rule, rules_cache)
23
+ return false unless subject.respond_to?(:descends_from_active_record?)
24
+ return false if subject == :all || subject.descends_from_active_record?
25
+ return false unless subject < ActiveRecord::Base
26
+
27
+ rules_cache.push(build_rule_for_subclass(rule, subject))
28
+ true
29
+ end
30
+
23
31
  # create a new rule for the subclasses that links on the inheritance_column
24
32
  def build_rule_for_subclass(rule, subject)
25
33
  CanCan::Rule.new(rule.base_behavior, rule.actions, subject.superclass,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CanCan
4
- VERSION = '3.2.0'.freeze
4
+ VERSION = '3.2.1'.freeze
5
5
  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: 3.2.0
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi (Renuo AG)
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-12-12 00:00:00.000000000 Z
14
+ date: 2020-12-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: appraisal