bali 1.0.0beta1 → 1.0.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/lib/bali.rb +6 -0
- data/lib/bali/objector.rb +21 -3
- data/lib/bali/rule_group.rb +4 -0
- data/lib/bali/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a81d37c12d122debb6581425d2b059f60860736
|
4
|
+
data.tar.gz: 2ae9be280d0738122c2e2825cbf8ec65d5374d6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94f479a43d56ebdb12808e466e09e5aa34e5d9748b112a337b91058dcaca2348aa13ecf4a2250b79433894cb87ed7f160360114f15434e9b4da21eb10275d4b7
|
7
|
+
data.tar.gz: 23c47258175bf243764327914e0cc296b5864b582e2421474d169c2d0ddba1a73d9fa9b3e6f4dea9352742b6fc41ba1515bdc5a82897be9d1750d6e55ae022f8
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ And then execute:
|
|
26
26
|
|
27
27
|
### First things first: defining rules
|
28
28
|
|
29
|
-
Rule in Bali is the law determining whether a user (called
|
29
|
+
Rule in Bali is the law determining whether a user (called `subtarget`) can do or perform specific operation on a target (which is your resource/model).
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
Bali.map_rules do
|
@@ -44,6 +44,7 @@ Rule in Bali is the law determining whether a user (called 'subtarget') can spec
|
|
44
44
|
can :update, :delete, :edit
|
45
45
|
can :delete, if: proc { |record| record.is_settled? }
|
46
46
|
end # finance_user description
|
47
|
+
describe :guest { cant_all }
|
47
48
|
end # rules_for
|
48
49
|
end
|
49
50
|
```
|
@@ -73,6 +74,7 @@ transaction.can?(:monitoring_user, :view) # => true
|
|
73
74
|
transaction.can?("monitoring user", :view) # => true
|
74
75
|
transaction.can?(:admin_user, :cancel) # depend on context
|
75
76
|
transaction.can?(:supreme_user, :cancel) # => true
|
77
|
+
transaction.can?(:guest, :view) # => false
|
76
78
|
```
|
77
79
|
|
78
80
|
If a rule is depending on a certain context, then the context will be evaluated to determine whether the subtarget is authorized or not.
|
@@ -82,7 +84,8 @@ In the above example, deletion of `transaction` is only allowed if the subtarget
|
|
82
84
|
Rule can also be called on a class, instead of on an object:
|
83
85
|
|
84
86
|
```ruby
|
85
|
-
My::Transaction.can?(:
|
87
|
+
My::Transaction.can?(:supreme_user, :new) # => true
|
88
|
+
My::Transaction.can?(:guest, :view) # => false
|
86
89
|
```
|
87
90
|
|
88
91
|
## Contributing
|
@@ -93,3 +96,12 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
93
96
|
## License
|
94
97
|
|
95
98
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
99
|
+
|
100
|
+
### Changelog
|
101
|
+
|
102
|
+
#### Version 1.0.0beta1
|
103
|
+
1. Initial version
|
104
|
+
|
105
|
+
#### Version 1.0.0rc1
|
106
|
+
1. Fix bug where user can't check on class
|
107
|
+
2. Adding new clause: cant_all
|
data/lib/bali.rb
CHANGED
@@ -177,6 +177,12 @@ module Bali
|
|
177
177
|
|
178
178
|
def can_all
|
179
179
|
self.current_rule_group.zeus = true
|
180
|
+
self.current_rule_group.plant = false
|
181
|
+
end
|
182
|
+
|
183
|
+
def cant_all
|
184
|
+
self.current_rule_group.plant = true
|
185
|
+
self.current_rule_group.zeus = false
|
180
186
|
end
|
181
187
|
|
182
188
|
end # class
|
data/lib/bali/objector.rb
CHANGED
@@ -16,12 +16,22 @@ end
|
|
16
16
|
|
17
17
|
module Bali::Objector::Statics
|
18
18
|
def can?(subtarget, operation, record = self)
|
19
|
-
|
19
|
+
# if performed on a class-level, don't call its class or it will return
|
20
|
+
# Class. That's not what is expected.
|
21
|
+
if self.is_a?(Class)
|
22
|
+
rule_group = Bali.rule_group_for(self, subtarget)
|
23
|
+
else
|
24
|
+
rule_group = Bali.rule_group_for(self.class, subtarget)
|
25
|
+
end
|
26
|
+
|
20
27
|
rule = rule_group.get_rule(:can, operation)
|
21
28
|
|
22
29
|
# godly subtarget is allowed to do as he wishes
|
23
30
|
# so long that the rule is not specificly defined
|
24
31
|
return true if rule_group.zeus? && rule.nil?
|
32
|
+
|
33
|
+
# plan subtarget is not allowed unless spesificly defined
|
34
|
+
return false if rule_group.plant? && rule.nil?
|
25
35
|
|
26
36
|
# default to false when asked about can? but no rule to be found
|
27
37
|
return false if rule.nil?
|
@@ -40,14 +50,22 @@ module Bali::Objector::Statics
|
|
40
50
|
end
|
41
51
|
end
|
42
52
|
|
43
|
-
def cant?(subtarget, operation)
|
44
|
-
|
53
|
+
def cant?(subtarget, operation, record = self)
|
54
|
+
if self.is_a?(Class)
|
55
|
+
rule_group = Bali.rule_group_for(self, subtarget)
|
56
|
+
else
|
57
|
+
rule_group = Bali.rule_group_for(self.class, subtarget)
|
58
|
+
end
|
59
|
+
|
45
60
|
rule = rule_group.get_rule(:cant, operation)
|
46
61
|
|
47
62
|
# godly subtarget is not to be prohibited in his endeavours
|
48
63
|
# so long that no specific rule about this operation is defined
|
49
64
|
return false if rule_group.zeus? && rule.nil?
|
50
65
|
|
66
|
+
# plant subtarget is not allowed to do things unless specificly defined
|
67
|
+
return true if rule_group.plant? && rule.nil?
|
68
|
+
|
51
69
|
# default to true when asked about cant? but no rule to be found
|
52
70
|
return true if rule.nil?
|
53
71
|
|
data/lib/bali/rule_group.rb
CHANGED
@@ -15,6 +15,10 @@ class Bali::RuleGroup
|
|
15
15
|
attr_accessor :zeus
|
16
16
|
alias :zeus? :zeus
|
17
17
|
|
18
|
+
# if set to true, well, cannot do anything
|
19
|
+
attr_accessor :plant
|
20
|
+
alias :plant? :plant
|
21
|
+
|
18
22
|
# allowing "general user" and :general_user to route to the same rule group
|
19
23
|
def self.canon_name(subtarget)
|
20
24
|
if subtarget.is_a?(String)
|
data/lib/bali/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bali
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.0rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Pahlevi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|