mongoid_ability 3.0.0 → 3.0.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: 9a0e978ec258c3a3b3e93fa34b6943c8af6b09666722b0ac2b61f196fa972394
4
- data.tar.gz: 132f93b4885b86db918c22739859944b86d98e83a07fd7f90ac0e259b5d6e901
3
+ metadata.gz: cc805cd65bf9cd6deb5fcf4492704ef31860639789ca5cb49825c4d6cc3b9a74
4
+ data.tar.gz: 566d6195f97fbe1ce3714a4c3d9831c77ed1aa973a2bf4ed6db223cd8795810d
5
5
  SHA512:
6
- metadata.gz: 50b463ff75c3ecf23a1187b05fcba527c4b50bd47e3c4831d7aece79124b366194d28da44af3acb414f4d0a8de8c02799a24e321a138bab1046552463f7b8a4e
7
- data.tar.gz: 06dee8bd65eacce1939aca16d3f6b001b7ed58e708f776903eeb3a2bd4873cf1a3d8d09e5a817590571113d29795b038ec979cacd6f243f43f18d07084d2efab
6
+ metadata.gz: 64306098207ce7c07afd427ace5f710048cfaab63c0dea919df0bfe1c181c75f730edde2bdd3da5b84f6241887b09acd091b487555ba9d6048ca1647fb17dd42
7
+ data.tar.gz: 802b0005642510a19cab284b15787090656dd96fbafc1c76d783b2d1f8f31c415e441b3934030e4eeb8953990009bfcd52725ea402d019d2eaa412e40bc08133
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.0.1
4
+
5
+ * OPTMIZE: `.accessible_by` is now using `$nin` with multiple values rather than multiple of `$ne`
6
+
3
7
  ## 3.0.0
4
8
 
5
9
  * upgrade to Mongoid 7+
@@ -88,11 +88,15 @@ module CanCan
88
88
  condition_rules.reject(&:base_behavior).each_with_object([]) do |rule, res|
89
89
  rule.conditions.each do |key, value|
90
90
  key = id_key if %i[id _id].include?(key.to_sym)
91
- res << case value
92
- when Regexp then { key => { '$not' => value } }
93
- when Array then { key => { '$nin' => value } }
94
- else { key => { '$ne' => value } }
95
- end
91
+ case value
92
+ when Regexp then res << { key => { '$not' => value } }
93
+ else
94
+ if prev_value = res.detect { |item| item.dig(key, '$nin') }
95
+ prev_value[key]['$nin'] += Array(value)
96
+ else
97
+ res << { key => { '$nin' => Array(value) } }
98
+ end
99
+ end
96
100
  end
97
101
  end
98
102
  end
@@ -100,6 +104,7 @@ module CanCan
100
104
 
101
105
  def subject_type_conditions
102
106
  return unless open_subject_types.present?
107
+
103
108
  { :"#{type_key}".nin => closed_subject_types.map(&:to_s) }
104
109
  end
105
110
 
@@ -112,7 +117,7 @@ module CanCan
112
117
  def database_records
113
118
  return @model_class.none unless has_any_conditions?
114
119
 
115
- or_conditions = { '$or' => ([subject_type_conditions, *open_conditions]).compact }
120
+ or_conditions = { '$or' => [subject_type_conditions, *open_conditions].compact }
116
121
  or_conditions = nil if or_conditions['$or'].empty?
117
122
 
118
123
  and_conditions = { '$and' => [or_conditions, *closed_conditions].compact }
@@ -1,3 +1,3 @@
1
1
  module MongoidAbility
2
- VERSION = '3.0.0'.freeze
2
+ VERSION = '3.0.1'.freeze
3
3
  end
@@ -196,7 +196,7 @@ module CanCan
196
196
  { 'subject_type' => { '$nin' => [] } },
197
197
  { 'subject_id' => my_subject1.id }
198
198
  ] },
199
- { 'subject_id' => { '$ne' => my_subject2.id } }
199
+ { 'subject_id' => { '$nin' => [my_subject2.id] } }
200
200
  ]
201
201
  )
202
202
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_ability
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-12 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cancancan
@@ -207,8 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
209
  requirements: []
210
- rubyforge_project:
211
- rubygems_version: 2.7.6
210
+ rubygems_version: 3.0.1
212
211
  signing_key:
213
212
  specification_version: 4
214
213
  summary: Custom Ability class that allows CanCanCan authorization library store permissions