mongoid_ability 0.3.7 → 0.3.8

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
  SHA1:
3
- metadata.gz: d30d247467a000a4905761928d401f3a6adbbc10
4
- data.tar.gz: a14eed2b95bd69392acc82b46d192902fef23a66
3
+ metadata.gz: 943814cee43339bf17cc8387496583fbbc797ddf
4
+ data.tar.gz: 714784b30fa8dad9f3e5aa32c8a25f62f034005a
5
5
  SHA512:
6
- metadata.gz: 297e80b5fec91daeb637f9394fdac3021df1ba902b20f743855fc1951e0da7adcd401b8207bb034e46357aba1247c3aad20cefbd28507add1a17f0815d66737e
7
- data.tar.gz: d8800d4844678c18e62eace9ae607e404fe469986a138fb0b9c3f2625c0986d897f16331b275fbbce266227beb72fce2032e01457ca1c2d9f154035101835890
6
+ metadata.gz: 05c965309b7d19f5afe52ed51f47189e4a06049a33af6ec640eb845a02137b9938762dd77e32d4b80c6f58037a5b5a7fc09999d71a1c36da5ccbcde021f347b0
7
+ data.tar.gz: e6d1dcf742c1c3dda15459b4dc1abdfbd7d08bbc419262033b72654df3c4e929a94d799027e42e4bc48c02f88b3d4d469287d7ed5ca5fc83208841150c9973e0
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@ language: ruby
2
2
  script: 'bundle exec rake'
3
3
  sudo: false
4
4
  rvm:
5
- - 2.1.2
5
+ - 2.2.2
6
6
  services:
7
7
  - mongodb
8
8
 
@@ -17,18 +17,18 @@ module MongoidAbility
17
17
  private # =============================================================
18
18
 
19
19
  def closed_types_condition
20
- { _type: { '$nin' => values.closed_types } }
20
+ { _type: { '$nin' => values.closed_types.uniq } }
21
21
  end
22
22
 
23
23
  def open_types_and_ids_condition
24
24
  {
25
- _type: { '$in' => values.open_types_and_ids.map(&:type) },
26
- _id: { '$in' => values.open_types_and_ids.map(&:id) }
25
+ _type: { '$in' => values.open_types_and_ids.map(&:type).uniq },
26
+ _id: { '$in' => values.open_types_and_ids.map(&:id).uniq }
27
27
  }
28
28
  end
29
29
 
30
30
  def closed_ids_condition
31
- { _id: { '$nin' => values.closed_ids } }
31
+ { _id: { '$nin' => values.closed_ids.uniq } }
32
32
  end
33
33
 
34
34
  # ---------------------------------------------------------------------
@@ -42,9 +42,5 @@ module MongoidAbility
42
42
  def base_class_superclass
43
43
  @base_class_superclass ||= (base_class.ancestors_with_default_locks.last || base_class)
44
44
  end
45
-
46
- def default_lock(_cls, action)
47
- base_class_superclass.default_locks.detect { |l| l.action.to_s == action.to_s }
48
- end
49
45
  end
50
46
  end
@@ -1,15 +1,14 @@
1
1
  module MongoidAbility
2
2
  class ResolveDefaultLocks < ResolveLocks
3
-
4
3
  def call
5
- return false if default_locks.any?{ |l| l.closed?(options) }
6
- return true if default_locks.any?{ |l| l.open?(options) }
4
+ return false if default_locks.any? { |l| l.closed?(options) }
5
+ return true if default_locks.any? { |l| l.open?(options) }
7
6
  end
8
7
 
9
8
  private # =============================================================
10
9
 
11
10
  def default_locks
12
- subject_class.default_locks.select{ |l| l.action.to_s == action.to_s }
11
+ subject_class.default_locks.select { |l| l.action.to_s == action.to_s }
13
12
  end
14
13
  end
15
14
  end
@@ -1,13 +1,12 @@
1
1
  module MongoidAbility
2
2
  class ResolveInheritedLocks < ResolveLocks
3
-
4
3
  def call
5
4
  uo = user_outcome
6
- return uo if uo != nil
5
+ return uo unless uo.nil?
7
6
 
