forest_liana 7.2.2 → 7.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/forest_liana/actions_controller.rb +5 -2
  3. data/app/controllers/forest_liana/associations_controller.rb +4 -0
  4. data/app/controllers/forest_liana/base_controller.rb +1 -0
  5. data/app/controllers/forest_liana/resources_controller.rb +8 -0
  6. data/app/controllers/forest_liana/router.rb +1 -0
  7. data/app/controllers/forest_liana/scopes_controller.rb +1 -0
  8. data/app/controllers/forest_liana/smart_actions_controller.rb +4 -0
  9. data/app/controllers/forest_liana/stats_controller.rb +2 -0
  10. data/app/services/forest_liana/intercom_attributes_getter.rb +1 -0
  11. data/app/services/forest_liana/intercom_conversation_getter.rb +1 -0
  12. data/app/services/forest_liana/intercom_conversations_getter.rb +1 -0
  13. data/app/services/forest_liana/ip_whitelist.rb +1 -0
  14. data/app/services/forest_liana/permissions_getter.rb +1 -0
  15. data/app/services/forest_liana/resources_getter.rb +1 -0
  16. data/app/services/forest_liana/schema_adapter.rb +4 -1
  17. data/app/services/forest_liana/search_query_builder.rb +1 -0
  18. data/app/services/forest_liana/stripe_invoices_getter.rb +1 -0
  19. data/app/services/forest_liana/stripe_payments_getter.rb +1 -0
  20. data/app/services/forest_liana/stripe_sources_getter.rb +1 -0
  21. data/app/services/forest_liana/stripe_subscriptions_getter.rb +1 -0
  22. data/config/initializers/logger.rb +8 -1
  23. data/lib/forest_liana/bootstrapper.rb +9 -5
  24. data/lib/forest_liana/collection.rb +1 -0
  25. data/lib/forest_liana/engine.rb +3 -0
  26. data/lib/forest_liana/schema_file_updater.rb +1 -0
  27. data/lib/forest_liana/version.rb +1 -1
  28. data/lib/forest_liana.rb +2 -0
  29. data/spec/config/initializers/logger_spec.rb +37 -0
  30. data/spec/dummy/tmp/cache/11D/A92/http%3A%2F%2Flocalhost%3A3000%2Fforest%2Fauthentication%2Fcallback-env_secret_test-client-data +1 -0
  31. data/spec/requests/actions_controller_spec.rb +20 -1
  32. metadata +121 -119
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e27c82de4862ee0ef5a2d1c3a83911f3257c5622979bb5a0fa2b60f367b6095
4
- data.tar.gz: 2e63d770bd045090db7458feb0a417e002419998202f2a9b20dc4087cf38e635
3
+ metadata.gz: '081fe9fbe4eb7375a7e0a613b55ad7fb51b95ab787df36f6fc7c7078c7ae2a5f'
4
+ data.tar.gz: 89c350e886e097d3624ded4025dce3a2b25dd06836354908f152283e0dbe5126
5
5
  SHA512:
6
- metadata.gz: e0a8e5a2a516e9224c90acf8c0ae367d2a99e5ec1d40132851c6e1a258d5a338c68e48eccd9facbccbe4650258426fb1d74286f9c58438ebd4e3a83a8a947d3e
7
- data.tar.gz: c64b4806f3073c29e20d4d5c24e6d3e28d785db24de4cb3e62e9dfedc971e6da4be789333913eacd0933d3ef3e7333029f5b3045d1394a768ba5cd0d808f780d
6
+ metadata.gz: a79ae6c586f14c4437904c1d4186712a248bd65727851d48d9a80ee5d9754cbfc323fd3aac2715b79b08b7df62a353fc95d48ddb2fd998e5ea3167a9dec3a49d
7
+ data.tar.gz: 44a947d09db5e6a6e6a299ff6b4615417262af919bb515fd2466e29edd54af065c15ca16f93556e6a9b5f55ef596016b7af497160e6d4c30920c02ea8e0d1f37
@@ -5,6 +5,7 @@ module ForestLiana
5
5
  begin
6
6
  params[:data][:attributes]
7
7
  rescue => error
8
+ FOREST_REPORTER.report error
8
9
  FOREST_LOGGER.error "Smart Action hook request error: #{error}"
9
10
  {}
10
11
  end
@@ -19,6 +20,7 @@ module ForestLiana
19
20
  begin
20
21
  collection.actions.find {|action| ActiveSupport::Inflector.parameterize(action.name) == params[:action_name]}
21
22
  rescue => error
23
+ FOREST_REPORTER.report error
22
24
  FOREST_LOGGER.error "Smart Action get action retrieval error: #{error}"
23
25
  nil
24
26
  end
@@ -30,7 +32,7 @@ module ForestLiana
30
32
  field[:value] = nil unless field[:value]
31
33
  field
32
34
  end
33
- {:fields => fields, :params => params}
35
+ {:fields => fields, :params => params, :user => forest_user}
34
36
  end
35
37
 
36
38
  def get_smart_action_change_ctx(fields, field_changed)
@@ -40,7 +42,7 @@ module ForestLiana
40
42
  ForestLiana::WidgetsHelper.set_field_widget(field)
41
43
  field
42
44
  end
43
- {:field_changed => found_field_changed, :fields => fields, :params => params}
45
+ {:field_changed => found_field_changed, :fields => fields, :params => params, :user => forest_user}
44
46
  end
45
47
 
46
48
  def handle_result(result, action)
@@ -57,6 +59,7 @@ module ForestLiana
57
59
  rescue ForestLiana::Errors::SmartActionInvalidFieldError => invalid_field_error
58
60
  FOREST_LOGGER.warn invalid_field_error.message
59
61
  rescue ForestLiana::Errors::SmartActionInvalidFieldHookError => invalid_hook_error
62
+ FOREST_REPORTER.report invalid_hook_error
60
63
  FOREST_LOGGER.error invalid_hook_error.message
