mongoid_ability 2.0.0 → 2.0.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
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 721df8ecdb6424b68a3bc809f25cdaba1c8ff688
|
|
4
|
+
data.tar.gz: 6d80989eadf2723af7eef09b9069b63ca2b84e26
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2a8e5866633b0cb5451edf17ade4b4b4fc5977f6bac78054df986b13b674e4647b6d0d3d704b5fed4bacb13b2225496153379f749f3fe1f827e09459998e28b
|
|
7
|
+
data.tar.gz: 8cd962801bd4b8960432707c6a4a8a0b6f8bd2fced346a9dee183f2724a830a67076b244563134a81fd79b1c620e8b0c452f963c3aaf88eeb77799be714f9f1c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 2.0.1
|
|
4
|
+
|
|
5
|
+
* make sure all `subject_id` values are converted to BSON
|
|
6
|
+
|
|
7
|
+
## 2.0.0
|
|
2
8
|
|
|
3
9
|
* Full rewrite, which more closely follows the `CanCanCan` conventions: instead of custom algorithm for resolving permissions, the `Lock` documents are now converted to standard `CanCanCan` rules. Similarly the `.acessible_by` criteria are now handled by standard model adapter (`MongoidAdapter`), to be extracted to separate gem. Therefore this gem can benefit for potential future performance improvements of `CanCanCan`. Lastly, the `ability` objects are now cacheable, therefore the conversion of `Lock` documents to `CanCanCan` rule objects does not need to be performed on every request.
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
## 1.0.0
|
|
6
12
|
|
|
7
13
|
* conforms to '[MONGOID-4418](https://jira.mongodb.org/browse/MONGOID-4418) Don't allow PersistenceContext method as field names' by renaming the `Lock` field `:options` to `:opts` (but aliasing it `as: :options`). As a result the `Mongoid::Ability` API stays unchanged, however in some cases it might be necessary to migrate the values from the `:options` fields to the new `:opts`.
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
## 0.4.3
|
|
10
16
|
|
|
11
17
|
* stub `default_locks` in tests to avoid brittle tests
|
|
12
18
|
* fix the ability syntactic sugar to support both proc & direct call
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
## 0.4.2
|
|
15
21
|
|
|
16
22
|
* **yanked**
|
|
17
23
|
* improved clarity in class naming
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
## 0.4.1
|
|
20
26
|
|
|
21
27
|
* **yanked**
|
|
22
28
|
* `Resolver` classes now accept `subject_id` (instead of `subject`) for greater flexibility
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
## 0.4.0
|
|
25
31
|
|
|
26
32
|
* **yanked**
|
|
27
33
|
* the `Resolver` classes refactored to return locks (instead of just an outcome)
|
|
@@ -83,9 +83,15 @@ module MongoidAbility
|
|
|
83
83
|
ability_type = lock.outcome ? :can : :cannot
|
|
84
84
|
cls = lock.subject_class
|
|
85
85
|
options = lock.options
|
|
86
|
-
options = options.merge(id: lock.subject_id) if lock.id_lock?
|
|
86
|
+
options = options.merge(id: convert_to_bson(lock.subject_id)) if lock.id_lock?
|
|
87
87
|
action = lock.action
|
|
88
88
|
send ability_type, action, cls, options
|
|
89
89
|
end
|
|
90
|
+
|
|
91
|
+
def convert_to_bson(id)
|
|
92
|
+
return id unless id.is_a?(String)
|
|
93
|
+
return id unless BSON::ObjectId.legal?(id)
|
|
94
|
+
BSON::ObjectId.from_string(id)
|
|
95
|
+
end
|
|
90
96
|
end
|
|
91
97
|
end
|
|
@@ -35,6 +35,13 @@ module MongoidAbility
|
|
|
35
35
|
|
|
36
36
|
it { ability.can?(:read, my_subject).must_equal true }
|
|
37
37
|
it { ability.cannot?(:read, my_subject).must_equal false }
|
|
38
|
+
|
|
39
|
+
describe 'when id stored as String' do
|
|
40
|
+
let(:read_lock) { MyLock.new(subject_type: my_subject.model_name.to_s, subject_id: my_subject.id.to_s, action: :read, outcome: true) }
|
|
41
|
+
|
|
42
|
+
it { ability.can?(:read, my_subject).must_equal true }
|
|
43
|
+
it { ability.cannot?(:read, my_subject).must_equal false }
|
|
44
|
+
end
|
|
38
45
|
end
|
|
39
46
|
end
|
|
40
47
|
|
|
@@ -4,14 +4,23 @@ module MongoidAbility
|
|
|
4
4
|
describe 'marshal' do
|
|
5
5
|
before(:all) { MySubject.default_lock MyLock, :read, true }
|
|
6
6
|
|
|
7
|
-
let(:
|
|
7
|
+
let(:my_subject) { MySubject.new }
|
|
8
|
+
let(:read_lock) { MyLock.new(subject_type: my_subject.model_name.to_s, subject_id: my_subject.id.to_s, action: :update, outcome: false) }
|
|
8
9
|
let(:owner) { MyRole.new(my_locks: [read_lock]) }
|
|
9
10
|
let(:ability) { Ability.new(owner) }
|
|
10
11
|
|
|
11
12
|
let(:ability_dump) { Marshal.dump(ability) }
|
|
12
13
|
let(:ability_load) { Marshal.load(ability_dump) }
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
let(:loaded_rules) { ability_load.send(:rules) }
|
|
16
|
+
|
|
17
|
+
describe 'dump' do
|
|
18
|
+
it { ability_dump.must_be :present? }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'load' do
|
|
22
|
+
it { loaded_rules.count.must_equal 2 }
|
|
23
|
+
it { loaded_rules.map(&:conditions).must_include({ id: my_subject.id }) }
|
|
24
|
+
end
|
|
16
25
|
end
|
|
17
26
|
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: 2.0.
|
|
4
|
+
version: 2.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-
|
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: cancancan
|