Skip to content

Commit 39e976e

Browse files
fix: allow actions hooks in production (#455)
1 parent 688b400 commit 39e976e

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

app/controllers/forest_liana/authentication_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module ForestLiana
55
class AuthenticationController < ForestLiana::BaseController
66
START_AUTHENTICATION_ROUTE = 'authentication'
77
CALLBACK_AUTHENTICATION_ROUTE = 'authentication/callback'
8-
LOGOUT_ROUTE = 'authentication/logout';
8+
LOGOUT_ROUTE = 'authentication/logout'
99
PUBLIC_ROUTES = [
1010
"/#{START_AUTHENTICATION_ROUTE}",
1111
"/#{CALLBACK_AUTHENTICATION_ROUTE}",

lib/forest_liana/bootstrapper.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,35 @@ def get_action(collection, action_name)
5353
collection.actions.find {|action| action.name == action_name}
5454
end
5555

56+
def generate_action_hooks()
57+
@collections_sent.each do |collection|
58+
collection['actions'].each do |action|
59+
c = get_collection(collection['name'])
60+
a = get_action(c, action['name'])
61+
load = !a.hooks.nil? && a.hooks.key?(:load) && a.hooks[:load].is_a?(Proc)
62+
change = !a.hooks.nil? && a.hooks.key?(:change) && a.hooks[:change].is_a?(Hash) ? a.hooks[:change].keys : []
63+
action['hooks'] = {:load => load, :change => change}
64+
end
65+
end
66+
end
67+
5668
def generate_apimap
5769
create_apimap
5870
require_lib_forest_liana
5971
format_and_validate_smart_actions
6072

6173
if Rails.env.development?
6274
@collections_sent = ForestLiana.apimap.as_json
63-
64-
@collections_sent.each do |collection|
65-
collection['actions'].each do |action|
66-
c = get_collection(collection['name'])
67-
a = get_action(c, action['name'])
68-
load = !a.hooks.nil? && a.hooks.key?(:load) && a.hooks[:load].is_a?(Proc)
69-
change = !a.hooks.nil? && a.hooks.key?(:change) && a.hooks[:change].is_a?(Hash) ? a.hooks[:change].keys : []
70-
action['hooks'] = {:load => load, :change => change}
71-
end
72-
end
73-
7475
@meta_sent = ForestLiana.meta
76+
generate_action_hooks
7577
SchemaFileUpdater.new(SCHEMA_FILENAME, @collections_sent, @meta_sent).perform()
7678
else
7779
if File.exists?(SCHEMA_FILENAME)
7880
begin
7981
content = JSON.parse(File.read(SCHEMA_FILENAME))
8082
@collections_sent = content['collections']
8183
@meta_sent = content['meta']
84+
generate_action_hooks
8285
rescue JSON::JSONError
8386
FOREST_LOGGER.error "The content of .forestadmin-schema.json file is not a correct JSON."
8487
FOREST_LOGGER.error "The schema cannot be synchronized with Forest Admin servers."

0 commit comments

Comments
 (0)