61
64
  return render status: 500, json: { error: invalid_hook_error.message }
62
65
  end
@@ -18,6 +18,7 @@ module ForestLiana
18
18
  format.csv { render_csv(getter, @association.klass) }
19
19
  end
20
20
  rescue => error
21
+ FOREST_REPORTER.report error
21
22
  FOREST_LOGGER.error "Association Index error: #{error}\n#{format_stacktrace(error)}"
22
23
  internal_server_error
23
24
  end
@@ -30,6 +31,7 @@ module ForestLiana
30
31
 
31
32
  render serializer: nil, json: { count: getter.records_count }
32
33
  rescue => error
34
+ FOREST_REPORTER.report error
33
35
  FOREST_LOGGER.error "Association Index Count error: #{error}\n#{format_stacktrace(error)}"
34
36
  internal_server_error
35
37
  end
@@ -47,6 +49,7 @@ module ForestLiana
47
49
  head :no_content
48
50
  end
49
51
  rescue => error
52
+ FOREST_REPORTER.report error
50
53
  FOREST_LOGGER.error "Association Update error: #{error}\n#{format_stacktrace(error)}"
51
54
  internal_server_error
52
55
  end
@@ -59,6 +62,7 @@ module ForestLiana
59
62
 
60
63
  head :no_content
61
64
  rescue => error
65
+ FOREST_REPORTER.report error
62
66
  FOREST_LOGGER.error "Association Associate error: #{error}\n#{format_stacktrace(error)}"
63
67
  internal_server_error
64
68
  end
@@ -30,6 +30,7 @@ module ForestLiana
30
30
  }])
31
31
  render(serializer: nil, json: error_data, status: exception.status)
32
32
  rescue => exception
33
+ FOREST_REPORTER.report exception
33
34
  FOREST_LOGGER.error(exception)
34
35
  FOREST_LOGGER.error(exception.backtrace.join("\n"))
35
36
  render(serializer: nil, json: nil, status: :internal_server_error)
@@ -47,6 +47,7 @@ module ForestLiana
47
47
  }])
48
48
  render(serializer: nil, json: error_data, status: error.status)
49
49
  rescue => error
50
+ FOREST_REPORTER.report error
50
51
  FOREST_LOGGER.error "Records Index error: #{error}\n#{format_stacktrace(error)}"
51
52
  internal_server_error
52
53
  end
@@ -79,6 +80,7 @@ module ForestLiana
79
80
  }])
80
81
  render(serializer: nil, json: error_data, status: error.status)
81
82
  rescue => error
83
+ FOREST_REPORTER.report error
82
84
  FOREST_LOGGER.error "Records Index Count error: #{error}\n#{format_stacktrace(error)}"
83
85
  internal_server_error
84
86
  end
@@ -96,6 +98,7 @@ module ForestLiana
96
98
  rescue ActiveRecord::RecordNotFound
97
99
  render serializer: nil, json: { status: 404 }, status: :not_found
98
100
  rescue => error
101
+ FOREST_REPORTER.report error
99
102
  FOREST_LOGGER.error "Record Show error: #{error}\n#{format_stacktrace(error)}"
100
103
  internal_server_error
101
104
  end
@@ -119,6 +122,7 @@ module ForestLiana
119
122
  creator.record.errors), status: 400
120
123
  end
121
124
  rescue => error
125
+ FOREST_REPORTER.report error
122
126
  FOREST_LOGGER.error "Record Create error: #{error}\n#{format_stacktrace(error)}"
123
127
  internal_server_error
124
128
  end
@@ -142,6 +146,7 @@ module ForestLiana
142
146
  updater.record.errors), status: 400
143
147
  end
144
148
  rescue => error
149
+ FOREST_REPORTER.report error
145
150
  FOREST_LOGGER.error "Record Update error: #{error}\n#{format_stacktrace(error)}"
146
151
  internal_server_error
147
152
  end
@@ -162,6 +167,7 @@ module ForestLiana
162
167
 
163
168
  head :no_content
164
169
  rescue => error
170
+ FOREST_REPORTER.report error
165
171
  FOREST_LOGGER.error "Record Destroy error: #{error}\n#{format_stacktrace(error)}"
166
172
  internal_server_error
167
173
  end
@@ -175,6 +181,7 @@ module ForestLiana
175
181
 
176
182
  head :no_content
177
183
  rescue => error
184
+ FOREST_REPORTER.report error
178
185
  FOREST_LOGGER.error "Records Destroy error: #{error}\n#{format_stacktrace(error)}"
179
186
  internal_server_error
180
187
  end
@@ -190,6 +197,7 @@ module ForestLiana
190
197
  render serializer: nil, json: { status: 404 }, status: :not_found
191
198
  end
192
199
  rescue => error
200
+ FOREST_REPORTER.report error
193
201
  FOREST_LOGGER.error "Find Collection error: #{error}\n#{format_stacktrace(error)}"
194
202
  render serializer: nil, json: { status: 404 }, status: :not_found
195
203
  end
@@ -39,6 +39,7 @@ class ForestLiana::Router
39
39
 
40
40
  controller.action(action.to_sym).call(env)
41
41
  rescue NoMethodError => exception
42
+ FOREST_REPORTER.report exception
42
43
  FOREST_LOGGER.error "Routing error: #{exception}\n#{exception.backtrace.join("\n\t")}"
43
44
  ForestLiana::BaseController.action(:route_not_found).call(env)
44
45
  end
@@ -12,6 +12,7 @@ module ForestLiana
12
12
  ForestLiana::ScopeManager.invalidate_scope_cache(rendering_id)
13
13
  return render serializer: nil, json: { status: 200 }, status: :ok
14
14
  rescue => error
15
+ FOREST_REPORTER.report error
15
16
  FOREST_LOGGER.error "Error during scope cache invalidation: #{error.message}"
16
17
  render serializer: nil, json: {status: 500 }, status: :internal_server_error
17
18
  end
