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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f654149dda4ee90b979831aeb07501fb41d22ff9
4
- data.tar.gz: 81415f18fc6021d1a65c346b6dd1ef6fc95fc49e
3
+ metadata.gz: 6a81d37c12d122debb6581425d2b059f60860736
4
+ data.tar.gz: 2ae9be280d0738122c2e2825cbf8ec65d5374d6d
5
5
  SHA512:
6
- metadata.gz: 884958b5928962a8ee79105b897f5b971f4dc73f263f407268e1332a72745f82e2b67c384d8dedb2d7e4744e80bc1af1432fbc34e80d138676a49a9dbe5808cc
7
- data.tar.gz: 3e2e565ff189df8a41265f7c3d4ec7d7071150267e9cdf18d330d94d3a14411a30eb30805546be172430a542f60f7491700676dfc2abcc6d6769bab1d3c61fad
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 'subtarget') can specific operation on a target (which is your resource).
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?(:bank_corp, :new) # => true
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
- rule_group = Bali.rule_group_for(record.class, subtarget)
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
- rule_group = Bali.rule_group_for(self.class, subtarget)
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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Bali
2
- VERSION = "1.0.0beta1"
2
+ VERSION = "1.0.0rc1"
3
3
  end
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.0beta1
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-09 00:00:00.000000000 Z
11
+ date: 2015-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler