Skip to content

Commit 5cd4a0e

Browse files
feat: smart action hooks now have access to the http request (#499)
BREAKING CHANGE: record is no longer send to the hook midleware & values option on smart action is no longer supported
1 parent 4fb3b84 commit 5cd4a0e

File tree

4 files changed

+2
-32
lines changed

4 files changed

+2
-32
lines changed

app/controllers/forest_liana/actions_controller.rb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ def get_smart_action_hook_request
1010
end
1111
end
1212

13-
def values
14-
render serializer: nil, json: {}, status: :ok
15-
end
16-
1713
def get_collection(collection_name)
1814
ForestLiana.apimap.find { |collection| collection.name.to_s == collection_name }
1915
end
@@ -27,22 +23,14 @@ def get_action(collection_name)
2723
nil
2824
end
2925
end
30-
31-
def get_record
32-
hook_request = get_smart_action_hook_request
33-
model = ForestLiana::SchemaUtils.find_model_from_collection_name(hook_request[:collection_name])
34-
record_getter = ForestLiana::ResourceGetter.new(model, {:id => hook_request[:ids][0]})
35-
record_getter.perform
36-
record_getter.record
37-
end
3826

3927
def get_smart_action_load_ctx(fields)
4028
fields = fields.map do |field|
4129
ForestLiana::WidgetsHelper.set_field_widget(field)
4230
field[:value] = nil unless field[:value]
4331
field
4432
end
45-
{:record => get_record, :fields => fields}
33+
{:fields => fields, :params => params}
4634
end
4735

4836
def get_smart_action_change_ctx(fields, field_changed)
@@ -52,7 +40,7 @@ def get_smart_action_change_ctx(fields, field_changed)
5240
ForestLiana::WidgetsHelper.set_field_widget(field)
5341
field
5442
end
55-
{:record => get_record, :field_changed => found_field_changed, :fields => fields}
43+
{:field_changed => found_field_changed, :fields => fields, :params => params}
5644
end
5745

5846
def handle_result(result, action)

app/controllers/forest_liana/application_controller.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ def authenticate_user_from_jwt
8686
end
8787
end
8888

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-
9889
def internal_server_error
9990
head :internal_server_error
10091
end

config/routes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
delete ':collection', to: router
5858

5959
# Smart Actions forms value
60-
post 'actions/:action_name/values' => 'actions#values'
6160
post 'actions/:action_name/hooks/load' => 'actions#load'
6261
post 'actions/:action_name/hooks/change' => 'actions#change'
6362
end

spec/requests/actions_controller_spec.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
after(:each) do
1111
Island.destroy_all
1212
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
2113

2214
describe 'hooks' do
2315
foo = {

0 commit comments

Comments
 (0)