@@ -12,6 +12,7 @@ module ForestLiana
12
12
  begin
13
13
  params[:data][:attributes]
14
14
  rescue => error
15
+ FOREST_REPORTER.report error
15
16
  FOREST_LOGGER.error "Smart Action execution error: #{error}"
16
17
  {}
17
18
  end
@@ -47,6 +48,7 @@ module ForestLiana
47
48
  # target records are out of scope
48
49
  render serializer: nil, json: { error: 'Smart Action: target record not found' }, status: :bad_request
49
50
  rescue => error
51
+ FOREST_REPORTER.report error
50
52
  FOREST_LOGGER.error "Smart Action: #{error}\n#{format_stacktrace(error)}"
51
53
  render serializer: nil, json: { error: 'Smart Action: failed to evaluate permissions' }, status: :internal_server_error
52
54
  end
@@ -70,6 +72,7 @@ module ForestLiana
70
72
  render serializer: nil, json: { status: 400 }, status: :bad_request
71
73
  end
72
74
  rescue => error
75
+ FOREST_REPORTER.report error
73
76
  FOREST_LOGGER.error "Smart Action execution error: #{error}"
74
77
  render serializer: nil, json: { status: 400 }, status: :bad_request
75
78
  end
@@ -85,6 +88,7 @@ module ForestLiana
85
88
  end
86
89
  resource
87
90
  rescue => error
91
+ FOREST_REPORTER.report error
88
92
  FOREST_LOGGER.error "Find Collection error: #{error}\n#{format_stacktrace(error)}"
89
93
  render serializer: nil, json: { status: 404 }, status: :not_found
90
94
  end
@@ -60,6 +60,7 @@ module ForestLiana
60
60
  render json: { errors: [{ status: 422, detail: error.message }] },
61
61
  status: :unprocessable_entity, serializer: nil
62
62
  rescue => error
63
+ FOREST_REPORTER.report error
63
64
  FOREST_LOGGER.error "Live Query error: #{error.message}"
64
65
  render json: { errors: [{ status: 422, detail: error.message }] },
65
66
  status: :unprocessable_entity, serializer: nil
@@ -110,6 +111,7 @@ module ForestLiana
110
111
 
111
112
  return head :forbidden unless checker.is_authorized?
112
113
  rescue => error
114
+ FOREST_REPORTER.report error
113
115
  FOREST_LOGGER.error "Stats execution error: #{error}"
114
116
  render serializer: nil, json: { status: 400 }, status: :bad_request
115
117
  end
@@ -18,6 +18,7 @@ module ForestLiana
18
18
  @record = user
19
19
  rescue Intercom::ResourceNotFound
20
20
  rescue Intercom::UnexpectedError => exception
21
+ FOREST_REPORTER.report exception
21
22
  FOREST_LOGGER.error "Cannot retrieve the Intercom attributes: #{exception.message}"
22
23
  end
23
24
  end
@@ -14,6 +14,7 @@ module ForestLiana
14
14
  rescue Intercom::ResourceNotFound
15
15
  @record = nil
16
16
  rescue Intercom::UnexpectedError => exception
17
+ FOREST_REPORTER.report exception
17
18
  FOREST_LOGGER.error "Cannot retrieve the Intercom conversation: #{exception.message}"
18
19
  @record = nil
19
20
  end
@@ -31,6 +31,7 @@ module ForestLiana
31
31
  rescue Intercom::ResourceNotFound
32
32
  @records = []
33
33
  rescue Intercom::UnexpectedError => exception
34
+ FOREST_REPORTER.report exception
34
35
  FOREST_LOGGER.error "Cannot retrieve the Intercom conversations: #{exception.message}"
35
36
  @records = []
36
37
  end
@@ -21,6 +21,7 @@ module ForestLiana
21
21
  false
22
22
  end
23
23
  rescue => exception
24
+ FOREST_REPORTER.report exception
24
25
  FOREST_LOGGER.error 'Cannot retrieve the IP Whitelist from the Forest server.'
25
26
  FOREST_LOGGER.error 'Which was caused by:'
26
27
  ForestLiana::Errors::ExceptionHelper.recursively_print(exception, margin: ' ', is_error: true)
@@ -47,6 +47,7 @@ module ForestLiana
47
47
  raise "Forest API returned an #{ForestLiana::Errors::HTTPErrorHelper.format(response)}"
48
48
  end
49
49
  rescue => exception
50
+ FOREST_REPORTER.report exception
50
51
  FOREST_LOGGER.error 'Cannot retrieve the permissions from the Forest server.'
51
52
  FOREST_LOGGER.error 'Which was caused by:'
52
53
  ForestLiana::Errors::ExceptionHelper.recursively_print(exception, margin: ' ', is_error: true)
@@ -179,6 +179,7 @@ module ForestLiana
179
179
  )
180
180
  rescue => error
181
181
  error_message = "Live Query Segment: #{error.message}"
182
+ FOREST_REPORTER.report error
182
183
  FOREST_LOGGER.error(error_message)
183
184
  raise ForestLiana::Errors::LiveQueryError.new(error_message)
184
185
  end
@@ -261,6 +261,7 @@ module ForestLiana
261
261
  FOREST_LOGGER.warn "The association \"#{association.name.to_s}\" " \
262
262
  "does not seem to exist for model \"#{@model.name}\"."
263
263
  rescue => exception
264
+ FOREST_REPORTER.report exception
264
265
  FOREST_LOGGER.error "An error occured trying to add " \
265
266
  "\"#{association.name.to_s}\" association:\n#{exception}"
266
267
  end
@@ -350,10 +351,12 @@ module ForestLiana
350
351
  type = 'Number'
351
352
  when :json, :jsonb, :hstore
352
353
  type = 'Json'
353
- when :string, :text, :citext, :uuid
354
+ when :string, :text, :citext
354
355
  type = 'String'
355
356
  when :time
356
357
  type = 'Time'
358
+ when :uuid
359
+ type = 'Uuid'
357
360
  end
