admission 0.4.5 → 0.4.6

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.
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
@@ -1,28 +0,0 @@
1
- require_relative 'rspec_config'
2
-
3
- require 'byebug'
4
-
5
- def with_bug
6
- $bug = true
7
- yield
8
- ensure
9
- $bug = false
10
- end
11
-
12
- RSpec::Matchers.define :have_inst_vars do |expected|
13
- match do |object|
14
- expected.to_a.all? do |var_name, value|
15
- var = object.instance_variable_get "@#{var_name}"
16
- var == value
17
- end
18
- end
19
- end
20
-
21
- require 'simplecov'
22
- SimpleCov.start do
23
- add_filter %r~^(?!/lib/)~
24
- end
25
-
26
- require_relative '../lib/admission'
27
- require_relative '../lib/admission/rails'
28
- require_relative './test_context/index'
@@ -1,24 +0,0 @@
1
- # COUNTRIES = [
2
- # :czech,
3
- # :deutschland,
4
- # :taiwan,
5
- # :russia,
6
- # :australia,
7
- # :moon
8
- # ]
9
- #
10
- # class << COUNTRIES
11
- #
12
- # def europe? country
13
- # %i[czech deutschland russia].include? country
14
- # end
15
- #
16
- # def safe? country
17
- # %i[czech deutschland taiwan].include? country
18
- # end
19
- #
20
- # def are_you_dispensable? person
21
- # not (%i[russia] & person.countries).empty?
22
- # end
23
- #
24
- # end
@@ -1,5 +0,0 @@
1
- require_relative 'country'
2
- require_relative 'person'
3
-
4
- require_relative 'privileges_and_rules'
5
- require_relative 'persons_fixtures'
@@ -1,31 +0,0 @@
1
-
2
- class Person
3
-
4
- attr_reader :name, :sex, :countries
5
- attr_reader :privileges, :rules
6
-
7
- FEMALE = 0
8
- MALE = 1
9
- APACHE_HELICOPTER = 2
10
-
11
- def initialize name, sex, countries
12
- @name = name
13
- @sex = sex
14
- @countries = countries
15
- end
16
-
17
-
18
- # privileges per country
19
-
20
- def not_woman?
21
- @sex != FEMALE
22
- end
23
-
24
- def person
25
- self
26
- end
27
-
28
- # def self.reduce_privileges **per_country
29
- # end
30
-
31
- end
@@ -1,43 +0,0 @@
1
-
2
- fixtures = {
3
-
4
- peasant_girl: [
5
- Person::FEMALE,
6
- []
7
- ],
8
-
9
- napoleon: [
10
- Person::MALE,
11
- []
12
- # {all: 'harambe'}
13
- ],
14
-
15
- franz_joseph: [
16
- Person::MALE,
17
- [:czech, :australia]
18
- # {czech: 'supernatural-primordial', taiwan: 'supernatural-god'}
19
- ]
20
-
21
- }
22
-
23
- privileges_data_reducer = -> (privileges_data) {
24
- privileges_data.to_a.reduce [] do |list, per_country_definition|
25
- country, privileges_names = per_country_definition
26
- raise "bad country #{country}" unless COUNTRIES.include? country
27
- privileges_names = [privileges_names] unless privileges_names.is_a? Array
28
-
29
- privileges = privileges_names.map do |name|
30
- privilege = Admission::Privilege.get_from_order PRIVILEGES_ORDER, *name.split('-')
31
- privilege.dup_with_context country
32
- end
33
-
34
- list + privileges
35
- end
36
- }
37
-
38
- Person::FIXTURES = ->(name) {
39
- *attrs, privileges = fixtures[name]
40
- person = Person.new name, *attrs
41
- person.instance_variable_set :@privileges, privileges_data_reducer.(privileges)
42
- person
43
- }
@@ -1,119 +0,0 @@
1
-
2
-
3
- PRIVILEGES_ORDER = Admission::Privilege.define_order do
4
- privilege :vassal, levels: %i[lord]
5
- privilege :human, levels: %i[count king]
6
- privilege :emperor, inherits: %i[vassal human]
7
- end
8
-
9
-
10
- ACTIONS_RULES = Admission::Arbitration.define_rules PRIVILEGES_ORDER do
11
-
12
- privilege :human do
13
- allow_all{ not_woman? }
14
- forbid :raise_taxes
15
- forbid :impose_corvee
16
-
17
- forbid :impose_draft
18
- forbid :act_as_god
19
- end
20
-
21
- privilege :human, :count do
22
- allow_all do |country|
23
- countries.include? country
24
- end
25
- allow :impose_corvee do |country|
26
- countries.include? country
27
- end
28
- end
29
-
30
- privilege :human, :king do
31
- allow_all
32
- allow :raise_taxes
33
- end
34
-
35
- privilege :vassal, :lord do
36
- allow :impose_draft
37
- end
38
-
39
- privilege :emperor do
40
- allow :act_as_god
41
- end
42
-
43
- end
44
-
45
-
46
- RESOURCE_RULES = Admission::ResourceArbitration.define_rules PRIVILEGES_ORDER do
47
-
48
- # `allow_all` & inheriting `:forbidden`
49
-
50
- privilege :human do
51
- allow_all(:actions){ not_woman? }
52
- forbid :actions, :raise_taxes
53
- forbid :actions, :impose_corvee
54
-
55
- forbid :actions, :impose_draft
56
- forbid :actions, :act_as_god
57
- end
58
-
59
- privilege :human, :count do
60
- allow_all :actions do |country|
61
- countries.include? country
62
- end
63
- allow :actions, :impose_corvee do |country|
64
- countries.include? country
65
- end
66
- end
67
-
68
- privilege :human, :king do
69
- allow_all :actions
70
- allow :actions, :raise_taxes
71
- end
72
-
73
- privilege :vassal, :lord do
74
- allow :actions, :impose_draft
75
- end
76
-
77
- privilege :emperor do
78
- allow :actions, :act_as_god
79
- end
80
-
81
- # `allow_resource` scoping & inheritance
82
-
83
- privilege :vassal do
84
-
85
- allow_resource Person, :show do |person, *|
86
- raise 'person is nil' unless person
87
- self == person
88
- end
89
-
90
- allow :persons, :index do |country|
91
- countries.include? country
92
- end
93
-
94
- end
95
-
96
- privilege :vassal, :lord do
97
-
98
- allow_resource(Person, :show){ true }
99
-
100
- allow_resource Person, %i[index update] do |person, country|
101
- allowance = countries.include? country
102
- next allowance unless person
103
-
104
- allowance && person.countries.include?(country)
105
- end
106
-
107
- allow_resource Person, :destroy do |person, country|
108
- person.countries.include?(country) &&
109
- person.sex != Person::APACHE_HELICOPTER
110
- end
111
-
112
- allow Admission::ResourceArbitration.nested_scope(Person, :possessions), :index
113
- allow_resource [Person, :possessions], :update do |person, country|
114
- person.countries.include?(country)
115
- end
116
-
117
- end
118
-
119
- end
@@ -1,33 +0,0 @@
1
- require_relative '../spec_helper'
2
-
3
- RSpec.describe Admission::Arbitration do
4
-
5
- describe 'RulesBuilder' do
6
-
7
- describe 'fails when given reserved action name' do
8
-
9
- let(:builder){
10
- builder = Admission::Arbitration::RulesBuilder.new nil
11
- builder.instance_variable_set '@privilege', 'privilege'
12
- builder
13
- }
14
-
15
- it '#allow' do
16
- expect{ builder.allow '', :allow }.not_to raise_exception
17
- expect{ builder.allow '', Admission::ALL_ACTION }.to(
18
- raise_exception("reserved action name #{Admission::ALL_ACTION}")
19
- )
20
- end
21
-
22
- it '#forbid' do
23
- expect{ builder.forbid '', :forbid }.not_to raise_exception
24
- expect{ builder.forbid '', Admission::ALL_ACTION }.to(
25
- raise_exception("reserved action name #{Admission::ALL_ACTION}")
26
- )
27
- end
28
-
29
- end
30
-
31
- end
32
-
33
- end
@@ -1,144 +0,0 @@
1
- require_relative '../spec_helper'
2
-
3
- RSpec.describe Admission::Index do
4
-
5
- let(:index){ Admission::Index.new }
6
-
7
- def instance_with items=[], children={}
8
- index = Admission::Index.new
9
- index.instance_variable_set '@items', items
10
- index.instance_variable_set '@children', children
11
- index
12
- end
13
-
14
- describe '#to_a' do
15
-
16
- it 'empty' do
17
- expect(instance_with.to_a).to eq([])
18
- end
19
-
20
- it 'non-nested' do
21
- index = instance_with [:item1, :item2]
22
- expect(index.to_a).to eq(
23
- [:item1, :item2]
24
- )
25
- end
26
-
27
- it 'nested one level' do
28
- index = instance_with [:item1, :item2], {nested: instance_with([:n1])}
29
- expect(index.to_a).to eq(
30
- [:item1, :item2, {nested: [:n1]}]
31
- )
32
- end
33
-
34
- it 'nested two levels' do
35
- index = instance_with [:item1, :item2],
36
- {
37
- nested1a: instance_with([:n1a]),
38
- nested1b: instance_with([:n1b, {nested2a: instance_with([:n2a, :n2b])}])
39
- }
40
- expect(index.to_a).to eq(
41
- [:item1, :item2, {nested1a: [:n1a], nested1b: [:n1b, {nested2a: [:n2a, :n2b]}]}]
42
- )
43
- end
44
-
45
- end
46
-
47
- describe '#==' do
48
-
49
- it 'compares two instances' do
50
- instance1 = instance_with
51
- expect(instance1).not_to receive(:to_a)
52
- instance2 = instance_with
53
- expect(instance2).not_to receive(:to_a)
54
-
55
- expect(instance1 == instance2).not_to be_truthy
56
- expect(instance2 == instance1).not_to be_truthy
57
- expect(instance1 == instance1).to be_truthy
58
- expect(instance2 == instance2).to be_truthy
59
- end
60
-
61
- it 'compares with an array using conversion' do
62
- instance1 = instance_with [:item1]
63
- expect(instance1).to receive(:to_a).and_call_original
64
- expect(instance1 == [:item1]).to be_truthy
65
- end
66
-
67
- it 'tests rspec eq() delegates to #eql?, i.e. #==' do
68
- instance1 = instance_with [:item1]
69
- expect(instance1).to receive(:==).and_call_original
70
- expect(instance1).to eq([:item1])
71
- end
72
-
73
- end
74
-
75
- describe '#allow' do
76
-
77
- it 'single' do
78
- index.allow :single
79
- expect(index).to eq([:single])
80
- end
81
-
82
- it 'passed as args' do
83
- index.allow :single, :double
84
- expect(index).to eq([:single, :double])
85
- end
86
-
87
- it 'passed as arrays' do
88
- index.allow :single, [:a1, :a2], :double, [:b1, :b2]
89
- expect(index).to eq([:single, :a1, :a2, :double, :b1, :b2])
90
- end
91
-
92
- it 'convert args to symbols' do
93
- index.allow 'single', ['a1', 'a2'], 'double', ['b1', 'b2']
94
- expect(index).to eq([:single, :a1, :a2, :double, :b1, :b2])
95
- end
96
-
97
- it 'passed as keyword args, nested item' do
98
- index.allow :single, nested: :a1
99
- expect(index).to eq([:single, {nested: [:a1]}])
100
- end
101
-
102
- it 'passed as last position hash' do
103
- index.allow :single, {nested: :a1}
104
- expect(index).to eq([:single, {nested: [:a1]}])
105
- end
106
-
107
- it 'passed as keyword args, nested item list' do
108
- index.allow :single, nested: [:a1]
109
- expect(index).to eq([:single, {nested: [:a1]}])
110
- end
111
-
112
- it 'passed as keyword args, deep nested' do
113
- index.allow :single, nested: [:a1, {deep_nested: :b1}]
114
- expect(index).to eq([:single, {nested: [:a1, {deep_nested: [:b1]}]}])
115
- end
116
-
117
- end
118
-
119
- describe '#allowed?' do
120
-
121
- it 'looks for an item' do
122
- index = instance_with [:item1]
123
- expect(index.allowed? :item1).to eq(true)
124
- expect(index.allowed? :item2).to eq(false)
125
- end
126
-
127
- it 'looks for a nested item' do
128
- index = instance_with [], {nested: instance_with([:item2])}
129
- expect(index.allowed? :item1).to eq(false)
130
- expect(index.allowed? :item2).to eq(false)
131
- expect(index.allowed? :nested, :item1).to eq(false)
132
- expect(index.allowed? :nested, :item2).to eq(true)
133
- expect(index.allowed? :non_nested, :item1).to eq(false)
134
- end
135
-
136
- it 'converts arguments' do
137
- index = instance_with [:item1], {nested: instance_with([:item2])}
138
- expect(index.allowed? 'item1').to eq(true)
139
- expect(index.allowed? 'nested', 'item2').to eq(true)
140
- end
141
-
142
- end
143
-
144
- end
@@ -1,184 +0,0 @@
1
- require_relative '../../spec_helper'
2
-
3
- RSpec.describe Admission::Privilege::OrderDefiner do
4
-
5
- def define_privileges &block
6
- Admission::Privilege::OrderDefiner.define &block
7
- end
8
-
9
- def privilege *args, inherits: nil
10
- p = Admission::Privilege.new *args
11
- p.inherits_from inherits if inherits
12
- p
13
- end
14
-
15
- let(:definer){ Admission::Privilege::OrderDefiner.new }
16
-
17
-
18
- describe '.define' do
19
-
20
- it 'builds empty index' do
21
- index = define_privileges{}
22
- expect(index).to be_a(Hash)
23
- expect(index).to be_empty
24
- expect(index).to be_frozen
25
- end
26
-
27
- it 'builds single privilege' do
28
- index = define_privileges{ privilege :man, levels: %i[commoner count] }
29
- expect(index.keys).to eq(%i[man])
30
- expect(index[:man].keys).to eq(%i[^ base commoner count])
31
- expect(index[:man][:base].inherited).to be_nil
32
- end
33
-
34
- it 'builds with inheritance' do
35
- index = define_privileges do
36
- privilege :man
37
- privilege :vassal, levels: %i[lord], inherits: :man
38
- end
39
-
40
- # structure
41
- expect(index.keys).to eq(%i[man vassal])
42
- expect(index[:man].keys).to eq(%i[^ base])
43
- expect(index[:vassal].keys).to eq(%i[^ base lord])
44
-
45
- # inheritance
46
- expect(index[:man][:base].inherited).to be_nil
47
- expect(index[:vassal][:base].inherited).to eql([privilege(:man)])
48
- expect(index[:vassal][:lord].inherited).to eql([privilege(:vassal)])
49
- end
50
-
51
- end
52
-
53
-
54
- describe '#privilege' do
55
-
56
- it 'adds privilege with no levels' do
57
- definer.privilege :man
58
- expect(definer.definitions.size).to eq(1)
59
- expect(definer.definitions[:man][:inherits]).to be_nil
60
- expect(definer.definitions[:man][:levels]).to eql([privilege(:man)])
61
- end
62
-
63
- it 'adds privilege with no levels by string' do
64
- definer.privilege 'man'
65
- expect(definer.definitions.size).to eq(1)
66
- expect(definer.definitions[:man][:inherits]).to be_nil
67
- expect(definer.definitions[:man][:levels]).to eql([privilege(:man)])
68
- end
69
-
70
- it 'adds privilege array of levels' do
71
- definer.privilege :man, levels: %i[commoner count]
72
- expect(definer.definitions.size).to eq(1)
73
- expect(definer.definitions[:man][:inherits]).to be_nil
74
- expect(definer.definitions[:man][:levels]).to eql([
75
- privilege(:man), privilege(:man, :commoner), privilege(:man, :count)
76
- ])
77
- end
78
-
79
- it 'adds privilege that inherits single other' do
80
- definer.privilege :vassal, inherits: :man
81
- expect(definer.definitions.size).to eq(1)
82
- expect(definer.definitions[:vassal][:inherits]).to eq([:man])
83
- end
84
-
85
- it 'adds privilege that inherits multiple others' do
86
- definer.privilege :vassal, inherits: %i[man woman apache-helicopter]
87
- expect(definer.definitions.size).to eq(1)
88
- expect(definer.definitions[:vassal][:inherits]).to eq([:man, :woman, :'apache-helicopter'])
89
- end
90
-
91
- it 'adds multiple privileges' do
92
- definer.privilege :man
93
- definer.privilege :vassal
94
- expect(definer.definitions.keys).to eq(%i[man vassal])
95
- end
96
-
97
- end
98
-
99
-
100
- describe '#setup_inheritance' do
101
-
102
- it 'sets inheritance' do
103
- definer.privilege :man
104
- definer.privilege :vassal, inherits: :man
105
- definer.send :setup_inheritance
106
-
107
- vassal = definer.definitions[:vassal]
108
- expect(vassal[:levels]).to eql([privilege(:vassal)])
109
- expect(vassal[:levels].first.inherited).to eql([privilege(:man)])
110
- end
111
-
112
- it 'sets inheritance to top level' do
113
- definer.privilege :man, levels: %i[commoner count]
114
- definer.privilege :vassal, inherits: :man
115
- definer.send :setup_inheritance
116
-
117
- vassal = definer.definitions[:vassal]
118
- expect(vassal[:levels]).to eql([privilege(:vassal)])
119
- expect(vassal[:levels].first.inherited).to eql([privilege(:man, :count)])
120
- end
121
-
122
- it 'sets inheritance throughout levels' do
123
- definer.privilege :man
124
- definer.privilege :vassal, inherits: :man, levels: %i[lord]
125
- definer.send :setup_inheritance
126
-
127
- vassal = definer.definitions[:vassal]
128
- expect(vassal[:levels]).to eql([privilege(:vassal), privilege(:vassal, :lord)])
129
- expect(vassal[:levels][0].inherited).to eql([privilege(:man)])
130
- expect(vassal[:levels][1].inherited).to eql([privilege(:vassal)])
131
- end
132
-
133
- end
134
-
135
-
136
- describe '#build_index' do
137
-
138
- it 'returns hash with single privileges' do
139
- definer.privilege :man
140
- index = definer.send :build_index
141
- expect(index).to be_a(Hash)
142
- expect(index.keys).to eq([:man])
143
-
144
- man = index.values.first
145
- expect(man.keys).to eq(%i[^ base])
146
- expect(man.values).to eql([privilege(:man), privilege(:man)])
147
- end
148
-
149
- it 'builds index for privilege with levels' do
150
- definer.privilege :man, levels: %i[commoner count]
151
- index = definer.send :build_index
152
- expect(index).to be_a(Hash)
153
- expect(index.keys).to eq([:man])
154
-
155
- man = index[:man]
156
- expect(man.keys).to eq(%i[^ base commoner count])
157
- expect(man[:'^']).to eql(privilege :man, :count)
158
- expect(man[:base]).to eql(privilege :man)
159
- expect(man[:commoner]).to eql(privilege :man, :commoner)
160
- expect(man[:count]).to eql(privilege :man, :count)
161
- end
162
-
163
- it 'returns hash with more privileges' do
164
- definer.privilege :man
165
- definer.privilege :vassal, levels: %i[lord]
166
- index = definer.send :build_index
167
- expect(index).to be_a(Hash)
168
- expect(index.keys).to eq([:man, :vassal])
169
-
170
- man = index[:man]
171
- expect(man.keys).to eq(%i[^ base])
172
- expect(man[:'^']).to eql(privilege :man)
173
- expect(man[:base]).to eql(privilege :man)
174
-
175
- vassal = index[:vassal]
176
- expect(vassal.keys).to eq(%i[^ base lord])
177
- expect(vassal[:'^']).to eql(privilege :vassal, :lord)
178
- expect(vassal[:base]).to eql(privilege :vassal)
179
- expect(vassal[:lord]).to eql(privilege :vassal, :lord)
180
- end
181
-
182
- end
183
-
184
- end