8
- if owner.respond_to?(owner.class.inherit_from_relation_name) && owner.inherit_from_relation != nil
7
+ if owner.respond_to?(owner.class.inherit_from_relation_name) && !owner.inherit_from_relation.nil?
9
8
  io = owner.inherit_from_relation.collect { |inherited_owner| inherited_owner_outcome(inherited_owner) }.compact
10
- return io.any?{ |o| o == true } unless io.empty?
9
+ return io.any? { |o| o == true } unless io.empty?
11
10
  end
12
11
 
13
12
  default_outcome
@@ -19,7 +18,7 @@ module MongoidAbility
19
18
  @user_outcome ||= ResolveOwnerLocks.call(owner, action, subject_class, subject, options)
20
19
  end
21
20
 
22
- def inherited_owner_outcome inherited_owner
21
+ def inherited_owner_outcome(inherited_owner)
23
22
  @inherited_owner_outcome ||= {}
24
23
  @inherited_owner_outcome[inherited_owner] ||= ResolveOwnerLocks.call(inherited_owner, action, subject_class, subject, options)
25
24
  end
@@ -27,6 +26,5 @@ module MongoidAbility
27
26
  def default_outcome
28
27
  @default_outcome ||= ResolveDefaultLocks.call(nil, action, subject_class, nil, options)
29
28
  end
30
-
31
29
  end
32
30
  end
@@ -1,6 +1,5 @@
1
1
  module MongoidAbility
2
2
  class ResolveLocks < Struct.new(:owner, :action, :subject_type, :subject, :options)
3
-
4
3
  attr_reader(
5
4
  :subject_class,
6
5
  :subject_id
@@ -18,17 +17,16 @@ module MongoidAbility
18
17
  @subject_class = subject_type.to_s.constantize
19
18
  @subject_id = subject.id if subject.present?
20
19
 
21
- raise StandardError, "#{subject_type} class does not have default locks" unless @subject_class.respond_to?(:default_locks)
22
- raise StandardError, "#{subject_type} class does not have default lock for :#{action} action" unless @subject_class.self_and_ancestors_with_default_locks.any? do |cls|
23
- cls.default_locks.any?{ |l| l.action == action }
20
+ fail StandardError, "#{subject_type} class does not have default locks" unless @subject_class.respond_to?(:default_locks)
21
+ fail StandardError, "#{subject_type} class does not have default lock for :#{action} action" unless @subject_class.self_and_ancestors_with_default_locks.any? do |cls|
22
+ cls.default_locks.any? { |l| l.action == action }
24
23
  end
25
24
  end
26
25
 
27
26
  # =====================================================================
28
27
 
29
28
  def call
30
- raise NotImplementedError
29
+ fail NotImplementedError
31
30
  end
32
-
33
31
  end
34
32
  end
@@ -1,3 +1,3 @@
1
1
  module MongoidAbility
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "cancancan", "~> 1.9"
22
- spec.add_dependency "mongoid", "~> 5.0"
22
+ spec.add_dependency "mongoid", "~> 5"
23
23
 
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "coveralls"
@@ -24,6 +24,9 @@ module MongoidAbility
24
24
  MySubject.default_locks = []
25
25
  MySubject.default_lock MyLock, :read, false
26
26
  MySubject.default_lock MyLock1, :read, false
27
+
28
+ MySubject1.default_locks = []
29
+ MySubject1.default_lock MyLock, :read, true
27
30
  end
28
31
 
29
32
  it 'does not allow multiple locks for same action' do
@@ -37,6 +40,11 @@ module MongoidAbility
37
40
  it 'replaces existing locks with new one' do
38
41
  MySubject.default_locks.detect { |l| l.action == :read }.class.must_equal MyLock1
39
42
  end
43
+
44
+ it 'replaces superclass locks' do
45
+ MySubject1.default_locks.count.must_equal 1
46
+ MySubject1.default_locks.detect { |l| l.action == :read }.outcome.must_equal true
47
+ end
40
48
  end
41
49
 
42
50
  describe '.is_root_class?' do
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: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomáš Celizna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-03 00:00:00.000000000 Z
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cancancan
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.0'
40
+ version: '5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -204,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  version: '0'
205
205
  requirements: []
206
206
  rubyforge_project:
207
- rubygems_version: 2.4.6
207
+ rubygems_version: 2.4.8
208
208
  signing_key:
209
209
  specification_version: 4
210
210
  summary: Custom Ability class that allows CanCanCan authorization library store permissions