admission 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/admission.gemspec +7 -7
  3. data/lib/admission/version.rb +1 -1
  4. metadata +5 -48
  5. data/.gitignore +0 -40
  6. data/.rspec +0 -2
  7. data/.ruby-version +0 -1
  8. data/Gemfile +0 -7
  9. data/LICENSE +0 -674
  10. data/README.md +0 -24
  11. data/bin/build +0 -10
  12. data/bin/rspec +0 -8
  13. data/spec/integration/action_arbitrating_spec.rb +0 -119
  14. data/spec/integration/resource_arbitrating_spec.rb +0 -276
  15. data/spec/rspec_config.rb +0 -103
  16. data/spec/spec_helper.rb +0 -28
  17. data/spec/test_context/country.rb +0 -24
  18. data/spec/test_context/index.rb +0 -5
  19. data/spec/test_context/person.rb +0 -31
  20. data/spec/test_context/persons_fixtures.rb +0 -43
  21. data/spec/test_context/privileges_and_rules.rb +0 -119
  22. data/spec/unit/arbitration_spec.rb +0 -33
  23. data/spec/unit/index_spec.rb +0 -144
  24. data/spec/unit/privilege/order_definer_spec.rb +0 -184
  25. data/spec/unit/privilege_spec.rb +0 -178
  26. data/spec/unit/rails/action_admission_spec.rb +0 -188
  27. data/spec/unit/rails/controller_addon_spec.rb +0 -68
  28. data/spec/unit/rails/scope_resolver_spec.rb +0 -72
  29. data/spec/unit/resource_arbitration_spec.rb +0 -76
  30. data/spec/unit/status_spec.rb +0 -79
  31. data/visualisation/.babelrc +0 -7
  32. data/visualisation/actions/index.js +0 -0
  33. data/visualisation/components/app_container.jsx +0 -78
  34. data/visualisation/components/input_with_select.jsx +0 -177
  35. data/visualisation/components/nested_list_row.jsx +0 -48
  36. data/visualisation/components/privilege_select.jsx +0 -70
  37. data/visualisation/components/privileges_panel.jsx +0 -73
  38. data/visualisation/components/rules_panel.jsx +0 -124
  39. data/visualisation/dist/.gitkeep +0 -0
  40. data/visualisation/helpers.js +0 -69
  41. data/visualisation/index.jsx +0 -89
  42. data/visualisation/package.json +0 -27
  43. data/visualisation/reducers/index.js +0 -35
  44. data/visualisation/server.rb +0 -23
  45. data/visualisation/style.scss +0 -248
  46. data/visualisation/webpack.config.js +0 -47
  47. data/visualisation/yarn.lock +0 -3354
