bali 2.4.0 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +2 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +44 -2
  5. data/gemfiles/Gemfile-rails.5.0.x +7 -0
  6. data/gemfiles/Gemfile-rails.5.1.x +6 -0
  7. data/gemfiles/Gemfile-rails.5.2.x +6 -0
  8. data/gemfiles/Gemfile-rails.6.0.x +5 -0
  9. data/gemfiles/Gemfile-rails.edge +14 -0
  10. data/lib/bali.rb +33 -22
  11. data/lib/bali/config.rb +12 -0
  12. data/lib/bali/dsl_error.rb +3 -0
  13. data/lib/bali/{foundations/exceptions/bali_error.rb → error.rb} +0 -0
  14. data/lib/bali/judge.rb +221 -0
  15. data/lib/bali/printer.rb +42 -31
  16. data/lib/bali/rails/action_controller.rb +17 -0
  17. data/lib/bali/rails/action_view.rb +12 -0
  18. data/lib/bali/rails/active_record.rb +11 -0
  19. data/lib/bali/railtie.rb +13 -0
  20. data/lib/bali/role.rb +110 -0
  21. data/lib/bali/rspec/able_to_matcher.rb +39 -0
  22. data/lib/bali/rule.rb +17 -0
  23. data/lib/bali/ruler.rb +38 -0
  24. data/lib/bali/rules.rb +51 -0
  25. data/lib/bali/statics/active_record.rb +2 -0
  26. data/lib/bali/statics/authorizer.rb +65 -0
  27. data/lib/bali/statics/record.rb +13 -0
  28. data/lib/bali/statics/scope_ruler.rb +39 -0
  29. data/lib/bali/tasks/bali/print_rules.rake +9 -0
  30. data/lib/bali/version.rb +1 -1
  31. data/lib/generators/rails/USAGE +8 -0
  32. data/lib/generators/rails/rules_generator.rb +17 -0
  33. data/lib/generators/rails/templates/rules.rb +4 -0
  34. data/lib/generators/rspec/rules_generator.rb +12 -0
  35. data/lib/generators/rspec/templates/rules_spec.rb +7 -0
  36. metadata +131 -49
  37. data/lib/bali/dsl/map_rules_dsl.rb +0 -75
  38. data/lib/bali/dsl/rules_for_dsl.rb +0 -130
  39. data/lib/bali/foundations/all_foundations.rb +0 -17
  40. data/lib/bali/foundations/exceptions/authorization_error.rb +0 -38
  41. data/lib/bali/foundations/exceptions/dsl_error.rb +0 -3
  42. data/lib/bali/foundations/exceptions/objection_error.rb +0 -3
  43. data/lib/bali/foundations/judger/judge.rb +0 -329
  44. data/lib/bali/foundations/judger/negative_judge.rb +0 -40
  45. data/lib/bali/foundations/judger/positive_judge.rb +0 -41
  46. data/lib/bali/foundations/role_extractor.rb +0 -61
  47. data/lib/bali/foundations/rule/rule.rb +0 -55
  48. data/lib/bali/foundations/rule/rule_class.rb +0 -54
  49. data/lib/bali/foundations/rule/rule_group.rb +0 -91
  50. data/lib/bali/integrators/all_integrators.rb +0 -8
  51. data/lib/bali/integrators/rule_class_integrator.rb +0 -27
  52. data/lib/bali/integrators/rule_group_integrator.rb +0 -29
  53. data/lib/bali/integrators/rule_integrator.rb +0 -56
  54. data/lib/bali/objector.rb +0 -173
@@ -1,3 +1,3 @@
1
1
  module Bali
2
- VERSION = "2.4.0"
2
+ VERSION = "6.0.1"
3
3
  end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Stubs out a rule class in app/rules directory.
3
+
4
+ Examples:
5
+ `rails g rules book`
6
+
7
+ This creates:
8
+ app/rules/book_rules.rb
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Generators
5
+ class RulesGenerator < NamedBase
6
+ source_root File.expand_path("templates", __dir__)
7
+ check_class_collision suffix: Bali.config.suffix
8
+
9
+ def create_decorator_file
10
+ template "rules.rb",
11
+ File.join(Bali.config.rules_path, "#{file_name}_#{Bali.config.suffix.downcase}.rb")
12
+ end
13
+
14
+ hook_for :test_framework
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class <%= class_name %><%= Bali.config.suffix %> < Bali::Rules
4
+ end
@@ -0,0 +1,12 @@
1
+ module Rspec
2
+ module Generators
3
+ class RulesGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+
6
+ def create_spec_file
7
+ template "rules_spec.rb",
8
+ File.join("spec/rules", class_path, "#{file_name}_#{Bali.config.suffix.downcase}_spec.rb")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require '<%= File.exists?('spec/rails_helper.rb') ? 'rails_helper' : 'spec_helper' %>'
4
+
5
+ RSpec.describe <%= class_name %><%= Bali.config.suffix %> do
6
+
7
+ end
metadata CHANGED
@@ -1,97 +1,181 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bali
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
- - Adam Pahlevi
7
+ - Adam Notodikromo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-01 00:00:00.000000000 Z
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zeitwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '2.2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 5.0.0
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 5.0.0
13
47
  - !ruby/object:Gem::Dependency
