forest_liana 7.0.0.beta.3 → 7.0.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3115af32c59b5bf0e32218f3d40cb661809d58316714654520bde1bfee235098
4
- data.tar.gz: 850a6dbc96d8ff1e74ffe7970dc98ff2bd721d6b834087353052208722b55810
3
+ metadata.gz: 0bf8bedca443e88f415a14995d430f5ba021cfe846d8471588680c5f35e619eb
4
+ data.tar.gz: f68ffb4494911b3b674965b3370988c4505be91673f7d67e194482b0975226e2
5
5
  SHA512:
6
- metadata.gz: ea018906c77a41db7a7dc1022cd6485e5f9a293763c1822a64706092f8be74d1046230198af6d0041277cb8f2b852115633b96f622f69a192dc99f911cd31178
7
- data.tar.gz: cf12c7f0821b3e9232fe884e3d5c04470f6467d4a571ffc88ce2f6e36c9edac6704dcdd9a0c431dd222435bac1c31b512a5585bc9fb99f141e309e41f9ff8696
6
+ metadata.gz: 97aeec5fc463e97cc3b8475c0f09228ea131a322d458104f2cf28306d390b904fd433a78e2a53b7baf34aaf05c6f66d7783e15a36b1f464790ab78bc5bd60ea6
7
+ data.tar.gz: 9339a84947baea79f91ebb48716760eee7f8e2acee6fc473b881904001c7f3f6bd6f1a1de6603df63eeba15967fcf6d982a60a7f42c049f007b958d60ff9732e
@@ -1,8 +1,13 @@
1
1
  module ForestLiana
2
2
  class ActionsController < ForestLiana::BaseController
3
3
 
4
- def values
5
- render serializer: nil, json: {}, status: :ok
4
+ def get_smart_action_hook_request
5
+ begin
6
+ params[:data][:attributes]
7
+ rescue => error
8
+ FOREST_LOGGER.error "Smart Action hook request error: #{error}"
9
+ {}
10
+ end
6
11
  end
7
12
 
8
13
  def get_collection(collection_name)
@@ -18,13 +23,6 @@ module ForestLiana
18
23
  nil
19
24
  end
20
25
  end
21
-
22
- def get_record
23
- model = ForestLiana::SchemaUtils.find_model_from_collection_name(params[:collectionName])
24
- redord_getter = ForestLiana::ResourceGetter.new(model, {:id => params[:recordIds][0]})
25
- redord_getter.perform
26
- redord_getter.record
27
- end
28
26
 
29
27
  def get_smart_action_load_ctx(fields)
30
28
  fields = fields.map do |field|
@@ -32,7 +30,7 @@ module ForestLiana
32
30
  field[:value] = nil unless field[:value]
33
31
  field
34
32
  end
35
- {:record => get_record, :fields => fields}
33
+ {:fields => fields, :params => params}
36
34
  end
37
35
 
38
36
  def get_smart_action_change_ctx(fields, field_changed)
@@ -42,7 +40,7 @@ module ForestLiana
42
40
  ForestLiana::WidgetsHelper.set_field_widget(field)
43
41
  field
44
42
  end
45
- {:record => get_record, :field_changed => found_field_changed, :fields => fields}
43
+ {:field_changed => found_field_changed, :fields => fields, :params => params}
46
44
  end
47
45
 
48
46
  def handle_result(result, action)
@@ -87,7 +85,9 @@ module ForestLiana
87
85
  end
88
86
 
89
87
  def load
90
- action = get_action(params[:collectionName])
88
+ load_request = get_smart_action_hook_request
89
+
90
+ action = get_action(load_request[:collection_name])
91
91
 
92
92
  if !action
93
93
  render status: 500, json: {error: 'Error in smart action load hook: cannot retrieve action from collection'}
@@ -103,18 +103,20 @@ module ForestLiana
103
103
  end
104
104
 
105
105
  def change
106
- action = get_action(params[:collectionName])
106
+ change_request = get_smart_action_hook_request
107
+
108
+ action = get_action(change_request[:collection_name])
107
109
 
108
110
  if !action
109
111
  return render status: 500, json: {error: 'Error in smart action change hook: cannot retrieve action from collection'}
110
- elsif params[:fields].nil?
112
+ elsif change_request[:fields].nil?
111
113
  return render status: 500, json: {error: 'Error in smart action change hook: fields params is mandatory'}
112
- elsif !params[:fields].is_a?(Array)
114
+ elsif !change_request[:fields].is_a?(Array)
113
115
  return render status: 500, json: {error: 'Error in smart action change hook: fields params must be an array'}
114
116
  end
115
117
 
116
118
  # Get the smart action hook change context
117
- context = get_smart_action_change_ctx(params[:fields], params[:changedField])
119
+ context = get_smart_action_change_ctx(change_request[:fields], change_request[:changed_field])
118
120
 
119
121
  field_changed_hook = context[:field_changed][:hook]
120
122
 
@@ -86,15 +86,6 @@ module ForestLiana
86
86
  end
87
87
  end
88
88
 
89
- def get_smart_action_context
90
- begin
91
- params[:data][:attributes].values[0].to_hash.symbolize_keys
92
- rescue => error
93
- FOREST_LOGGER.error "Smart Action context retrieval error: #{error}"
94
- {}
95
- end
96
- end
97
-
98
89
  def internal_server_error
99
90
  head :internal_server_error
100
91
  end
data/config/routes.rb CHANGED
@@ -57,7 +57,6 @@ ForestLiana::Engine.routes.draw do
57
57
  delete ':collection', to: router
58
58
 
59
59
  # Smart Actions forms value
