mongoid_ability 0.3.9 → 0.3.10
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5e922ad81d138949099439d6b784e0f61f478b2
|
4
|
+
data.tar.gz: 39097d4d5d0fa47b9df342e75d5daa0023f91393
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac11777dadc4735bb86671358b190ff0d670a7af68849e68630eb76a31dd47300370960c59dc12f0dffca68e8ccd341f81222c58e3b605744c5d5881aae58fc8
|
7
|
+
data.tar.gz: c91acfed7222d481be96e740f5eecf2d760a116604f974e5f4756983f53bafc86cf43755fc4f783b9d953f9ebbb286e4ea84a41817288ed284189d511237bf4e
|
@@ -40,8 +40,9 @@ module MongoidAbility
|
|
40
40
|
|
41
41
|
# ---------------------------------------------------------------------
|
42
42
|
|
43
|
-
def has_lock?
|
44
|
-
|
43
|
+
def has_lock?(lock)
|
44
|
+
@has_lock ||= {}
|
45
|
+
@has_lock[lock] ||= locks_relation.where(action: lock.action, subject_type: lock.subject_type, subject_id: lock.subject_id.presence).cache.exists?
|
45
46
|
end
|
46
47
|
|
47
48
|
private # =============================================================
|
@@ -1,22 +1,23 @@
|
|
1
|
+
# OPTIMIZE: this seems quite expensive
|
2
|
+
|
1
3
|
module MongoidAbility
|
2
4
|
class ResolveOwnerLocks < ResolveLocks
|
3
5
|
def call
|
4
|
-
# FIXME: this is not a very nice fix
|
5
6
|
return unless owner.respond_to?(:locks_relation)
|
6
7
|
|
7
|
-
locks_for_subject_type = owner.locks_relation.for_action(action).for_subject_type(subject_type)
|
8
|
+
locks_for_subject_type = owner.locks_relation.for_action(action).for_subject_type(subject_type).cache
|
8
9
|
|
9
10
|
return unless locks_for_subject_type.exists?
|
10
11
|
|
11
12
|
# return outcome if owner defines lock for id
|
12
|
-
if
|
13
|
-
id_locks = locks_for_subject_type.id_locks.for_subject_id(subject_id)
|
13
|
+
if subject_id.present?
|
14
|
+
id_locks = locks_for_subject_type.id_locks.for_subject_id(subject_id).cache
|
14
15
|
return false if id_locks.any? { |l| l.closed?(options) }
|
15
16
|
return true if id_locks.any? { |l| l.open?(options) }
|
16
17
|
end
|
17
18
|
|
18
19
|
# return outcome if owner defines lock for subject_type
|
19
|
-
class_locks = locks_for_subject_type.class_locks
|
20
|
+
class_locks = locks_for_subject_type.class_locks.cache
|
20
21
|
return false if class_locks.class_locks.any? { |l| l.closed?(options) }
|
21
22
|
return true if class_locks.class_locks.any? { |l| l.open?(options) }
|
22
23
|
|
@@ -43,14 +43,14 @@ module MongoidAbility
|
|
43
43
|
|
44
44
|
def owner_id_locks_for_subject_type(cls)
|
45
45
|
@owner_id_locks_for_subject_type ||= {}
|
46
|
-
@owner_id_locks_for_subject_type[cls] ||= owner.locks_relation.id_locks.for_action(action).for_subject_type(cls.to_s)
|
46
|
+
@owner_id_locks_for_subject_type[cls] ||= owner.locks_relation.id_locks.for_action(action).for_subject_type(cls.to_s).cache
|
47
47
|
end
|
48
48
|
|
49
49
|
def inherited_from_relation_ids_locks_for_subject_type(cls)
|
50
50
|
return [] unless inherited_from_relation
|
51
51
|
@inherited_from_relation_ids_locks_for_subject_type ||= {}
|
52
52
|
@inherited_from_relation_ids_locks_for_subject_type[cls] ||= inherited_from_relation.collect do |o|
|
53
|
-
o.locks_relation.id_locks.for_action(action).for_subject_type(cls.to_s)
|
53
|
+
o.locks_relation.id_locks.for_action(action).for_subject_type(cls.to_s).cache
|
54
54
|
end.flatten
|
55
55
|
end
|
56
56
|
|
@@ -135,5 +135,14 @@ module MongoidAbility
|
|
135
135
|
MySubject2.accessible_by(ability, :update).to_a.wont_include my_subject2
|
136
136
|
end
|
137
137
|
end
|
138
|
+
|
139
|
+
# =====================================================================
|
140
|
+
|
141
|
+
describe 'prefix' do
|
142
|
+
it 'allows to pass prefix' do
|
143
|
+
skip 'not sure how to best test this'
|
144
|
+
MySubject.accessible_by(ability, :update, prefix: :subject).must_equal 'foo'
|
145
|
+
end
|
146
|
+
end
|
138
147
|
end
|
139
148
|
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: 0.3.
|
4
|
+
version: 0.3.10
|
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-
|
11
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cancancan
|