14
48
  name: bundler
15
49
  requirement: !ruby/object:Gem::Requirement
16
50
  requirements:
17
- - - ~>
51
+ - - ">="
18
52
  - !ruby/object:Gem::Version
19
- version: '1.9'
53
+ version: '0'
20
54
  type: :development
21
55
  prerelease: false
22
56
  version_requirements: !ruby/object:Gem::Requirement
23
57
  requirements:
24
- - - ~>
58
+ - - ">="
25
59
  - !ruby/object:Gem::Version
26
- version: '1.9'
60
+ version: '0'
27
61
  - !ruby/object:Gem::Dependency
28
62
  name: rake
29
63
  requirement: !ruby/object:Gem::Requirement
30
64
  requirements:
31
- - - ~>
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec-rails
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "<="
80
+ - !ruby/object:Gem::Version
81
+ version: '4'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "<="
87
+ - !ruby/object:Gem::Version
88
+ version: '4'
89
+ - !ruby/object:Gem::Dependency
90
+ name: pry-byebug
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: simplecov
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '='
32
108
  - !ruby/object:Gem::Version
33
- version: '10.0'
109
+ version: '0.17'
34
110
  type: :development
35
111
  prerelease: false
36
112
  version_requirements: !ruby/object:Gem::Requirement
37
113
  requirements:
38
- - - ~>
114
+ - - '='
39
115
  - !ruby/object:Gem::Version
40
- version: '10.0'
116
+ version: '0.17'
41
117
  - !ruby/object:Gem::Dependency
42
- name: rspec
118
+ name: sqlite3
43
119
  requirement: !ruby/object:Gem::Requirement
44
120
  requirements:
45
- - - ~>
121
+ - - ">="
46
122
  - !ruby/object:Gem::Version
47
- version: '3.3'
123
+ version: '0'
48
124
  type: :development
49
125
  prerelease: false
50
126
  version_requirements: !ruby/object:Gem::Requirement
51
127
  requirements:
52
- - - ~>
128
+ - - ">="
53
129
  - !ruby/object:Gem::Version
54
- version: '3.3'
55
- description: ! "Bali (Bulwark Authorization Library) is a universal authorization
56
- library, in the sense that \n it does not assume you to
57
- use specific Ruby library/gem/framework."
130
+ version: '0'
131
+ description: Bali (Bulwark Authorization Library) is a to-the-point authorization
132
+ library for Rails.
58
133
  email:
59
- - adam.pahlevi@gmail.com
134
+ - abaihaqi@acm.org
60
135
  executables: []
61
136
  extensions: []
62
137
  extra_rdoc_files: []
63
138
  files:
64
- - .gitignore
65
- - .rspec
66
- - .travis.yml
139
+ - ".gitignore"
140
+ - ".rspec"
141
+ - ".travis.yml"
67
142
  - Gemfile
68
143
  - Rakefile
69
144
  - bali.gemspec
70
145
  - bin/console
71
146
  - bin/setup
147
+ - gemfiles/Gemfile-rails.5.0.x
148
+ - gemfiles/Gemfile-rails.5.1.x
149
+ - gemfiles/Gemfile-rails.5.2.x
150
+ - gemfiles/Gemfile-rails.6.0.x
151
+ - gemfiles/Gemfile-rails.edge
72
152
  - lib/bali.rb
73
- - lib/bali/dsl/map_rules_dsl.rb
74
- - lib/bali/dsl/rules_for_dsl.rb
75
- - lib/bali/foundations/all_foundations.rb
76
- - lib/bali/foundations/exceptions/authorization_error.rb
77
- - lib/bali/foundations/exceptions/bali_error.rb
78
- - lib/bali/foundations/exceptions/dsl_error.rb
79
- - lib/bali/foundations/exceptions/objection_error.rb
80
- - lib/bali/foundations/judger/judge.rb
81
- - lib/bali/foundations/judger/negative_judge.rb
82
- - lib/bali/foundations/judger/positive_judge.rb
83
- - lib/bali/foundations/role_extractor.rb
84
- - lib/bali/foundations/rule/rule.rb
85
- - lib/bali/foundations/rule/rule_class.rb
86
- - lib/bali/foundations/rule/rule_group.rb
87
- - lib/bali/integrators/all_integrators.rb
88
- - lib/bali/integrators/rule_class_integrator.rb
89
- - lib/bali/integrators/rule_group_integrator.rb
90
- - lib/bali/integrators/rule_integrator.rb
91
- - lib/bali/objector.rb
153
+ - lib/bali/config.rb
154
+ - lib/bali/dsl_error.rb
155
+ - lib/bali/error.rb
156
+ - lib/bali/judge.rb
92
157
  - lib/bali/printer.rb