358
361
 
359
362
  is_array = (column.respond_to?(:array) && column.array == true)
@@ -31,6 +31,7 @@ module ForestLiana
31
31
  begin
32
32
  @records = field[:search].call(@records, @search)
33
33
  rescue => exception
34
+ FOREST_REPORTER.report exception
34
35
  FOREST_LOGGER.error "Cannot search properly on Smart Field:\n" \
35
36
  "#{exception}"
36
37
  end
@@ -50,6 +50,7 @@ module ForestLiana
50
50
  d
51
51
  end
52
52
  rescue ::Stripe::InvalidRequestError => error
53
+ FOREST_REPORTER.report error
53
54
  FOREST_LOGGER.error "Stripe error: #{error.message}"
54
55
  @records = []
55
56
  end
@@ -48,6 +48,7 @@ module ForestLiana
48
48
  d
49
49
  end
50
50
  rescue ::Stripe::InvalidRequestError => error
51
+ FOREST_REPORTER.report error
51
52
  FOREST_LOGGER.error "Stripe error: #{error.message}"
52
53
  @records = []
53
54
  end
@@ -46,6 +46,7 @@ module ForestLiana
46
46
  d
47
47
  end
48
48
  rescue ::Stripe::InvalidRequestError => error
49
+ FOREST_REPORTER.report error
49
50
  FOREST_LOGGER.error "Stripe error: #{error.message}"
50
51
  @records = []
51
52
  end
@@ -43,6 +43,7 @@ module ForestLiana
43
43
  d
44
44
  end
45
45
  rescue ::Stripe::InvalidRequestError => error
46
+ FOREST_REPORTER.report error
46
47
  FOREST_LOGGER.error "Stripe error: #{error.message}"
47
48
  @records = []
48
49
  end
@@ -18,12 +18,19 @@ module ForestLiana
18
18
  displayed_message = "[#{datetime.to_s(:db)}] Forest 🌳🌳🌳 " \
19
19
  "#{message}\n"
20
20
  "\e[#{logger_colors[severity.to_sym]}m#{displayed_message}\033[0m"
21
- end
21
+ end
22
22
  logger
23
23
  end
24
24
  end
25
25
  end
26
26
  end
27
+
28
+ class Reporter
29
+ def self.report (error)
30
+ ForestLiana.reporter.report error if ForestLiana.reporter
31
+ end
32
+ end
27
33
  end
28
34
 
29
35
  FOREST_LOGGER = ForestLiana::Logger.log
36
+ FOREST_REPORTER = ForestLiana::Reporter
@@ -57,10 +57,12 @@ module ForestLiana
57
57
  @collections_sent.each do |collection|
58
58
  collection['actions'].each do |action|
59
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}
60
+ unless c.nil?
61
+ a = get_action(c, action['name'])
62
+ load = !a.hooks.nil? && a.hooks.key?(:load) && a.hooks[:load].is_a?(Proc)
63
+ change = !a.hooks.nil? && a.hooks.key?(:change) && a.hooks[:change].is_a?(Hash) ? a.hooks[:change].keys : []
64
+ action['hooks'] = {'load' => load, 'change' => change}
65
+ end
64
66
  end
65
67
  end
66
68
  end
@@ -82,7 +84,8 @@ module ForestLiana
82
84
  @collections_sent = content['collections']
83
85
  @meta_sent = content['meta']
84
86
  generate_action_hooks
85
- rescue JSON::JSONError
87
+ rescue JSON::JSONError => error
88
+ FOREST_REPORTER.report error
86
89
  FOREST_LOGGER.error "The content of .forestadmin-schema.json file is not a correct JSON."
87
90
  FOREST_LOGGER.error "The schema cannot be synchronized with Forest Admin servers."
88
91
  end
@@ -122,6 +125,7 @@ module ForestLiana
122
125
  end
123
126
  end
124
127
  rescue => exception
128
+ FOREST_REPORTER.report exception
125
129
  FOREST_LOGGER.error "Cannot fetch properly model #{model.name}:\n" \
126
130
  "#{exception}"
127
131
  end
@@ -91,6 +91,7 @@ module ForestLiana::Collection
91
91
  begin
92
92
  object.instance_eval(&block)
93
93
  rescue => exception
94
+ FOREST_REPORTER.report exception
94
95
  FOREST_LOGGER.error "Cannot retrieve the " + name.to_s + " value because of an " \
95
96
  "internal error in the getter implementation: " + exception.message
96
97
  nil
@@ -37,6 +37,7 @@ module ForestLiana
37
37
  end
38
38
  nil
39
39
  rescue => exception
40
+ FOREST_REPORTER.report exception
40
41
  exception
41
42
  end
42
43
  end
@@ -51,6 +52,7 @@ module ForestLiana
51
52
  ActiveRecord::Base.connection_pool.with_connection { |connection| connection.active? }
52
53
  rescue => error
53
54
  database_available = false
55
+ FOREST_REPORTER.report error
54
56
  FOREST_LOGGER.error "No Apimap sent to Forest servers, it seems that the database is not accessible:\n#{error}"
55
57
  end
56
58
  database_available
@@ -75,6 +77,7 @@ module ForestLiana
75
77
 
76
78
  config.after_initialize do |app|
77
79
  if error
80
+ FOREST_REPORTER.report error
78
81
  FOREST_LOGGER.error "Impossible to set the whitelisted Forest " \
79
82
  "domains for CORS constraint:\n#{error}"
80
83
  end
@@ -102,6 +102,7 @@ module ForestLiana
102
102
  rescue ForestLiana::Errors::SmartActionInvalidFieldError => invalid_field_error
103
103
  FOREST_LOGGER.warn invalid_field_error.message
104
104
  rescue ForestLiana::Errors::SmartActionInvalidFieldHookError => invalid_hook_error
105
+ FOREST_REPORTER.report invalid_hook_error
105
106
  FOREST_LOGGER.error invalid_hook_error.message
