cancancan 3.5.0 → 3.6.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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0d4a5b11aba155764cf54465d5d8bf88872fed61f4a33736d45a531c619ad6e
|
4
|
+
data.tar.gz: 12b3b41403f3fdaba3fdb97c30ce17e319d1bfdef05fcb7700d41ba754c75a55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: beb6989dbb2554678fa17626b6138aab396419b6d01ed8ce3ee3781030086da48985837a01bef50ab111fb47273454df8c7e3d6ced11b10a036ffe2e494feb15
|
7
|
+
data.tar.gz: 405b0e6eb4ab73f04964651ab27e106701c014cd706f74012e5f30aada5796de6541f812593b57e058031af0991890884701136229f0405900e3bc99ce3747ee
|
@@ -31,7 +31,7 @@ module CanCan
|
|
31
31
|
klass = subject_class?(subject) ? subject : subject.class
|
32
32
|
# empty attributes is an 'all'
|
33
33
|
if rule.attributes.empty? && klass < ActiveRecord::Base
|
34
|
-
klass.
|
34
|
+
klass.attribute_names.map(&:to_sym) - Array(klass.primary_key)
|
35
35
|
else
|
36
36
|
rule.attributes
|
37
37
|
end
|
@@ -171,6 +171,11 @@ module CanCan
|
|
171
171
|
# [:+instance_name+]
|
172
172
|
# The name of the instance variable for this resource.
|
173
173
|
#
|
174
|
+
# [:+id_param+]
|
175
|
+
# Find using a param key other than :id. For example:
|
176
|
+
#
|
177
|
+
# load_resource :id_param => :url # will use find(params[:url])
|
178
|
+
#
|
174
179
|
# [:+through+]
|
175
180
|
# Authorize conditions on this parent resource when instance isn't available.
|
176
181
|
#
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Metrics/AbcSize
|
4
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
5
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
3
6
|
module CanCan
|
4
7
|
module ModelAdapters
|
5
8
|
class ActiveRecordAdapter < AbstractAdapter
|
@@ -52,7 +55,7 @@ module CanCan
|
|
52
55
|
# Search again in case of polymorphic associations, this time matching on the :has_many side
|
53
56
|
# via the :as option, as well as klass
|
54
57
|
foreign_key ||= parent_class.reflect_on_all_associations(:has_many).find do |has_many_assoc|
|
55
|
-
|
58
|
+
matching_parent_child_polymorphic_association(has_many_assoc, child_class)
|
56
59
|
end&.foreign_key&.to_sym
|
57
60
|
|
58
61
|
foreign_key.nil? ? nil : all_conditions[foreign_key]
|
@@ -61,7 +64,7 @@ module CanCan
|
|
61
64
|
def matching_parent_child_polymorphic_association(parent_assoc, child_class)
|
62
65
|
return nil unless parent_assoc.klass == child_class
|
63
66
|
return nil if parent_assoc&.options[:as].nil?
|
64
|
-
|
67
|
+
|
65
68
|
child_class.reflect_on_all_associations(:belongs_to).find do |child_assoc|
|
66
69
|
# Only match this way for polymorphic associations
|
67
70
|
child_assoc.polymorphic? && child_assoc.name == parent_assoc.options[:as]
|
@@ -72,12 +75,12 @@ module CanCan
|
|
72
75
|
child_class = child.is_a?(Class) ? child : child.class
|
73
76
|
parent_class = parent.is_a?(Class) ? parent : parent.class
|
74
77
|
|
75
|
-
association = child_class.reflect_on_all_associations(:belongs_to).find do |
|
78
|
+
association = child_class.reflect_on_all_associations(:belongs_to).find do |belongs_to_assoc|
|
76
79
|
# Do not match on polymorphic associations or it will throw an error (klass cannot be determined)
|
77
|
-
!
|
80
|
+
!belongs_to_assoc.polymorphic? && belongs_to_assoc.klass == parent.class
|
78
81
|
end
|
79
82
|
|
80
|
-
return association
|
83
|
+
return association if association
|
81
84
|
|
82
85
|
parent_class.reflect_on_all_associations(:has_many).each do |has_many_assoc|
|
83
86
|
association ||= matching_parent_child_polymorphic_association(has_many_assoc, child_class)
|
@@ -217,6 +220,9 @@ module CanCan
|
|
217
220
|
end
|
218
221
|
end
|
219
222
|
end
|
223
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
224
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
225
|
+
# rubocop:enable Metrics/AbcSize
|
220
226
|
|
221
227
|
ActiveSupport.on_load(:active_record) do
|
222
228
|
send :include, CanCan::ModelAdditions
|
@@ -11,6 +11,7 @@ module CanCan
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def compress(array)
|
14
|
+
array = simplify(array)
|
14
15
|
idx = array.rindex(&:catch_all?)
|
15
16
|
return array unless idx
|
16
17
|
|
@@ -19,5 +20,22 @@ module CanCan
|
|
19
20
|
.drop_while { |n| n.base_behavior == value.base_behavior }
|
20
21
|
.tap { |a| a.unshift(value) unless value.cannot_catch_all? }
|
21
22
|
end
|
23
|
+
|
24
|
+
# If we have A OR (!A AND anything ), then we can simplify to A OR anything
|
25
|
+
# If we have A OR (A OR anything ), then we can simplify to A OR anything
|
26
|
+
# If we have !A AND (A OR something), then we can simplify it to !A AND something
|
27
|
+
# If we have !A AND (!A AND something), then we can simplify it to !A AND something
|
28
|
+
#
|
29
|
+
# So as soon as we see a condition that is the same as the previous one,
|
30
|
+
# we can skip it, no matter of the base_behavior
|
31
|
+
def simplify(rules)
|
32
|
+
seen = Set.new
|
33
|
+
rules.reverse_each.filter_map do |rule|
|
34
|
+
next if seen.include?(rule.conditions)
|
35
|
+
|
36
|
+
seen.add(rule.conditions)
|
37
|
+
rule
|
38
|
+
end.reverse
|
39
|
+
end
|
22
40
|
end
|
23
41
|
end
|
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.6.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:
|
14
|
+
date: 2024-05-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: appraisal
|
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
|
-
rubygems_version: 3.3.
|
175
|
+
rubygems_version: 3.3.3
|
176
176
|
signing_key:
|
177
177
|
specification_version: 4
|
178
178
|
summary: Simple authorization solution for Rails.
|