158
+ - lib/bali/rails/action_controller.rb
159
+ - lib/bali/rails/action_view.rb
160
+ - lib/bali/rails/active_record.rb
161
+ - lib/bali/railtie.rb
162
+ - lib/bali/role.rb
163
+ - lib/bali/rspec/able_to_matcher.rb
164
+ - lib/bali/rule.rb
165
+ - lib/bali/ruler.rb
166
+ - lib/bali/rules.rb
167
+ - lib/bali/statics/active_record.rb
168
+ - lib/bali/statics/authorizer.rb
169
+ - lib/bali/statics/record.rb
170
+ - lib/bali/statics/scope_ruler.rb
171
+ - lib/bali/tasks/bali/print_rules.rake
93
172
  - lib/bali/version.rb
94
- homepage: https://github.com/saveav/bali
173
+ - lib/generators/rails/USAGE
174
+ - lib/generators/rails/rules_generator.rb
175
+ - lib/generators/rails/templates/rules.rb
176
+ - lib/generators/rspec/rules_generator.rb
177
+ - lib/generators/rspec/templates/rules_spec.rb
178
+ homepage: https://github.com/adamnoto/bali
95
179
  licenses:
96
180
  - MIT
97
181
  metadata: {}
@@ -101,19 +185,17 @@ require_paths:
101
185
  - lib
102
186
  required_ruby_version: !ruby/object:Gem::Requirement
103
187
  requirements:
104
- - - ! '>='
188
+ - - ">="
105
189
  - !ruby/object:Gem::Version
106
190
  version: '0'
107
191
  required_rubygems_version: !ruby/object:Gem::Requirement
108
192
  requirements:
109
- - - ! '>='
193
+ - - ">="
110
194
  - !ruby/object:Gem::Version
111
195
  version: '0'
112
196
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.4.8
197
+ rubygems_version: 3.0.3
115
198
  signing_key:
116
199
  specification_version: 4
117
- summary: Bali is a powerful, framework-agnostic, thread-safe Ruby language authorization
118
- library
200
+ summary: A to-the-point authorization library for Rails
119
201
  test_files: []
