cancancan 3.2.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cancancan.gemspec +1 -0
- data/lib/cancan/ability/rules.rb +5 -2
- data/lib/cancan/config.rb +24 -4
- data/lib/cancan/model_additions.rb +4 -2
- data/lib/cancan/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4498ac94e1994faa4da80dc957d8c9564433d991048774f9ac2f051e60de580
|
4
|
+
data.tar.gz: 74209123c4c49adcd1d2d81df1de61c5f8cc2f243fdcdb4d01d3e41731e4c266
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb7774650d12a7073d09bb713f7eedfd7d376689f6d6bb842620b325a814720172f4fec900705bcc0dd3bd90818a88d2ab7e3904ea3a5d004533e13b4bed1c4c
|
7
|
+
data.tar.gz: a7a6fff07fbd7d52816dd960d00ae0baea7d50c5ed41d0abf32ac3a0c2b6bc3c557a4309944717b57aad785ad7dc394870c079b6a820b62798a373a9d9f8c2b0
|
data/cancancan.gemspec
CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.authors = ['Alessandro Rodi (Renuo AG)', 'Bryan Rite', 'Ryan Bates', 'Richard Wilson']
|
11
11
|
s.email = 'alessandro.rodi@renuo.ch'
|
12
12
|
s.homepage = 'https://github.com/CanCanCommunity/cancancan'
|
13
|
+
s.metadata = { 'funding_uri' => 'https://github.com/sponsors/coorasse' }
|
13
14
|
s.summary = 'Simple authorization solution for Rails.'
|
14
15
|
s.description = 'Simple authorization solution for Rails. All permissions are stored in a single location.'
|
15
16
|
s.platform = Gem::Platform::RUBY
|
data/lib/cancan/ability/rules.rb
CHANGED
@@ -19,12 +19,13 @@ module CanCan
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def add_rule_to_index(rule, position)
|
22
|
-
@rules_index ||=
|
22
|
+
@rules_index ||= {}
|
23
23
|
|
24
24
|
subjects = rule.subjects.compact
|
25
25
|
subjects << :all if subjects.empty?
|
26
26
|
|
27
27
|
subjects.each do |subject|
|
28
|
+
@rules_index[subject] ||= []
|
28
29
|
@rules_index[subject] << position
|
29
30
|
end
|
30
31
|
end
|
@@ -48,7 +49,9 @@ module CanCan
|
|
48
49
|
rules
|
49
50
|
else
|
50
51
|
positions = @rules_index.values_at(subject, *alternative_subjects(subject))
|
51
|
-
positions.
|
52
|
+
positions.compact!
|
53
|
+
positions.flatten!
|
54
|
+
positions.sort!
|
52
55
|
positions.map { |i| @rules[i] }
|
53
56
|
end
|
54
57
|
end
|
data/lib/cancan/config.rb
CHANGED
@@ -21,7 +21,9 @@ module CanCan
|
|
21
21
|
# `distinct` is not reliable in some cases. See
|
22
22
|
# https://github.com/CanCanCommunity/cancancan/pull/605
|
23
23
|
def self.accessible_by_strategy
|
24
|
-
@accessible_by_strategy
|
24
|
+
return @accessible_by_strategy if @accessible_by_strategy
|
25
|
+
|
26
|
+
@accessible_by_strategy = default_accessible_by_strategy
|
25
27
|
end
|
26
28
|
|
27
29
|
def self.default_accessible_by_strategy
|
@@ -36,9 +38,7 @@ module CanCan
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def self.accessible_by_strategy=(value)
|
39
|
-
|
40
|
-
raise ArgumentError, "accessible_by_strategy must be one of #{valid_accessible_by_strategies.join(', ')}"
|
41
|
-
end
|
41
|
+
validate_accessible_by_strategy!(value)
|
42
42
|
|
43
43
|
if value == :subquery && does_not_support_subquery_strategy?
|
44
44
|
raise ArgumentError, 'accessible_by_strategy = :subquery requires ActiveRecord 5 or newer'
|
@@ -47,6 +47,26 @@ module CanCan
|
|
47
47
|
@accessible_by_strategy = value
|
48
48
|
end
|
49
49
|
|
50
|
+
def self.with_accessible_by_strategy(value)
|
51
|
+
return yield if value == accessible_by_strategy
|
52
|
+
|
53
|
+
validate_accessible_by_strategy!(value)
|
54
|
+
|
55
|
+
begin
|
56
|
+
strategy_was = accessible_by_strategy
|
57
|
+
@accessible_by_strategy = value
|
58
|
+
yield
|
59
|
+
ensure
|
60
|
+
@accessible_by_strategy = strategy_was
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.validate_accessible_by_strategy!(value)
|
65
|
+
return if valid_accessible_by_strategies.include?(value)
|
66
|
+
|
67
|
+
raise ArgumentError, "accessible_by_strategy must be one of #{valid_accessible_by_strategies.join(', ')}"
|
68
|
+
end
|
69
|
+
|
50
70
|
def self.does_not_support_subquery_strategy?
|
51
71
|
!defined?(CanCan::ModelAdapters::ActiveRecordAdapter) ||
|
52
72
|
CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0')
|
@@ -20,8 +20,10 @@ module CanCan
|
|
20
20
|
# @articles = Article.accessible_by(current_ability, :update)
|
21
21
|
#
|
22
22
|
# Here only the articles which the user can update are returned.
|
23
|
-
def accessible_by(ability, action = :index)
|
24
|
-
|
23
|
+
def accessible_by(ability, action = :index, strategy: CanCan.accessible_by_strategy)
|
24
|
+
CanCan.with_accessible_by_strategy(strategy) do
|
25
|
+
ability.model_adapter(self, action).database_records
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
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.
|
4
|
+
version: 3.3.0
|
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:
|
14
|
+
date: 2021-06-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: appraisal
|
@@ -149,7 +149,8 @@ files:
|
|
149
149
|
homepage: https://github.com/CanCanCommunity/cancancan
|
150
150
|
licenses:
|
151
151
|
- MIT
|
152
|
-
metadata:
|
152
|
+
metadata:
|
153
|
+
funding_uri: https://github.com/sponsors/coorasse
|
153
154
|
post_install_message:
|
154
155
|
rdoc_options: []
|
155
156
|
require_paths:
|