106
107
  end
107
108
  action['fields'] = action['fields'].map { |field| field.slice(*KEYS_ACTION_FIELD) }
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "7.2.2"
2
+ VERSION = "7.4.2"
3
3
  end
data/lib/forest_liana.rb CHANGED
@@ -28,6 +28,7 @@ module ForestLiana
28
28
  mattr_accessor :names_overriden
29
29
  mattr_accessor :meta
30
30
  mattr_accessor :logger
31
+ mattr_accessor :reporter
31
32
  # TODO: Remove once lianas prior to 2.0.0 are not supported anymore.
32
33
  mattr_accessor :names_old_overriden
33
34
 
@@ -40,6 +41,7 @@ module ForestLiana
40
41
  self.names_overriden = {}
41
42
  self.meta = {}
42
43
  self.logger = nil
44
+ self.reporter = nil
43
45
 
44
46
  @config_dir = 'lib/forest_liana/**/*.rb'
45
47
 
@@ -27,4 +27,41 @@ module ForestLiana
27
27
  end
28
28
  end
29
29
  end
30
+
31
+ describe Reporter do
32
+ describe 'self.reporter' do
33
+ describe 'with a reporter provided' do
34
+ it 'should report the error' do
35
+ class SampleReporter
36
+ def report(error)
37
+ end
38
+ end
39
+
40
+ spier = spy('sampleReporter')
41
+
42
+ ForestLiana.reporter = spier
43
+ FOREST_REPORTER.report(Exception.new "sample error")
44
+
45
+ expect(spier).to have_received(:report)
46
+ ForestLiana.reporter = nil
47
+ end
48
+ end
49
+
50
+ describe 'without any reporter provided' do
51
+ it 'should not report the error' do
52
+ class ErrorReporter
53
+ def report(error)
54
+ expect(false).to be_truthy
55
+ end
56
+ end
57
+
58
+ spier = spy('errorReporter')
59
+
60
+ FOREST_REPORTER.report(Exception.new "sample error")
61
+
62
+ expect(spier).not_to have_received(:export)
63
+ end
64
+ end
65
+ end
66
+ end
30
67
  end
@@ -0,0 +1 @@
1
+ o: ActiveSupport::Cache::Entry : @value{:client_idI"random_id:ET: issuerI"api.forestadmin.com;T:
@@ -136,13 +136,26 @@ describe 'Requesting Actions routes', :type => :request do
136
136
  }
137
137
  }
138
138
 
139
+ use_user_context_action_definition = {
140
+ name: 'use_user_context',
141
+ fields: [foo],
142
+ hooks: {
143
+ :load => -> (context) {
144
+ foo = context[:fields].find{|field| field[:field] == 'foo'}
145
+ foo[:value] = context[:user]['first_name']
146
+ context[:fields]
147
+ }
148
+ }
149
+ }
150
+
139
151
  action = ForestLiana::Model::Action.new(action_definition)
140
152
  fail_action = ForestLiana::Model::Action.new(fail_action_definition)
141
153
  cheat_action = ForestLiana::Model::Action.new(cheat_action_definition)
142
154
  enums_action = ForestLiana::Model::Action.new(enums_action_definition)
143
155
  multiple_enums_action = ForestLiana::Model::Action.new(multiple_enums_action_definition)
156
+ use_user_context_action = ForestLiana::Model::Action.new(use_user_context_action_definition)
144
157
  island = ForestLiana.apimap.find {|collection| collection.name.to_s == ForestLiana.name_for(Island)}
145
- island.actions = [action, fail_action, cheat_action, enums_action, multiple_enums_action]
158
+ island.actions = [action, fail_action, cheat_action, enums_action, multiple_enums_action, use_user_context_action]
146
159
 
147
160
  describe 'call /load' do