@@ -1,75 +0,0 @@
1
- # grand scheme of things begin here
2
- class Bali::MapRulesDsl
3
- attr_accessor :current_rule_class
4
-
5
- def initialize
6
- @@lock ||= Mutex.new
7
- end
8
-
9
- # defining rules
10
- def rules_for(target_class, options_hash = {}, &block)
11
- @@lock.synchronize do
12
- self.current_rule_class = Bali::RuleClass.new(target_class)
13
-
14
- parent_class = options_hash[:inherits] || options_hash["inherits"]
15
- if parent_class
16
- # in case there is inherits specification
17
- parent_is_class = parent_class.class
18
- fail Bali::DslError, 'inherits must take a class' unless parent_is_class
19
- rule_class_from_parent = Bali::Integrator::RuleClass.for(parent_class)
20
- fail Bali::DslError, "not yet defined a rule class for #{parent_class}" if rule_class_from_parent.nil?
21
- self.current_rule_class = rule_class_from_parent.clone(target_class: target_class)
22
- end
23
-
24
- Bali::RulesForDsl.new(self).instance_eval(&block)
25
-
26
- # done processing the block, now add the rule class
27
- Bali::Integrator::RuleClass.add(self.current_rule_class)
28
- end
29
- end
30
-
31
- # subtarget_class is the subtarget's class definition
32
- # field_name is the field that will be consulted when instantiated object of this class is passed in can? or cant?
33
- def roles_for(subtarget_class, field_name)
34
- Bali::TRANSLATED_SUBTARGET_ROLES[subtarget_class.to_s] = field_name
35
- nil
36
- end
37
-
38
- def describe(*params)
39
- fail Bali::DslError, "describe block must be within rules_for block"
40
- end
41
-
42
- def role(*params)
43
- fail Bali::DslError, "role block must be within rules_for block"
44
- end
45
-
46
- def can(*params)
47
- fail Bali::DslError, "can block must be within role block"
48
- end
49
-
50
- def cant(*params)
51
- puts "Deprecation Warning: declaring rules with cant will be deprecated on major release 3.0, use cannot instead"
52
- cannot *params
53
- end
54
-
55
- def cannot(*params)
56
- fail Bali::DslError, "cant block must be within role block"
57
- end
58
-
59
- def can_all(*params)
60
- fail Bali::DslError, "can_all block must be within role block"
61
- end
62
-
63
- def clear_rules
64
- fail Bali::DslError, "clear_rules must be called within role block"
65
- end
66
-
67
- def cant_all(*params)
68
- puts "Deprecation Warning: declaring rules with cant_all will be deprecated on major release 3.0, use cannot instead"
69
- cannot_all *params
70
- end
71
-
72
- def cannot_all(*params)
73
- fail Bali::DslError, "cant_all block must be within role block"
74
- end
75
- end
@@ -1,130 +0,0 @@
1
- # this class is used to define DSL after rules_for is invoked.
2
- # @author Adam Pahlevi Baihaqi
3
- class Bali::RulesForDsl
4
- attr_accessor :map_rules_dsl
5
- attr_accessor :current_rule_group
6
-
7
- # all to be processed subtargets
8
- attr_accessor :current_subtargets
9
-
10
- def initialize(map_rules_dsl)
11
- @@lock ||= Mutex.new
12
- self.map_rules_dsl = map_rules_dsl
13
- end
14
-
15
- def current_rule_class
16
- self.map_rules_dsl.current_rule_class
17
- end
18
- protected :current_rule_class
19
-
20
- def role(*params)
21
- @@lock.synchronize do
22
- bali_scrap_actors(*params)
23
- current_subtargets.each do |subtarget|
24
- bali_set_subtarget(subtarget)
25
-
26
- if block_given?
27
- yield
28
- else
29
- # if no block, then rules are defined using shortcut notation, eg:
30
- # role :user, can: [:edit]
31
- # the last element of which params must be a hash
32
- shortcut_rules = params[-1]
33
- unless shortcut_rules.is_a?(Hash)
34
- raise Bali::DslError, "Pass a hash for shortcut notation"
35
- end
36
-
37
- shortcut_can_rules = shortcut_rules[:can] || shortcut_rules["can"]
38
- shortcut_cannot_rules = shortcut_rules[:cannot] || shortcut_rules["cannot"]
39
-
40
- shortcut_rules.each do |auth_val, args|
41
- Bali::Integrator::Rule.add(auth_val, self.current_rule_group, *args)
42
- end # each shortcut rules
43
- end # whether block is given or not
44
- end # each subtarget
45
- end # sync
46
- end # role
47
-
48
- def describe(*params)
49
- puts "Bali Deprecation Warning: describing rules using describe will be deprecated on major release 3.0, use role instead"
50
- if block_given?
51
- role(*params) do
52
- yield
53
- end
54
- else
55
- role(*params)
56
- end
57
- end
58
-
59
- # others block
60
- def others(*params)
61
- if block_given?
62
- role("__*__") do
63
- yield
64
- end
65
- end
66
- end # others
67
-
68
- # clear all defined rules
69
- def clear_rules
70
- self.current_rule_group.clear_rules
71
- true
72
- end
73
-
74
- def can(*args)
75
- Bali::Integrator::Rule.add_can(self.current_rule_group, *args)
76
- end
77
-
78
- def cannot(*args)
79
- Bali::Integrator::Rule.add_cannot(self.current_rule_group, *args)
80
- end
81
-
82
- def cant(*operations)
83
- puts "Deprecation Warning: declaring rules with cant will be deprecated on major release 3.0, use cannot instead"
84
- cannot(*operations)
85
- end
86
-
87
- def can_all
88
- Bali::Integrator::RuleGroup.make_zeus(self.current_rule_group)
89
- end
90
-
91
- def cannot_all
92
- Bali::Integrator::RuleGroup.make_plant(self.current_rule_group)
93
- end
94
-
95
- def cant_all
96
- puts "Deprecation Warning: declaring rules with cant_all will be deprecated on major release 3.0, use cannot_all instead"
97
- cannot_all
98
- end
99
-
100
- private
101
- def bali_scrap_actors(*params)
102
- self.current_subtargets = []
103
- params.each do |passed_argument|
104
- if passed_argument.is_a?(Symbol) || passed_argument.is_a?(String)
105
- self.current_subtargets << passed_argument
106
- elsif passed_argument.is_a?(NilClass)
107
- self.current_subtargets << passed_argument
108
- elsif passed_argument.is_a?(Array)
109
- self.current_subtargets += passed_argument
110
- end
111
- end
112
- nil
113
- end
114
-
115
- # set the current processing on a specific subtarget
116
- def bali_set_subtarget(subtarget)
117
- rule_class = self.map_rules_dsl.current_rule_class
118
- target_class = rule_class.target_class
119
-
120
- rule_group = rule_class.rules_for(subtarget)
121
-
122
- if rule_group.nil?
123
- rule_group = Bali::RuleGroup.new(target_class, subtarget)
124
- end
125
-
126
- rule_class.add_rule_group rule_group
127
- self.current_rule_group = rule_group
128
- end
129
-
130
- end # class