forest_liana 5.4.4 → 6.0.0.pre.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/forest_liana/actions_controller.rb +0 -105
- data/app/controllers/forest_liana/resources_controller.rb +17 -14
- data/app/controllers/forest_liana/smart_actions_controller.rb +5 -10
- data/app/models/forest_liana/model/action.rb +1 -2
- data/app/serializers/forest_liana/stripe_invoice_serializer.rb +5 -5
- data/app/services/forest_liana/apimap_sorter.rb +0 -1
- data/app/services/forest_liana/permissions_checker.rb +56 -118
- data/app/services/forest_liana/permissions_getter.rb +17 -52
- data/app/services/forest_liana/resource_creator.rb +1 -1
- data/app/services/forest_liana/resource_updater.rb +3 -3
- data/app/services/forest_liana/resources_getter.rb +3 -3
- data/app/services/forest_liana/schema_utils.rb +3 -8
- data/app/services/forest_liana/scope_validator.rb +7 -8
- data/app/services/forest_liana/stripe_invoice_getter.rb +1 -1
- data/app/services/forest_liana/stripe_invoices_getter.rb +1 -1
- data/app/services/forest_liana/stripe_source_getter.rb +1 -1
- data/app/services/forest_liana/stripe_sources_getter.rb +1 -1
- data/config/routes.rb +0 -2
- data/lib/forest_liana/bootstrapper.rb +5 -24
- data/lib/forest_liana/schema_file_updater.rb +0 -1
- data/lib/forest_liana/version.rb +1 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/db/migrate/20190226172951_create_user.rb +1 -1
- data/spec/dummy/db/migrate/20190226173051_create_isle.rb +1 -1
- data/spec/dummy/db/migrate/20190226174951_create_tree.rb +1 -1
- data/spec/dummy/db/migrate/20190716130830_add_age_to_tree.rb +1 -1
- data/spec/dummy/db/migrate/20190716135241_add_type_to_user.rb +1 -1
- data/spec/dummy/db/schema.rb +20 -18
- data/spec/requests/resources_spec.rb +4 -4
- data/spec/services/forest_liana/apimap_sorter_spec.rb +4 -6
- data/spec/services/forest_liana/schema_adapter_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -3
- data/test/dummy/config/application.rb +1 -1
- data/test/dummy/db/migrate/20150608130516_create_date_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131430_create_integer_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131603_create_decimal_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131610_create_float_field.rb +1 -1
- data/test/dummy/db/migrate/20150608132159_create_boolean_field.rb +1 -1
- data/test/dummy/db/migrate/20150608132621_create_string_field.rb +1 -1
- data/test/dummy/db/migrate/20150608133038_create_belongs_to_field.rb +1 -1
- data/test/dummy/db/migrate/20150608133044_create_has_one_field.rb +1 -1
- data/test/dummy/db/migrate/20150608150016_create_has_many_field.rb +1 -1
- data/test/dummy/db/migrate/20150609114636_create_belongs_to_class_name_field.rb +1 -1
- data/test/dummy/db/migrate/20150612112520_create_has_and_belongs_to_many_field.rb +1 -1
- data/test/dummy/db/migrate/20150616150629_create_polymorphic_field.rb +1 -1
- data/test/dummy/db/migrate/20150623115554_create_has_many_class_name_field.rb +1 -1
- data/test/dummy/db/migrate/20150814081918_create_has_many_through_field.rb +1 -1
- data/test/dummy/db/migrate/20160627172810_create_owner.rb +1 -1
- data/test/dummy/db/migrate/20160627172951_create_tree.rb +1 -1
- data/test/dummy/db/migrate/20160628173505_add_timestamps.rb +1 -1
- data/test/dummy/db/migrate/20170614141921_create_serialize_field.rb +1 -1
- data/test/dummy/db/migrate/20181111162121_create_references_table.rb +1 -1
- data/test/services/forest_liana/resources_getter_test.rb +1 -1
- metadata +106 -126
- data/app/helpers/forest_liana/is_same_data_structure_helper.rb +0 -44
- data/app/helpers/forest_liana/widgets_helper.rb +0 -59
- data/app/services/forest_liana/permissions_formatter.rb +0 -52
- data/app/services/forest_liana/utils/beta_schema_utils.rb +0 -13
- data/spec/dummy/app/assets/config/manifest.js +0 -1
- data/spec/helpers/forest_liana/is_same_data_structure_helper_spec.rb +0 -87
- data/spec/requests/actions_controller_spec.rb +0 -222
- data/spec/services/forest_liana/permissions_checker_acl_disabled_spec.rb +0 -711
- data/spec/services/forest_liana/permissions_checker_acl_enabled_spec.rb +0 -831
- data/spec/services/forest_liana/permissions_formatter_spec.rb +0 -222
- data/spec/services/forest_liana/permissions_getter_spec.rb +0 -82
- data/test/dummy/app/assets/config/manifest.js +0 -1
@@ -1,222 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe 'Requesting Actions routes', :type => :request do
|
4
|
-
before(:each) do
|
5
|
-
allow(ForestLiana::IpWhitelist).to receive(:is_ip_whitelist_retrieved) { true }
|
6
|
-
allow(ForestLiana::IpWhitelist).to receive(:is_ip_valid) { true }
|
7
|
-
Island.create(name: 'Corsica')
|
8
|
-
end
|
9
|
-
|
10
|
-
after(:each) do
|
11
|
-
Island.destroy_all
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'call /values' do
|
15
|
-
it 'should respond 200' do
|
16
|
-
post '/forest/actions/foo/values', {}
|
17
|
-
expect(response.status).to eq(200)
|
18
|
-
expect(response.body).to be {}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'hooks' do
|
23
|
-
foo = {
|
24
|
-
field: 'foo',
|
25
|
-
type: 'String',
|
26
|
-
default_value: nil,
|
27
|
-
enums: nil,
|
28
|
-
is_required: false,
|
29
|
-
reference: nil,
|
30
|
-
description: nil,
|
31
|
-
widget: nil,
|
32
|
-
}
|
33
|
-
enum = {
|
34
|
-
field: 'enum',
|
35
|
-
type: 'Enum',
|
36
|
-
enums: %w[a b c],
|
37
|
-
}
|
38
|
-
multiple_enum = {
|
39
|
-
field: 'multipleEnum',
|
40
|
-
type: ['Enum'],
|
41
|
-
enums: %w[a b c],
|
42
|
-
}
|
43
|
-
|
44
|
-
action_definition = {
|
45
|
-
name: 'my_action',
|
46
|
-
fields: [foo],
|
47
|
-
hooks: {
|
48
|
-
:load => -> (context) {
|
49
|
-
context[:fields]
|
50
|
-
},
|
51
|
-
:change => {
|
52
|
-
'foo' => -> (context) {
|
53
|
-
fields = context[:fields]
|
54
|
-
fields['foo'][:value] = 'baz'
|
55
|
-
return fields
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
fail_action_definition = {
|
61
|
-
name: 'fail_action',
|
62
|
-
fields: [foo],
|
63
|
-
hooks: {
|
64
|
-
:load => -> (context) {
|
65
|
-
1
|
66
|
-
},
|
67
|
-
:change => {
|
68
|
-
'foo' => -> (context) {
|
69
|
-
1
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
}
|
74
|
-
cheat_action_definition = {
|
75
|
-
name: 'cheat_action',
|
76
|
-
fields: [foo],
|
77
|
-
hooks: {
|
78
|
-
:load => -> (context) {
|
79
|
-
context[:fields]['baz'] = foo.clone.update({field: 'baz'})
|
80
|
-
context[:fields]
|
81
|
-
},
|
82
|
-
:change => {
|
83
|
-
'foo' => -> (context) {
|
84
|
-
context[:fields]['baz'] = foo.clone.update({field: 'baz'})
|
85
|
-
context[:fields]
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}
|
89
|
-
}
|
90
|
-
enums_action_definition = {
|
91
|
-
name: 'enums_action',
|
92
|
-
fields: [foo, enum],
|
93
|
-
hooks: {
|
94
|
-
:change => {
|
95
|
-
'foo' => -> (context) {
|
96
|
-
fields = context[:fields]
|
97
|
-
fields['enum'][:enums] = %w[c d e]
|
98
|
-
return fields
|
99
|
-
}
|
100
|
-
}
|
101
|
-
}
|
102
|
-
}
|
103
|
-
|
104
|
-
multiple_enums_action_definition = {
|
105
|
-
name: 'multiple_enums_action',
|
106
|
-
fields: [foo, multiple_enum],
|
107
|
-
hooks: {
|
108
|
-
:change => {
|
109
|
-
'foo' => -> (context) {
|
110
|
-
fields = context[:fields]
|
111
|
-
fields['multipleEnum'][:enums] = %w[c d z]
|
112
|
-
return fields
|
113
|
-
}
|
114
|
-
}
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
action = ForestLiana::Model::Action.new(action_definition)
|
119
|
-
fail_action = ForestLiana::Model::Action.new(fail_action_definition)
|
120
|
-
cheat_action = ForestLiana::Model::Action.new(cheat_action_definition)
|
121
|
-
enums_action = ForestLiana::Model::Action.new(enums_action_definition)
|
122
|
-
multiple_enums_action = ForestLiana::Model::Action.new(multiple_enums_action_definition)
|
123
|
-
island = ForestLiana.apimap.find {|collection| collection.name.to_s == ForestLiana.name_for(Island)}
|
124
|
-
island.actions = [action, fail_action, cheat_action, enums_action, multiple_enums_action]
|
125
|
-
|
126
|
-
describe 'call /load' do
|
127
|
-
params = {recordIds: [1], collectionName: 'Island'}
|
128
|
-
|
129
|
-
it 'should respond 200' do
|
130
|
-
post '/forest/actions/my_action/hooks/load', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
131
|
-
expect(response.status).to eq(200)
|
132
|
-
expect(JSON.parse(response.body)).to eq({'fields' => [foo.merge({:value => nil}).stringify_keys]})
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'should respond 500 with bad params' do
|
136
|
-
post '/forest/actions/my_action/hooks/load', params: {}
|
137
|
-
expect(response.status).to eq(500)
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'should respond 500 with bad hook result type' do
|
141
|
-
post '/forest/actions/fail_action/hooks/load', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
142
|
-
expect(response.status).to eq(500)
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'should respond 500 with bad hook result data structure' do
|
146
|
-
post '/forest/actions/cheat_action/hooks/load', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
147
|
-
expect(response.status).to eq(500)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe 'call /change' do
|
152
|
-
updated_foo = foo.clone.merge({:previousValue => nil, :value => 'bar'})
|
153
|
-
params = {recordIds: [1], fields: [updated_foo], collectionName: 'Island', changedField: 'foo'}
|
154
|
-
|
155
|
-
it 'should respond 200' do
|
156
|
-
post '/forest/actions/my_action/hooks/change', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
157
|
-
expect(response.status).to eq(200)
|
158
|
-
expected = updated_foo.clone.merge({:value => 'baz'})
|
159
|
-
expected[:widgetEdit] = nil
|
160
|
-
expected.delete(:widget)
|
161
|
-
expect(JSON.parse(response.body)).to eq({'fields' => [expected.stringify_keys]})
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'should respond 500 with bad params' do
|
165
|
-
post '/forest/actions/my_action/hooks/change', params: {}
|
166
|
-
expect(response.status).to eq(500)
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'should respond 500 with bad hook result type' do
|
170
|
-
post '/forest/actions/fail_action/hooks/change', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
171
|
-
expect(response.status).to eq(500)
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'should respond 500 with bad hook result data structure' do
|
175
|
-
post '/forest/actions/cheat_action/hooks/change', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
176
|
-
expect(response.status).to eq(500)
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'should reset value when enums has changed' do
|
180
|
-
updated_enum = enum.clone.merge({:previousValue => nil, :value => 'a'}) # set value to a
|
181
|
-
p = {recordIds: [1], fields: [updated_foo, updated_enum], collectionName: 'Island', changedField: 'foo'}
|
182
|
-
post '/forest/actions/enums_action/hooks/change', params: JSON.dump(p), headers: { 'CONTENT_TYPE' => 'application/json' }
|
183
|
-
expect(response.status).to eq(200)
|
184
|
-
|
185
|
-
expected_enum = updated_enum.clone.merge({ :enums => %w[c d e], :value => nil, :widgetEdit => nil})
|
186
|
-
expected_enum.delete(:widget)
|
187
|
-
expected_foo = updated_foo.clone.merge({ :widgetEdit => nil})
|
188
|
-
expected_foo.delete(:widget)
|
189
|
-
|
190
|
-
expect(JSON.parse(response.body)).to eq({'fields' => [expected_foo.stringify_keys, expected_enum.stringify_keys]})
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'should not reset value when every enum values are in the enums definition' do
|
194
|
-
updated_multiple_enum = multiple_enum.clone.merge({:previousValue => nil, :value => %w[c]})
|
195
|
-
p = {recordIds: [1], fields: [foo, updated_multiple_enum], collectionName: 'Island', changedField: 'foo'}
|
196
|
-
post '/forest/actions/multiple_enums_action/hooks/change', params: JSON.dump(p), headers: { 'CONTENT_TYPE' => 'application/json' }
|
197
|
-
expect(response.status).to eq(200)
|
198
|
-
|
199
|
-
expected_multiple_enum = updated_multiple_enum.clone.merge({ :enums => %w[c d z], :widgetEdit => nil, :value => %w[c]})
|
200
|
-
expected_multiple_enum.delete(:widget)
|
201
|
-
expected_foo = foo.clone.merge({ :widgetEdit => nil})
|
202
|
-
expected_foo.delete(:widget)
|
203
|
-
|
204
|
-
expect(JSON.parse(response.body)).to eq({'fields' => [expected_foo.stringify_keys, expected_multiple_enum.stringify_keys]})
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'should reset value when one of the enum values is not in the enums definition' do
|
208
|
-
wrongly_updated_multiple_enum = multiple_enum.clone.merge({:previousValue => nil, :value => %w[a b]})
|
209
|
-
p = {recordIds: [1], fields: [foo, wrongly_updated_multiple_enum], collectionName: 'Island', changedField: 'foo'}
|
210
|
-
post '/forest/actions/multiple_enums_action/hooks/change', params: JSON.dump(p), headers: { 'CONTENT_TYPE' => 'application/json' }
|
211
|
-
expect(response.status).to eq(200)
|
212
|
-
|
213
|
-
expected_multiple_enum = wrongly_updated_multiple_enum.clone.merge({ :enums => %w[c d z], :widgetEdit => nil, :value => nil })
|
214
|
-
expected_multiple_enum.delete(:widget)
|
215
|
-
expected_foo = foo.clone.merge({ :widgetEdit => nil})
|
216
|
-
expected_foo.delete(:widget)
|
217
|
-
|
218
|
-
expect(JSON.parse(response.body)).to eq({'fields' => [expected_foo.stringify_keys, expected_multiple_enum.stringify_keys]})
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|