60
- post 'actions/:action_name/values' => 'actions#values'
61
60
  post 'actions/:action_name/hooks/load' => 'actions#load'
62
61
  post 'actions/:action_name/hooks/change' => 'actions#change'
63
62
  end
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "7.0.0.beta.3"
2
+ VERSION = "7.0.0.beta.4"
3
3
  end
@@ -10,15 +10,7 @@ describe 'Requesting Actions routes', :type => :request do
10
10
  after(:each) do
11
11
  Island.destroy_all
12
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
-
13
+
22
14
  describe 'hooks' do
23
15
  foo = {
24
16
  field: 'foo',
@@ -127,7 +119,11 @@ describe 'Requesting Actions routes', :type => :request do
127
119
  island.actions = [action, fail_action, cheat_action, enums_action, multiple_enums_action]
128
120
 
129
121
  describe 'call /load' do
130
- params = {recordIds: [1], collectionName: 'Island'}
122
+ params = {
123
+ data: {
124
+ attributes: { ids: [1], collection_name: 'Island' }
125
+ }
126
+ }
131
127
 
132
128
  it 'should respond 200' do
133
129
  post '/forest/actions/my_action/hooks/load', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
@@ -156,7 +152,16 @@ describe 'Requesting Actions routes', :type => :request do
156
152
 
157
153
  describe 'call /change' do
158
154
  updated_foo = foo.clone.merge({:previousValue => nil, :value => 'bar'})
159
- params = {recordIds: [1], fields: [updated_foo], collectionName: 'Island', changedField: 'foo'}
155
+ params = {
156
+ data: {
157
+ attributes: {
158
+ ids: [1],
159
+ fields: [updated_foo],
160
+ collection_name: 'Island',
161
+ changed_field: 'foo'
162
+ }
163
+ }
164
+ }
160
165
 
161
166
  it 'should respond 200' do
162
167
  post '/forest/actions/my_action/hooks/change', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
@@ -168,7 +173,7 @@ describe 'Requesting Actions routes', :type => :request do
168
173
  end
169
174
 
170
175
  it 'should respond 500 with bad params' do
171
- post '/forest/actions/my_action/hooks/change', params: JSON.dump({collectionName: 'Island'}), headers: { 'CONTENT_TYPE' => 'application/json' }
176
+ post '/forest/actions/my_action/hooks/change', params: JSON.dump({ data: { attributes: { collection_name: 'Island' }}}), headers: { 'CONTENT_TYPE' => 'application/json' }
172
177
  expect(response.status).to eq(500)
173
178
  expect(JSON.parse(response.body)).to eq({'error' => 'Error in smart action change hook: fields params is mandatory'})
174
179
  end
@@ -181,7 +186,16 @@ describe 'Requesting Actions routes', :type => :request do
181
186
 
182
187
  it 'should reset value when enums has changed' do
183
188
  updated_enum = enum.clone.merge({:previousValue => nil, :value => 'a'}) # set value to a
184
- p = {recordIds: [1], fields: [updated_foo, updated_enum], collectionName: 'Island', changedField: 'foo'}
189
+ p = {
190
+ data: {
191
+ attributes: {
192
+ ids: [1],
193
+ fields: [updated_foo, updated_enum],
194
+ collection_name: 'Island',
195
+ changed_field: 'foo'
196
+ }
197
+ }
198
+ }
185
199
  post '/forest/actions/enums_action/hooks/change', params: JSON.dump(p), headers: { 'CONTENT_TYPE' => 'application/json' }
186
200
  expect(response.status).to eq(200)
187
201
 
@@ -195,7 +209,16 @@ describe 'Requesting Actions routes', :type => :request do
195
209
 
196
210
  it 'should not reset value when every enum values are in the enums definition' do
197
211
  updated_multiple_enum = multiple_enum.clone.merge({:previousValue => nil, :value => %w[c]})
198
- p = {recordIds: [1], fields: [foo, updated_multiple_enum], collectionName: 'Island', changedField: 'foo'}
212
+ p = {
213
+ data: {
214
+ attributes: {
215
+ ids: [1],
216
+ fields: [foo, updated_multiple_enum],
217
+ collection_name: 'Island',
218
+ changed_field: 'foo'
219
+ }
220
+ }
221
+ }
199
222
  post '/forest/actions/multiple_enums_action/hooks/change', params: JSON.dump(p), headers: { 'CONTENT_TYPE' => 'application/json' }
200
223
  expect(response.status).to eq(200)
201
224
 
@@ -209,7 +232,17 @@ describe 'Requesting Actions routes', :type => :request do
209
232
 
210
233
  it 'should reset value when one of the enum values is not in the enums definition' do
211
234
  wrongly_updated_multiple_enum = multiple_enum.clone.merge({:previousValue => nil, :value => %w[a b]})
212
- p = {recordIds: [1], fields: [foo, wrongly_updated_multiple_enum], collectionName: 'Island', changedField: 'foo'}
235
+ p = {
236
+ data: {
237
+ attributes: {
238
+ ids: [1],
239
+ fields: [foo, wrongly_updated_multiple_enum],
240
+ collection_name: 'Island',
241
+ changed_field: 'foo'
242
+ }
243
+ }
244
+ }
245
+
213
246
  post '/forest/actions/multiple_enums_action/hooks/change', params: JSON.dump(p), headers: { 'CONTENT_TYPE' => 'application/json' }
214
247
  expect(response.status).to eq(200)
215
248
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0.beta.3
4
+ version: 7.0.0.beta.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-02 00:00:00.000000000 Z
11
+ date: 2021-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails