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 +4 -4
- data/lib/cancan/ability.rb +1 -1
- data/lib/cancan/config.rb +8 -3
- data/lib/cancan/model_adapters/sti_normalizer.rb +13 -5
- data/lib/cancan/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d109d94a089119e1183b6ed77e78316e212b3d78506b8ed10aabb1e8e0e090ce
|
4
|
+
data.tar.gz: '09d6acb72b55c2892be6d7c614bbf9a55b4f60ca3eee1e6aa898e1213e0e807d'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c708dbbefc7a0d120cf9dbacb3d478e2a6155dbb72800563be83b2fced563118b79454a6d9f6eb372bad88f7c4835ebefa636058d055f161b395a6076d154781
|
7
|
+
data.tar.gz: 269ff0d42f16aff0db8882473364fee508504c5f8dd5e4e8d271810d7420e76bebf3c64a16b58a81ed2754e9b1c7fdb9f576c5bc3804c6d26d5b19386e3e9f8e
|
data/lib/cancan/ability.rb
CHANGED
@@ -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]
|
data/lib/cancan/config.rb
CHANGED
@@ -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
|
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
|
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 &&
|
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
|
-
|
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
|
-
|
14
|
-
|
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,
|
data/lib/cancan/version.rb
CHANGED
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.
|
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-
|
14
|
+
date: 2020-12-29 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: appraisal
|