bali 2.4.0 → 6.0.0rc1
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 +5 -13
- data/.rspec +1 -0
- data/lib/bali.rb +23 -14
- data/lib/bali/activerecord.rb +8 -0
- data/lib/bali/authorizer.rb +24 -0
- data/lib/bali/config.rb +12 -0
- data/lib/bali/dsl_error.rb +3 -0
- data/lib/bali/{foundations/exceptions/bali_error.rb → error.rb} +0 -0
- data/lib/bali/judge.rb +239 -0
- data/lib/bali/printer.rb +16 -26
- data/lib/bali/railtie.rb +13 -0
- data/lib/bali/role.rb +79 -0
- data/lib/bali/rule.rb +17 -0
- data/lib/bali/ruler.rb +36 -0
- data/lib/bali/rules.rb +68 -0
- data/lib/bali/tasks/bali/print_rules.rake +9 -0
- data/lib/bali/version.rb +1 -1
- data/lib/generators/rails/USAGE +8 -0
- data/lib/generators/rails/rules_generator.rb +17 -0
- data/lib/generators/rails/templates/rules.rb +4 -0
- data/lib/generators/rspec/rules_generator.rb +12 -0
- data/lib/generators/rspec/templates/rules_spec.rb +7 -0
- metadata +104 -47
- data/lib/bali/dsl/map_rules_dsl.rb +0 -75
- data/lib/bali/dsl/rules_for_dsl.rb +0 -130
- data/lib/bali/foundations/all_foundations.rb +0 -17
- data/lib/bali/foundations/exceptions/authorization_error.rb +0 -38
- data/lib/bali/foundations/exceptions/dsl_error.rb +0 -3
- data/lib/bali/foundations/exceptions/objection_error.rb +0 -3
- data/lib/bali/foundations/judger/judge.rb +0 -329
- data/lib/bali/foundations/judger/negative_judge.rb +0 -40
- data/lib/bali/foundations/judger/positive_judge.rb +0 -41
- data/lib/bali/foundations/role_extractor.rb +0 -61
- data/lib/bali/foundations/rule/rule.rb +0 -55
- data/lib/bali/foundations/rule/rule_class.rb +0 -54
- data/lib/bali/foundations/rule/rule_group.rb +0 -91
- data/lib/bali/integrators/all_integrators.rb +0 -8
- data/lib/bali/integrators/rule_class_integrator.rb +0 -27
- data/lib/bali/integrators/rule_group_integrator.rb +0 -29
- data/lib/bali/integrators/rule_integrator.rb +0 -56
- data/lib/bali/objector.rb +0 -173
data/lib/bali/objector.rb
DELETED
@@ -1,173 +0,0 @@
|
|
1
|
-
# module that will be included in each instantiated target classes as defined
|
2
|
-
# in map_rules
|
3
|
-
module Bali::Objector
|
4
|
-
def self.included(base)
|
5
|
-
base.extend Bali::Objector::Statics
|
6
|
-
end
|
7
|
-
|
8
|
-
# check whether user can/cant perform an operation, return true when positive
|
9
|
-
# or false otherwise
|
10
|
-
def can?(subtargets, operation)
|
11
|
-
self.class.can?(subtargets, operation, self)
|
12
|
-
end
|
13
|
-
|
14
|
-
# check whether user can/cant perform an operation, raise an error when access
|
15
|
-
# is denied
|
16
|
-
def can!(subtargets, operation)
|
17
|
-
self.class.can!(subtargets, operation, self)
|
18
|
-
end
|
19
|
-
|
20
|
-
# check whether user can/cant perform an operation, return true when negative
|
21
|
-
# or false otherwise
|
22
|
-
def cannot?(subtargets, operation)
|
23
|
-
self.class.cannot?(subtargets, operation, self)
|
24
|
-
end
|
25
|
-
|
26
|
-
# check whether user can/cant perform an operation, raise an error when access
|
27
|
-
# is given
|
28
|
-
def cannot!(subtargets, operation)
|
29
|
-
self.class.cannot!(subtargets, operation, self)
|
30
|
-
end
|
31
|
-
|
32
|
-
def cant?(subtargets, operation)
|
33
|
-
puts "Deprecation Warning: please use cannot? instead, cant? will be deprecated on major release 3.0"
|
34
|
-
cannot?(subtargets, operation)
|
35
|
-
end
|
36
|
-
|
37
|
-
def cant!(subtargets, operation)
|
38
|
-
puts "Deprecation Warning: please use cannot! instead, cant! will be deprecated on major release 3.0"
|
39
|
-
cannot!(subtargets, operation)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# to allow class-level objection
|
44
|
-
module Bali::Objector::Statics
|
45
|
-
# get the proper roles for the subtarget, for any type of subtarget
|
46
|
-
def bali_translate_subtarget_roles(arg)
|
47
|
-
role_extractor = Bali::RoleExtractor.new(arg)
|
48
|
-
role_extractor.get_roles
|
49
|
-
end
|
50
|
-
|
51
|
-
def can?(subtarget_roles, operation, record = self, options = {})
|
52
|
-
subs = bali_translate_subtarget_roles(subtarget_roles)
|
53
|
-
# well, it is largely not used unless decider's is 2 arity
|
54
|
-
original_subtarget = options[:original_subtarget].nil? ? subtarget_roles : options[:original_subtarget]
|
55
|
-
|
56
|
-
judgement_value = false
|
57
|
-
role = nil
|
58
|
-
judger = nil
|
59
|
-
|
60
|
-
subs.each do |subtarget|
|
61
|
-
next if judgement_value == true
|
62
|
-
|
63
|
-
judge = Bali::Judger::Judge.build(:can, {
|
64
|
-
subtarget: subtarget,
|
65
|
-
original_subtarget: original_subtarget,
|
66
|
-
operation: operation,
|
67
|
-
record: record
|
68
|
-
})
|
69
|
-
judgement_value = judge.judgement
|
70
|
-
|
71
|
-
role = subtarget
|
72
|
-
end
|
73
|
-
|
74
|
-
if block_given?
|
75
|
-
yield original_subtarget, role, judgement_value
|
76
|
-
end
|
77
|
-
|
78
|
-
judgement_value
|
79
|
-
rescue => e
|
80
|
-
if e.is_a?(Bali::AuthorizationError) || e.is_a?(Bali::Error)
|
81
|
-
raise e
|
82
|
-
else
|
83
|
-
raise Bali::ObjectionError, e.message, e.backtrace
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def cannot?(subtarget_roles, operation, record = self, options = {})
|
88
|
-
subs = bali_translate_subtarget_roles subtarget_roles
|
89
|
-
original_subtarget = options[:original_subtarget].nil? ? subtarget_roles : options[:original_subtarget]
|
90
|
-
|
91
|
-
judgement_value = true
|
92
|
-
role = nil
|
93
|
-
judger = nil
|
94
|
-
|
95
|
-
subs.each do |subtarget|
|
96
|
-
next if judgement_value == false
|
97
|
-
|
98
|
-
judge = Bali::Judger::Judge.build(:cannot, {
|
99
|
-
subtarget: subtarget,
|
100
|
-
original_subtarget: original_subtarget,
|
101
|
-
operation: operation,
|
102
|
-
record: record
|
103
|
-
})
|
104
|
-
judgement_value = judge.judgement
|
105
|
-
|
106
|
-
role = subtarget
|
107
|
-
end
|
108
|
-
|
109
|
-
if block_given?
|
110
|
-
yield original_subtarget, role, judgement_value
|
111
|
-
end
|
112
|
-
|
113
|
-
judgement_value
|
114
|
-
rescue => e
|
115
|
-
if e.is_a?(Bali::AuthorizationError)
|
116
|
-
raise e
|
117
|
-
else
|
118
|
-
raise Bali::ObjectionError, e.message, e.backtrace
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def can!(subtarget_roles, operation, record = self, options = {})
|
123
|
-
can?(subtarget_roles, operation, record, options) do |original_subtarget, role, can_value|
|
124
|
-
if !can_value
|
125
|
-
auth_error = Bali::AuthorizationError.new
|
126
|
-
auth_error.auth_level = :can
|
127
|
-
auth_error.operation = operation
|
128
|
-
auth_error.role = role
|
129
|
-
auth_error.target = record
|
130
|
-
auth_error.subtarget = original_subtarget
|
131
|
-
|
132
|
-
if role
|
133
|
-
auth_error.subtarget = original_subtarget if !(original_subtarget.is_a?(Symbol) || original_subtarget.is_a?(String) || original_subtarget.is_a?(Array))
|
134
|
-
end
|
135
|
-
|
136
|
-
raise auth_error
|
137
|
-
else
|
138
|
-
return can_value
|
139
|
-
end # if cannot is false, means cannot
|
140
|
-
end # can?
|
141
|
-
end
|
142
|
-
|
143
|
-
def cant!(subtarget_roles, operation, record = self, options = {})
|
144
|
-
puts "Deprecation Warning: please use cannot! instead, cant! will be deprecated on major release 3.0"
|
145
|
-
cannot!(subtarget_roles, operation, record, options)
|
146
|
-
end
|
147
|
-
|
148
|
-
def cant?(subtarget_roles, operation)
|
149
|
-
puts "Deprecation Warning: please use cannot? instead, cant? will be deprecated on major release 3.0"
|
150
|
-
cannot?(subtarget_roles, operation)
|
151
|
-
end
|
152
|
-
|
153
|
-
def cannot!(subtarget_roles, operation, record = self, options = {})
|
154
|
-
cannot?(subtarget_roles, operation, record, options) do |original_subtarget, role, cant_value|
|
155
|
-
if cant_value == false
|
156
|
-
auth_error = Bali::AuthorizationError.new
|
157
|
-
auth_error.auth_level = :cannot
|
158
|
-
auth_error.operation = operation
|
159
|
-
auth_error.role = role
|
160
|
-
auth_error.target = record
|
161
|
-
auth_error.subtarget = original_subtarget
|
162
|
-
|
163
|
-
if role
|
164
|
-
auth_error.subtarget = original_subtarget if !(original_subtarget.is_a?(Symbol) || original_subtarget.is_a?(String) || original_subtarget.is_a?(Array))
|
165
|
-
end
|
166
|
-
|
167
|
-
raise auth_error
|
168
|
-
else
|
169
|
-
return cant_value
|
170
|
-
end # if cannot is false, means can
|
171
|
-
end # cannot?
|
172
|
-
end
|
173
|
-
end
|