data/README.md DELETED
@@ -1,24 +0,0 @@
1
- # Admission
2
- A system to manage user privileges. Heavily inspired by cancan.
3
-
4
- ### Is it "cancancancan"?
5
- Yes, sort of. It's built around the same premise: having an index of rules, which resolve into entitling allowance for an user to a named action. But in Cancan you have to create your own system of privileges. Admission on the other hand is meant for the cases where you need the user to have multiple privileges, while having clear rules to resolve precedences between them.
6
-
7
- The other thing that always bugged me about cancan (and was proven problematic in production) is that users' ability rules are loaded every time again, for every instance of the user record. I tried to introduce some kind of caching - only ended up making this library.
8
-
9
- ## Is it any good?
10
- [yes](https://news.ycombinator.com/item?id=3067434)
11
-
12
- ## write-me please
13
- ### status
14
- * used in production for a rails app
15
- * tests are only "ok"
16
- * documentation non-existent
17
-
18
- ### to-do list
19
- - [ ] reuse arbitration instance
20
- - [x] Admission::Denied must be able to tell the requested action and scope
21
- - [x] minitest helpers
22
- - [ ] rspec helpers
23
- - [ ] test guides
24
- - [ ] rails example
data/bin/build DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- cd visualisation
4
- yarn run build
5
-
6
- cd ..
7
- git add -f visualisation/dist/app.js
8
-
9
- rm *.gem
10
- gem build admission.gemspec
data/bin/rspec DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- # Set up gems listed in the Gemfile.
5
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
6
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
7
-
8
- load Gem.bin_path('rspec-core', 'rspec')
@@ -1,119 +0,0 @@
1
- require_relative '../spec_helper'
2
-
3
- RSpec.describe 'actions_arbitrating' do
4
-
5
- def arbitration request, context=nil
6
- person = Person.new 'person', Person::MALE, [:czech]
7
- arbitration = Admission::Arbitration.new person, ACTIONS_RULES, request
8
- arbitration.prepare_sitting context
9
- arbitration
10
- end
11
-
12
- def privilege *args, context: nil
13
- p = Admission::Privilege.get_from_order PRIVILEGES_ORDER, *args
14
- p = p.dup_with_context context if context
15
- p
16
- end
17
-
18
- def rule request, privilege
19
- arbitration(request, privilege.context).rule_per_privilege privilege
20
- end
21
-
22
- it 'allows human to do anything' do
23
- expect(
24
- rule :anything, privilege(:human)
25
- ).to eql(true)
26
- end
27
-
28
- it 'disallows woman to do anything' do
29
- person = Person.new 'person', Person::FEMALE, [:czech]
30
- arbitration = Admission::Arbitration.new person, ACTIONS_RULES, :anything
31
- arbitration.prepare_sitting
32
- expect(
33
- arbitration.rule_per_privilege privilege(:human)
34
- ).to eql(false)
35
- end
36
-
37
- it 'allow woman-count to do anything in her country' do
38
- person = Person.new 'person', Person::FEMALE, [:czech]
39
- arbitration = Admission::Arbitration.new person, ACTIONS_RULES, :anything
40
- arbitration.prepare_sitting :czech
41
- expect(
42
- arbitration.rule_per_privilege privilege(:human, :count, context: :czech)
43
- ).to eql(true)
44
- end
45
-
46
- it 'allows only king to raise taxes' do
47
- expect(
48
- rule :raise_taxes, privilege(:human)
49
- ).to eql(:forbidden)
50
-
51
- expect(
52
- rule :raise_taxes, privilege(:human, :count)
53
- ).to eql(:forbidden)
54
-
55
- expect(
56
- rule :raise_taxes, privilege(:human, :king)
57
- ).to eql(true)
58
- end
59
-
60
- it 'allows count and king to impose corvee in his countries' do
61
- expect(
62
- rule :impose_corvee,
63
- privilege(:human, :count, context: :czech)
64
- ).to eql(true)
65
-
66
- expect(
67
- rule :impose_corvee,
68
- privilege(:human, :king, context: :czech)
69
- ).to eql(true)
70
- end
71
-
72
- it 'forbids count and king to impose corvee outside his countries' do
73
- expect(
74
- rule :impose_corvee,
75
- privilege(:human, :count, context: :taiwan)
76
- ).to eql(:forbidden)
77
-
78
- expect(
79
- rule :impose_corvee,
80
- privilege(:human, :king, context: :taiwan)
81
- ).to eql(:forbidden)
82
- end
83
-
84
- it 'forbids any human to impose a draft' do
85
- expect(
86
- rule :impose_draft, privilege(:human)
87
- ).to eql(:forbidden)
88
-
89
- expect(
90
- rule :impose_draft, privilege(:human, :count)
91
- ).to eql(:forbidden)
92
-
93
- expect(
94
- rule :impose_draft, privilege(:human, :king)
95
- ).to eql(:forbidden)
96
- end
97
-
98
- it 'allows lord to impose draft' do
99
- expect(
100
- rule :impose_draft,
101
- privilege(:vassal, :lord)
102
- ).to eql(true)
103
- end
104
-
105
- it 'forbids emperor to impose draft because of inheritance' do
106
- expect(
107
- rule :impose_draft,
108
- privilege(:emperor)
109
- ).to eql(:forbidden)
110
- end
111
-
112
- it 'allows emperor to act as god' do
113
- expect(
114
- rule :act_as_god,
115
- privilege(:emperor)
116
- ).to eql(true)
117
- end
118
-
119
- end
@@ -1,276 +0,0 @@
1
- require_relative '../spec_helper'
2
-
3
- RSpec.describe 'resources_arbitrating' do
4
-
5
- let(:person){ Person.new 'person', Person::MALE, [:czech] }
6
- let(:female){ Person.new 'female', Person::FEMALE, [:czech] }
7
-
8
- def arbitration scope, action, context=nil
9
- arbitration = Admission::ResourceArbitration.new person, RESOURCE_RULES, action, scope
10
- arbitration.prepare_sitting context
11
- arbitration
12
- end
13
-
14
- def privilege *args, context: nil
15
- p = Admission::Privilege.get_from_order PRIVILEGES_ORDER, *args
16
- p = p.dup_with_context context if context
17
- p
18
- end
19
-
20
- def actions_rule action, privilege
21
- arbitration(:actions, action, privilege.context).rule_per_privilege privilege
22
- end
23
-
24
- def rule scope, action, privilege
25
- arbitration(scope, action, privilege.context).rule_per_privilege privilege
26
- end
27
-
28
- describe 'actions scope' do
29
-
30
- it 'allows human to do anything' do
31
- expect(
32
- actions_rule :anything, privilege(:human)
33
- ).to eql(true)
34
- end
35
-
36
- it 'disallows woman to do anything' do
37
- arbitration = Admission::ResourceArbitration.new female, RESOURCE_RULES,
38
- :anything, :actions
39
- arbitration.prepare_sitting
40
- expect(
41
- arbitration.rule_per_privilege privilege(:human)
42
- ).to eql(false)
43
- end
44
-
45
- it 'allow woman-count to do anything in her country' do
46
- arbitration = Admission::ResourceArbitration.new female, RESOURCE_RULES,
47
- :anything, :actions
48
- arbitration.prepare_sitting :czech
49
- expect(
50
- arbitration.rule_per_privilege privilege(:human, :count, context: :czech)
51
- ).to eql(true)
52
- end
53
-
54
- it 'allows only king to raise taxes' do
55
- expect(
56
- actions_rule :raise_taxes, privilege(:human)
57
- ).to eql(:forbidden)
58
-
59
- expect(
60
- actions_rule :raise_taxes, privilege(:human, :count)
61
- ).to eql(:forbidden)
62
-
63
- expect(
64
- actions_rule :raise_taxes, privilege(:human, :king)
65
- ).to eql(true)
66
- end
67
-
68
- it 'allows count and king to impose corvee in his countries' do
69
- expect(
70
- actions_rule :impose_corvee,
71
- privilege(:human, :count, context: :czech)
72
- ).to eql(true)
73
-
74
- expect(
75
- actions_rule :impose_corvee,
76
- privilege(:human, :king, context: :czech)
77
- ).to eql(true)
78
- end
79
-
80
- it 'forbids count and king to impose corvee outside his countries' do
81
- expect(
82
- actions_rule :impose_corvee,
83
- privilege(:human, :count, context: :taiwan)
84
- ).to eql(:forbidden)
85
-
86
- expect(
87
- actions_rule :impose_corvee,
88
- privilege(:human, :king, context: :taiwan)
89
- ).to eql(:forbidden)
90
- end
91
-
92
- it 'forbids any human to impose a draft' do
93
- expect(
94
- actions_rule :impose_draft, privilege(:human)
95
- ).to eql(:forbidden)
96
-
97
- expect(
98
- actions_rule :impose_draft, privilege(:human, :count)
99
- ).to eql(:forbidden)
100
-
101
- expect(
102
- actions_rule :impose_draft, privilege(:human, :king)
103
- ).to eql(:forbidden)
104
- end
105
-
106
- it 'allows lord to impose draft' do
107
- expect(
108
- actions_rule :impose_draft, privilege(:vassal, :lord)
109
- ).to eql(true)
110
- end
111
-
112
- it 'forbids emperor to impose draft because of inheritance' do
113
- expect(
114
- actions_rule :impose_draft, privilege(:emperor)
115
- ).to eql(:forbidden)
116
- end
117
-
118
- it 'allows emperor to act as god' do
119
- expect(
120
- actions_rule :act_as_god, privilege(:emperor)
121
- ).to eql(true)
122
- end
123
-
124
- end
125
-
126
- describe 'resources scope' do
127
-
128
- it 'allows vassal to see only himself' do
129
- expect(
130
- rule person, :show, privilege(:vassal)
131
- ).to eql(true)
132
-
133
- person = Person.new 'person', Person::FEMALE, [:czech]
134
- expect(
135
- rule person, :show, privilege(:vassal)
136
- ).to eql(false)
137
- end
138
-
139
- it 'passes nil as argument if resource-arbiter accessed by name-scope' do
140
- expect{
141
- rule :persons, :show, privilege(:vassal)
142
- }.to raise_error('person is nil')
143
- end
144
-
145
- it 'allows vassal to list persons only per his countries' do
146
- expect(
147
- rule :persons, :index, privilege(:vassal, context: :czech)
148
- ).to eql(true)
149
-
150
- expect(
151
- rule :persons, :index, privilege(:vassal, context: :taiwan)
152
- ).to eql(false)
153
- end
154
-
155
- it 'allows access scope-arbiter by resource' do
156
- expect(
157
- rule person, :index, privilege(:vassal, context: :czech)
158
- ).to eql(true)
159
- end
160
-
161
- it 'allows lord to see any person' do
162
- expect(
163
- rule person, :show, privilege(:vassal, :lord)
164
- ).to eql(true)
165
-
166
- expect(
167
- rule female, :show, privilege(:vassal, :lord)
168
- ).to eql(true)
169
- end
170
-
171
- it 'allows lord to list persons from his country' do
172
- expect(
173
- rule person, :index, privilege(:vassal, context: :czech)
174
- ).to eql(true)
175
-
176
- expect(
177
- rule :persons, :index, privilege(:vassal, context: :czech)
178
- ).to eql(true)
179
-
180
- expect(
181
- rule person, :index, privilege(:vassal, context: :taiwan)
182
- ).to eql(false)
183
- end
184
-
185
- it 'allows lord to update person that is from his country' do
186
- expect(
187
- rule female, :update,
188
- privilege(:vassal, :lord, context: :czech)
189
- ).to eql(true)
190
-
191
- expect(
192
- rule female, :update, privilege(:vassal, :lord)
193
- ).to eql(false)
194
- end
195
-
196
- it 'disallows lord to update person not from his country' do
197
- female = Person.new 'person', Person::FEMALE, [:taiwan]
198
-
199
- expect(
200
- rule female, :update,
201
- privilege(:vassal, :lord, context: :czech)
202
- ).to eql(false)
203
-
204
- expect(
205
- rule female, :update,
206
- privilege(:vassal, :lord, context: :taiwan)
207
- ).to eql(false)
208
- end
209
-
210
- it 'ensures lord cannot update person accessing him by scope-name' do
211
- expect(
212
- rule :persons, :update, privilege(:vassal, :lord)
213
- ).to eql(false)
214
- end
215
-
216
- it 'disallows vassal to update person' do
217
- expect(
218
- rule person, :update, privilege(:vassal, context: :czech)
219
- ).to eql(false)
220
- end
221
-
222
- it 'allows lord to destroy person from his country' do
223
- female = Person.new 'person', Person::FEMALE, [:taiwan]
224
-
225
- expect(
226
- rule person, :destroy,
227
- privilege(:vassal, :lord, context: :czech)
228
- ).to eql(true)
229
-
230
- expect(
231
- rule female, :destroy,
232
- privilege(:vassal, :lord, context: :czech)
233
- ).to eql(false)
234
- end
235
-
236
- it 'disallows lord to destroy apache helicopter' do
237
- helicopter = Person.new 'person', Person::APACHE_HELICOPTER, [:czech]
238
- expect(
239
- rule helicopter, :destroy,
240
- privilege(:vassal, :lord, context: :czech)
241
- ).to eql(false)
242
- end
243
-
244
- end
245
-
246
- describe 'nested resource scope' do
247
-
248
- it 'allows any lord to list others possessions' do
249
- expect(
250
- rule [person, :possessions], :index, privilege(:vassal, :lord)
251
- ).to eql(true)
252
-
253
- expect(
254
- rule [person, :possessions], :index, privilege(:vassal)
255
- ).to eql(false)
256
- end
257
-
258
- it 'allows lord to update possessions of his country' do
259
- expect(
260
- rule [person, :possessions], :update, privilege(:vassal, :lord)
261
- ).to eql(false)
262
-
263
- expect(
264
- rule [person, :possessions], :update,
265
- privilege(:vassal, :lord, context: :czech)
266
- ).to eql(true)
267
-
268
- expect(
269
- rule [person, :possessions], :update,
270
- privilege(:vassal, :lord, context: :taiwan)
271
- ).to eql(false)
272
- end
273
-
274
- end
275
-
276
- end
@@ -1,103 +0,0 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # The generated `.rspec` file contains `--require spec_helper` which will cause
4
- # this file to always be loaded, without a need to explicitly require it in any
5
- # files.
6
- #
7
- # Given that it is always loaded, you are encouraged to keep this file as
8
- # light-weight as possible. Requiring heavyweight dependencies from this file
9
- # will add to the boot time of your test suite on EVERY test run, even for an
10
- # individual file that may not need all of that loaded. Instead, consider making
11
- # a separate helper file that requires the additional dependencies and performs
12
- # the additional setup, and require it from the spec files that actually need
13
- # it.
14
- #
15
- # The `.rspec` file also contains a few flags that are not defaults but that
16
- # users commonly want.
17
- #
18
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
- RSpec.configure do |config|
20
- # rspec-expectations config goes here. You can use an alternate
21
- # assertion/expectation library such as wrong or the stdlib/minitest
22
- # assertions if you prefer.
23
- config.expect_with :rspec do |expectations|
24
- # This option will default to `true` in RSpec 4. It makes the `description`
25
- # and `failure_message` of custom matchers include text for helper methods
26
- # defined using `chain`, e.g.:
27
- # be_bigger_than(2).and_smaller_than(4).description
28
- # # => "be bigger than 2 and smaller than 4"
29
- # ...rather than:
30
- # # => "be bigger than 2"
31
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
- end
33
-
34
- # rspec-mocks config goes here. You can use an alternate test double
35
- # library (such as bogus or mocha) by changing the `mock_with` option here.
36
- config.mock_with :rspec do |mocks|
37
- # Prevents you from mocking or stubbing a method that does not exist on
38
- # a real object. This is generally recommended, and will default to
39
- # `true` in RSpec 4.
40
- mocks.verify_partial_doubles = true
41
- end
42
-
43
- # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44
- # have no way to turn it off -- the option exists only for backwards
45
- # compatibility in RSpec 3). It causes shared context metadata to be
46
- # inherited by the metadata hash of host groups and examples, rather than
47
- # triggering implicit auto-inclusion in groups with matching metadata.
48
- config.shared_context_metadata_behavior = :apply_to_host_groups
49
-
50
- # The settings below are suggested to provide a good initial experience
51
- # with RSpec, but feel free to customize to your heart's content.
52
-
53
- # This allows you to limit a spec run to individual examples or groups
54
- # you care about by tagging them with `:focus` metadata. When nothing
55
- # is tagged with `:focus`, all examples get run. RSpec also provides
56
- # aliases for `it`, `describe`, and `context` that include `:focus`
57
- # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
58
- # config.filter_run_when_matching :focus
59
-
60
- # Allows RSpec to persist some state between runs in order to support
61
- # the `--only-failures` and `--next-failure` CLI options. We recommend
62
- # you configure your source control system to ignore this file.
63
- # config.example_status_persistence_file_path = "spec/examples.txt"
64
-
65
- # Limits the available syntax to the non-monkey patched syntax that is
66
- # recommended. For more details, see:
67
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
70
- config.disable_monkey_patching!
71
-
72
- # This setting enables warnings. It's recommended, but in some cases may
73
- # be too noisy due to issues in dependencies.
74
- # config.warnings = true
75
-
76
- # Many RSpec users commonly either run the entire suite or an individual
77
- # file, and it's useful to allow more verbose output when running an
78
- # individual spec file.
79
- # if config.files_to_run.one?
80
- # # Use the documentation formatter for detailed output,
81
- # # unless a formatter has already been configured
82
- # # (e.g. via a command-line flag).
83
- # config.default_formatter = 'doc'
84
- # end
85
-
86
- # Print the 10 slowest examples and example groups at the
87
- # end of the spec run, to help surface which specs are running
88
- # particularly slow.
89
- # config.profile_examples = 10
90
-
91
- # Run specs in random order to surface order dependencies. If you find an
92
- # order dependency and want to debug it, you can fix the order by providing
93
- # the seed, which is printed after each run.
94
- # --seed 1234
95
- config.order = :random
96
-
97
- # Seed global randomization in this process using the `--seed` CLI option.
98
- # Setting this allows you to use `--seed` to deterministically reproduce
99
- # test failures related to randomization by passing the same `--seed` value
100
- # as the one that triggered the failure.
101
- # Kernel.srand config.seed
102
-
103
- end