148
161
  params = {
@@ -174,6 +187,12 @@ describe 'Requesting Actions routes', :type => :request do
174
187
  expect(response.status).to eq(500)
175
188
  expect(JSON.parse(response.body)).to eq({'error' => 'Error in smart action load hook: hook must return an array of fields'})
176
189
  end
190
+
191
+ it 'should return the first_name of the user who call the action' do
192
+ post '/forest/actions/use_user_context/hooks/load', params: JSON.dump(params), headers: headers
193
+ expect(response.status).to eq(200)
194
+ expect(JSON.parse(response.body)).to eq({'fields' => [foo.merge({:value => 'Michael'}).transform_keys { |key| key.to_s.camelize(:lower) }.stringify_keys]})
195
+ end
177
196
  end
178
197
 
179
198
  describe 'call /change' do
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.2.2
4
+ version: 7.4.2
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-09-30 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -372,6 +372,7 @@ files:
372
372
  - spec/dummy/lib/forest_liana/collections/island.rb
373
373
  - spec/dummy/lib/forest_liana/collections/location.rb
374
374
  - spec/dummy/lib/forest_liana/collections/user.rb
375
+ - spec/dummy/tmp/cache/11D/A92/http%3A%2F%2Flocalhost%3A3000%2Fforest%2Fauthentication%2Fcallback-env_secret_test-client-data
375
376
  - spec/helpers/forest_liana/query_helper_spec.rb
376
377
  - spec/helpers/forest_liana/schema_helper_spec.rb
377
378
  - spec/lib/forest_liana/bootstrapper_spec.rb
@@ -510,171 +511,172 @@ signing_key:
510
511
  specification_version: 4
511
512
  summary: Official Rails Liana for Forest
512
513
  test_files:
514
+ - test/test_helper.rb
515
+ - test/services/forest_liana/operator_date_interval_parser_test.rb
516
+ - test/services/forest_liana/schema_adapter_test.rb
513
517
  - test/routing/route_test.rb
514
518
  - test/forest_liana_test.rb
515
- - test/fixtures/belongs_to_field.yml
516
- - test/fixtures/owner.yml
517
- - test/fixtures/has_one_field.yml
518
- - test/fixtures/serialize_field.yml
519
- - test/fixtures/string_field.yml
520
- - test/fixtures/has_many_through_field.yml
521
- - test/fixtures/reference.yml
522
- - test/fixtures/has_many_field.yml
523
- - test/fixtures/tree.yml
524
- - test/dummy/README.rdoc
525
- - test/dummy/public/404.html
526
- - test/dummy/public/422.html
527
- - test/dummy/public/500.html
528
- - test/dummy/public/favicon.ico
529
519
  - test/dummy/Rakefile
530
- - test/dummy/config/application.rb
531
- - test/dummy/config/routes.rb
520
+ - test/dummy/bin/setup
521
+ - test/dummy/bin/bundle
522
+ - test/dummy/bin/rake
523
+ - test/dummy/bin/rails
524
+ - test/dummy/db/schema.rb
525
+ - test/dummy/db/migrate/20150608131603_create_decimal_field.rb
526
+ - test/dummy/db/migrate/20150814081918_create_has_many_through_field.rb
527
+ - test/dummy/db/migrate/20160627172951_create_tree.rb
528
+ - test/dummy/db/migrate/20160628173505_add_timestamps.rb
529
+ - test/dummy/db/migrate/20150608130516_create_date_field.rb
530
+ - test/dummy/db/migrate/20181111162121_create_references_table.rb
531
+ - test/dummy/db/migrate/20160627172810_create_owner.rb
532
+ - test/dummy/db/migrate/20150608132621_create_string_field.rb
533
+ - test/dummy/db/migrate/20150609114636_create_belongs_to_class_name_field.rb
534
+ - test/dummy/db/migrate/20150616150629_create_polymorphic_field.rb
535
+ - test/dummy/db/migrate/20150608133038_create_belongs_to_field.rb
536
+ - test/dummy/db/migrate/20150608133044_create_has_one_field.rb
537
+ - test/dummy/db/migrate/20150608131610_create_float_field.rb
538
+ - test/dummy/db/migrate/20150608150016_create_has_many_field.rb
539
+ - test/dummy/db/migrate/20150608132159_create_boolean_field.rb
540
+ - test/dummy/db/migrate/20170614141921_create_serialize_field.rb
541
+ - test/dummy/db/migrate/20150623115554_create_has_many_class_name_field.rb
542
+ - test/dummy/db/migrate/20150612112520_create_has_and_belongs_to_many_field.rb
543
+ - test/dummy/db/migrate/20150608131430_create_integer_field.rb
544
+ - test/dummy/config.ru
545
+ - test/dummy/README.rdoc
546
+ - test/dummy/config/environment.rb
547
+ - test/dummy/config/locales/en.yml
548
+ - test/dummy/config/database.yml
532
549
  - test/dummy/config/environments/production.rb
533
550
  - test/dummy/config/environments/test.rb
534
551
  - test/dummy/config/environments/development.rb
535
- - test/dummy/config/database.yml
552
+ - test/dummy/config/routes.rb
553
+ - test/dummy/config/secrets.yml
536
554
  - test/dummy/config/initializers/backtrace_silencers.rb
537
- - test/dummy/config/initializers/assets.rb
538
555
  - test/dummy/config/initializers/wrap_parameters.rb
539
- - test/dummy/config/initializers/filter_parameter_logging.rb
540
- - test/dummy/config/initializers/session_store.rb
541
- - test/dummy/config/initializers/inflections.rb
542
556
  - test/dummy/config/initializers/mime_types.rb
543
557
  - test/dummy/config/initializers/cookies_serializer.rb
544
- - test/dummy/config/locales/en.yml
545
- - test/dummy/config/environment.rb
546
- - test/dummy/config/secrets.yml
558
+ - test/dummy/config/initializers/inflections.rb
559
+ - test/dummy/config/initializers/filter_parameter_logging.rb
560
+ - test/dummy/config/initializers/session_store.rb
561
+ - test/dummy/config/initializers/assets.rb
562
+ - test/dummy/config/application.rb
547
563
  - test/dummy/config/boot.rb
548
- - test/dummy/app/models/has_many_through_field.rb
549
- - test/dummy/app/models/tree.rb
564
+ - test/dummy/app/helpers/application_helper.rb
550
565
  - test/dummy/app/models/belongs_to_field.rb
551
- - test/dummy/app/models/belongs_to_class_name_field.rb
566
+ - test/dummy/app/models/tree.rb
567
+ - test/dummy/app/models/boolean_field.rb
552
568
  - test/dummy/app/models/polymorphic_field.rb
553
569
  - test/dummy/app/models/reference.rb
570
+ - test/dummy/app/models/belongs_to_class_name_field.rb
571
+ - test/dummy/app/models/integer_field.rb
554
572
  - test/dummy/app/models/date_field.rb
573
+ - test/dummy/app/models/serialize_field.rb
555
574
  - test/dummy/app/models/decimal_field.rb
556
575
  - test/dummy/app/models/owner.rb
557
576
  - test/dummy/app/models/has_many_field.rb
558
- - test/dummy/app/models/boolean_field.rb
559
- - test/dummy/app/models/has_and_belongs_to_many_field.rb
560
- - test/dummy/app/models/serialize_field.rb
561
- - test/dummy/app/models/integer_field.rb
562
- - test/dummy/app/models/float_field.rb
563
577
  - test/dummy/app/models/has_many_class_name_field.rb
564
578
  - test/dummy/app/models/string_field.rb
565
579
  - test/dummy/app/models/has_one_field.rb
566
- - test/dummy/app/views/layouts/application.html.erb
580
+ - test/dummy/app/models/has_many_through_field.rb
581
+ - test/dummy/app/models/float_field.rb
582
+ - test/dummy/app/models/has_and_belongs_to_many_field.rb
567
583
  - test/dummy/app/assets/javascripts/application.js
568
584
  - test/dummy/app/assets/stylesheets/application.css
569
585
  - test/dummy/app/assets/config/manifest.js
570
586
  - test/dummy/app/controllers/application_controller.rb
571
- - test/dummy/app/helpers/application_helper.rb
572
- - test/dummy/config.ru
573
- - test/dummy/db/migrate/20150608131603_create_decimal_field.rb
574
- - test/dummy/db/migrate/20150616150629_create_polymorphic_field.rb
575
- - test/dummy/db/migrate/20160628173505_add_timestamps.rb
576
- - test/dummy/db/migrate/20181111162121_create_references_table.rb
577
- - test/dummy/db/migrate/20150623115554_create_has_many_class_name_field.rb
578
- - test/dummy/db/migrate/20150608131610_create_float_field.rb
579
- - test/dummy/db/migrate/20160627172951_create_tree.rb
580
- - test/dummy/db/migrate/20150612112520_create_has_and_belongs_to_many_field.rb
581
- - test/dummy/db/migrate/20150608132159_create_boolean_field.rb
582
- - test/dummy/db/migrate/20150608131430_create_integer_field.rb
583
- - test/dummy/db/migrate/20150608133044_create_has_one_field.rb
584
- - test/dummy/db/migrate/20150609114636_create_belongs_to_class_name_field.rb
585
- - test/dummy/db/migrate/20150814081918_create_has_many_through_field.rb
586
- - test/dummy/db/migrate/20150608130516_create_date_field.rb
587
- - test/dummy/db/migrate/20170614141921_create_serialize_field.rb
588
- - test/dummy/db/migrate/20150608133038_create_belongs_to_field.rb
589
- - test/dummy/db/migrate/20150608150016_create_has_many_field.rb
590
- - test/dummy/db/migrate/20160627172810_create_owner.rb
591
- - test/dummy/db/migrate/20150608132621_create_string_field.rb
592
- - test/dummy/db/schema.rb
593
- - test/dummy/bin/rails
594
- - test/dummy/bin/rake
595
- - test/dummy/bin/bundle
596
- - test/dummy/bin/setup
597
- - test/services/forest_liana/operator_date_interval_parser_test.rb
598
- - test/services/forest_liana/schema_adapter_test.rb
599
- - test/test_helper.rb
587
+ - test/dummy/app/views/layouts/application.html.erb
588
+ - test/dummy/public/favicon.ico
589
+ - test/dummy/public/422.html
590
+ - test/dummy/public/404.html
591
+ - test/dummy/public/500.html
592
+ - test/fixtures/serialize_field.yml
593
+ - test/fixtures/has_one_field.yml
594
+ - test/fixtures/owner.yml
595
+ - test/fixtures/has_many_field.yml
596
+ - test/fixtures/has_many_through_field.yml
597
+ - test/fixtures/tree.yml
598
+ - test/fixtures/reference.yml
599
+ - test/fixtures/belongs_to_field.yml
600
+ - test/fixtures/string_field.yml
601
+ - spec/helpers/forest_liana/query_helper_spec.rb
602
+ - spec/helpers/forest_liana/schema_helper_spec.rb
603
+ - spec/services/forest_liana/permissions_checker_acl_disabled_spec.rb
604
+ - spec/services/forest_liana/has_many_getter_spec.rb
605
+ - spec/services/forest_liana/smart_action_field_validator_spec.rb
606
+ - spec/services/forest_liana/permissions_checker_live_queries_spec.rb
607
+ - spec/services/forest_liana/schema_adapter_spec.rb
608
+ - spec/services/forest_liana/scope_manager_spec.rb
609
+ - spec/services/forest_liana/permissions_formatter_spec.rb
610
+ - spec/services/forest_liana/filters_parser_spec.rb
611
+ - spec/services/forest_liana/apimap_sorter_spec.rb
612
+ - spec/services/forest_liana/pie_stat_getter_spec.rb
613
+ - spec/services/forest_liana/resources_getter_spec.rb
614
+ - spec/services/forest_liana/permissions_getter_spec.rb
615
+ - spec/services/forest_liana/line_stat_getter_spec.rb
616
+ - spec/services/forest_liana/value_stat_getter_spec.rb
617
+ - spec/services/forest_liana/resource_updater_spec.rb
618
+ - spec/services/forest_liana/permissions_checker_acl_enabled_spec.rb
619
+ - spec/services/forest_liana/ip_whitelist_checker_spec.rb
600
620
  - spec/spec_helper.rb
601
- - spec/config/initializers/logger_spec.rb
602
- - spec/lib/forest_liana/schema_file_updater_spec.rb
603
621
  - spec/lib/forest_liana/bootstrapper_spec.rb
622
+ - spec/lib/forest_liana/schema_file_updater_spec.rb
623
+ - spec/config/initializers/logger_spec.rb
604
624
  - spec/rails_helper.rb
605
- - spec/dummy/README.rdoc
606
625
  - spec/dummy/Rakefile
607
- - spec/dummy/config/application.rb
608
- - spec/dummy/config/routes.rb
626
+ - spec/dummy/bin/setup
627
+ - spec/dummy/bin/bundle
628
+ - spec/dummy/bin/rake
629
+ - spec/dummy/bin/rails
630
+ - spec/dummy/db/schema.rb
631
+ - spec/dummy/db/migrate/20190716135241_add_type_to_user.rb
632
+ - spec/dummy/db/migrate/20190226174951_create_tree.rb
633
+ - spec/dummy/db/migrate/20210326110524_create_references.rb
634
+ - spec/dummy/db/migrate/20210526084712_create_products.rb
635
+ - spec/dummy/db/migrate/20190226172951_create_user.rb
636
+ - spec/dummy/db/migrate/20210511141752_create_owners.rb
637
+ - spec/dummy/db/migrate/20190716130830_add_age_to_tree.rb
638
+ - spec/dummy/db/migrate/20210326140855_create_locations.rb
639
+ - spec/dummy/db/migrate/20190226173051_create_isle.rb
640
+ - spec/dummy/config.ru
641
+ - spec/dummy/README.rdoc
642
+ - spec/dummy/lib/forest_liana/collections/user.rb
643
+ - spec/dummy/lib/forest_liana/collections/island.rb
644
+ - spec/dummy/lib/forest_liana/collections/location.rb
645
+ - spec/dummy/config/environment.rb
646
+ - spec/dummy/config/database.yml
609
647
  - spec/dummy/config/environments/production.rb
610
648
  - spec/dummy/config/environments/test.rb
611
649
  - spec/dummy/config/environments/development.rb
612
- - spec/dummy/config/database.yml
650
+ - spec/dummy/config/routes.rb
651
+ - spec/dummy/config/secrets.yml
613
652
  - spec/dummy/config/initializers/backtrace_silencers.rb
614
- - spec/dummy/config/initializers/assets.rb
615
653
  - spec/dummy/config/initializers/wrap_parameters.rb
616
- - spec/dummy/config/initializers/filter_parameter_logging.rb
617
- - spec/dummy/config/initializers/session_store.rb
618
- - spec/dummy/config/initializers/forest_liana.rb
619
- - spec/dummy/config/initializers/inflections.rb
620
654
  - spec/dummy/config/initializers/mime_types.rb
621
655
  - spec/dummy/config/initializers/cookies_serializer.rb
622
- - spec/dummy/config/environment.rb
623
- - spec/dummy/config/secrets.yml
656
+ - spec/dummy/config/initializers/forest_liana.rb
657
+ - spec/dummy/config/initializers/inflections.rb
658
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
659
+ - spec/dummy/config/initializers/session_store.rb
660
+ - spec/dummy/config/initializers/assets.rb
661
+ - spec/dummy/config/application.rb
624
662
  - spec/dummy/config/boot.rb
625
- - spec/dummy/lib/forest_liana/collections/island.rb
626
- - spec/dummy/lib/forest_liana/collections/user.rb
627
- - spec/dummy/lib/forest_liana/collections/location.rb
663
+ - spec/dummy/app/helpers/application_helper.rb
628
664
  - spec/dummy/app/models/tree.rb
629
- - spec/dummy/app/models/island.rb
630
665
  - spec/dummy/app/models/reference.rb
666
+ - spec/dummy/app/models/user.rb
667
+ - spec/dummy/app/models/island.rb
631
668
  - spec/dummy/app/models/owner.rb
632
669
  - spec/dummy/app/models/product.rb
633
- - spec/dummy/app/models/user.rb
634
670
  - spec/dummy/app/models/location.rb
635
- - spec/dummy/app/views/layouts/application.html.erb
636
671
  - spec/dummy/app/config/routes.rb
637
672
  - spec/dummy/app/assets/javascripts/application.js
638
673
  - spec/dummy/app/assets/stylesheets/application.css
639
674
  - spec/dummy/app/assets/config/manifest.js
640
675
  - spec/dummy/app/controllers/application_controller.rb
641
676
  - spec/dummy/app/controllers/forest/islands_controller.rb
642
- - spec/dummy/app/helpers/application_helper.rb
643
- - spec/dummy/config.ru
644
- - spec/dummy/db/migrate/20190226173051_create_isle.rb
645
- - spec/dummy/db/migrate/20190226172951_create_user.rb
646
- - spec/dummy/db/migrate/20190716130830_add_age_to_tree.rb
647
- - spec/dummy/db/migrate/20210326110524_create_references.rb
648
- - spec/dummy/db/migrate/20190226174951_create_tree.rb
649
- - spec/dummy/db/migrate/20210526084712_create_products.rb
650
- - spec/dummy/db/migrate/20210326140855_create_locations.rb
651
- - spec/dummy/db/migrate/20190716135241_add_type_to_user.rb
652
- - spec/dummy/db/migrate/20210511141752_create_owners.rb
653
- - spec/dummy/db/schema.rb
654
- - spec/dummy/bin/rails
655
- - spec/dummy/bin/rake
656
- - spec/dummy/bin/bundle
657
- - spec/dummy/bin/setup
658
- - spec/services/forest_liana/apimap_sorter_spec.rb
659
- - spec/services/forest_liana/smart_action_field_validator_spec.rb
660
- - spec/services/forest_liana/resource_updater_spec.rb
661
- - spec/services/forest_liana/has_many_getter_spec.rb
662
- - spec/services/forest_liana/scope_manager_spec.rb
663
- - spec/services/forest_liana/permissions_checker_acl_disabled_spec.rb
664
- - spec/services/forest_liana/ip_whitelist_checker_spec.rb
665
- - spec/services/forest_liana/permissions_formatter_spec.rb
666
- - spec/services/forest_liana/value_stat_getter_spec.rb
667
- - spec/services/forest_liana/line_stat_getter_spec.rb
668
- - spec/services/forest_liana/filters_parser_spec.rb
669
- - spec/services/forest_liana/permissions_checker_live_queries_spec.rb
670
- - spec/services/forest_liana/permissions_getter_spec.rb
671
- - spec/services/forest_liana/pie_stat_getter_spec.rb
672
- - spec/services/forest_liana/permissions_checker_acl_enabled_spec.rb
673
- - spec/services/forest_liana/schema_adapter_spec.rb
674
- - spec/services/forest_liana/resources_getter_spec.rb
677
+ - spec/dummy/app/views/layouts/application.html.erb
678
+ - spec/dummy/tmp/cache/11D/A92/http%3A%2F%2Flocalhost%3A3000%2Fforest%2Fauthentication%2Fcallback-env_secret_test-client-data
679
+ - spec/requests/resources_spec.rb
675
680
  - spec/requests/authentications_spec.rb
676
681
  - spec/requests/actions_controller_spec.rb
677
682
  - spec/requests/stats_spec.rb
678
- - spec/requests/resources_spec.rb
679
- - spec/helpers/forest_liana/query_helper_spec.rb
680
- - spec/helpers/forest_liana/schema_helper_spec.rb