forest_liana 1.3.28 → 1.3.29
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/intercom_controller.rb +8 -1
- data/app/controllers/forest_liana/stripe_controller.rb +33 -0
- data/app/models/forest_liana/model/collection.rb +1 -1
- data/app/serializers/forest_liana/collection_serializer.rb +3 -0
- data/app/serializers/forest_liana/intercom_attribute_serializer.rb +1 -1
- data/app/serializers/forest_liana/intercom_conversation_serializer.rb +1 -1
- data/app/serializers/forest_liana/serializer_factory.rb +44 -8
- data/app/serializers/forest_liana/stripe_bank_account_serializer.rb +43 -0
- data/app/serializers/forest_liana/stripe_card_serializer.rb +1 -1
- data/app/serializers/forest_liana/stripe_invoice_serializer.rb +1 -1
- data/app/serializers/forest_liana/stripe_payment_serializer.rb +1 -1
- data/app/serializers/forest_liana/stripe_subscription_serializer.rb +45 -0
- data/app/services/forest_liana/intercom_attributes_getter.rb +3 -11
- data/app/services/forest_liana/intercom_conversations_getter.rb +3 -10
- data/app/services/forest_liana/operator_value_parser.rb +1 -1
- data/app/services/forest_liana/schema_adapter.rb +61 -31
- data/app/services/forest_liana/stripe_bank_accounts_getter.rb +86 -0
- data/app/services/forest_liana/stripe_cards_getter.rb +26 -22
- data/app/services/forest_liana/stripe_invoices_getter.rb +28 -26
- data/app/services/forest_liana/stripe_payments_getter.rb +28 -25
- data/app/services/forest_liana/stripe_subscriptions_getter.rb +97 -0
- data/config/routes.rb +5 -2
- data/lib/forest_liana/bootstraper.rb +205 -30
- data/lib/forest_liana/version.rb +1 -1
- metadata +6 -2
@@ -3,12 +3,28 @@ module ForestLiana
|
|
3
3
|
|
4
4
|
def initialize(app)
|
5
5
|
@app = app
|
6
|
+
|
7
|
+
@integration_stripe_valid = false
|
8
|
+
@integration_intercom_valid = false
|
9
|
+
|
6
10
|
@logger = Logger.new(STDOUT)
|
7
11
|
|
12
|
+
@@logger_colors = {
|
13
|
+
DEBUG: 34,
|
14
|
+
WARN: 33,
|
15
|
+
ERROR: 31,
|
16
|
+
INFO: 37
|
17
|
+
}
|
18
|
+
|
19
|
+
@logger.formatter = proc do |severity, datetime, progname, message|
|
20
|
+
displayed_message = "[#{datetime.to_s(:db)}] Forest 🌳🌳🌳 #{message}\n"
|
21
|
+
"\e[#{@@logger_colors[severity.to_sym]}m#{displayed_message}\033[0m"
|
22
|
+
end
|
23
|
+
|
8
24
|
if ForestLiana.jwt_signing_key
|
9
|
-
warn "DEPRECATION WARNING: the use of
|
10
|
-
(config/initializers/forest_liana.rb) is
|
11
|
-
ForestLiana.secret_key and ForestLiana.auth_key instead. \
|
25
|
+
@logger.warn "DEPRECATION WARNING: the use of \
|
26
|
+
ForestLiana.jwt_signing_key (config/initializers/forest_liana.rb) is \
|
27
|
+
deprecated. Use ForestLiana.secret_key and ForestLiana.auth_key instead. \
|
12
28
|
More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
13
29
|
ForestLiana.secret_key = ForestLiana.jwt_signing_key
|
14
30
|
ForestLiana.auth_key = ForestLiana.jwt_signing_key
|
@@ -16,6 +32,7 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
16
32
|
end
|
17
33
|
|
18
34
|
def perform
|
35
|
+
check_integrations_setup
|
19
36
|
create_serializers
|
20
37
|
|
21
38
|
if ForestLiana.secret_key
|
@@ -27,6 +44,10 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
27
44
|
|
28
45
|
private
|
29
46
|
|
47
|
+
def cast_to_array value
|
48
|
+
value.is_a?(String) ? [value] : value
|
49
|
+
end
|
50
|
+
|
30
51
|
def create_serializers
|
31
52
|
SchemaUtils.tables_names.map do |table_name|
|
32
53
|
model = SchemaUtils.find_model_from_table_name(table_name)
|
@@ -47,6 +68,28 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
47
68
|
end
|
48
69
|
end
|
49
70
|
|
71
|
+
def check_integrations_setup
|
72
|
+
if stripe_integration?
|
73
|
+
if stripe_integration_valid? || stripe_integration_deprecated?
|
74
|
+
ForestLiana.integrations[:stripe][:mapping] =
|
75
|
+
cast_to_array(ForestLiana.integrations[:stripe][:mapping])
|
76
|
+
@integration_stripe_valid = true
|
77
|
+
else
|
78
|
+
@logger.error 'Cannot setup properly your Stripe integration.'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
if intercom_integration?
|
83
|
+
if intercom_integration_valid? || intercom_integration_deprecated?
|
84
|
+
ForestLiana.integrations[:intercom][:mapping] =
|
85
|
+
cast_to_array(ForestLiana.integrations[:intercom][:mapping])
|
86
|
+
@integration_intercom_valid = true
|
87
|
+
else
|
88
|
+
@logger.error 'Cannot setup properly your Intercom integration.'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
50
93
|
def create_apimap
|
51
94
|
SchemaUtils.tables_names.map do |table_name|
|
52
95
|
model = SchemaUtils.find_model_from_table_name(table_name)
|
@@ -55,8 +98,17 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
55
98
|
end
|
56
99
|
end
|
57
100
|
|
58
|
-
|
59
|
-
|
101
|
+
if @integration_stripe_valid
|
102
|
+
ForestLiana.integrations[:stripe][:mapping].each do |collection|
|
103
|
+
setup_stripe_integration collection
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
if @integration_intercom_valid
|
108
|
+
ForestLiana.integrations[:intercom][:mapping].each do |collection_name|
|
109
|
+
setup_intercom_integration collection_name
|
110
|
+
end
|
111
|
+
end
|
60
112
|
end
|
61
113
|
|
62
114
|
def require_lib_forest_liana
|
@@ -73,26 +125,35 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
73
125
|
meta: { liana: 'forest-rails', liana_version: liana_version }
|
74
126
|
})
|
75
127
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
"
|
128
|
+
begin
|
129
|
+
uri = URI.parse("#{forest_url}/forest/apimaps")
|
130
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
131
|
+
http.use_ssl = true if forest_url.start_with?('https')
|
132
|
+
http.start do |client|
|
133
|
+
request = Net::HTTP::Post.new(uri.path)
|
134
|
+
request.body = json.to_json
|
135
|
+
request['Content-Type'] = 'application/json'
|
136
|
+
request['forest-secret-key'] = ForestLiana.secret_key
|
137
|
+
response = client.request(request)
|
138
|
+
|
139
|
+
if response.is_a?(Net::HTTPNotFound)
|
140
|
+
@logger.warn "Cannot find your project secret key. " \
|
141
|
+
"Please, run `rails g forest_liana:install`."
|
142
|
+
end
|
89
143
|
end
|
144
|
+
rescue Errno::ECONNREFUSED
|
145
|
+
@logger.warn "Cannot send the apimap to Forest. Are you online?"
|
90
146
|
end
|
91
147
|
end
|
92
148
|
|
93
|
-
def setup_intercom_integration
|
149
|
+
def setup_intercom_integration(collection_name)
|
150
|
+
model_name = collection_name.constantize.try(:table_name)
|
151
|
+
collection_display_name = collection_name.capitalize
|
152
|
+
|
94
153
|
ForestLiana.apimap << ForestLiana::Model::Collection.new({
|
95
|
-
name:
|
154
|
+
name: "#{model_name}_intercom_conversations",
|
155
|
+
display_name: collection_display_name + ' Conversations',
|
156
|
+
icon: 'intercom',
|
96
157
|
only_for_relationships: true,
|
97
158
|
is_virtual: true,
|
98
159
|
fields: [
|
@@ -105,7 +166,9 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
105
166
|
})
|
106
167
|
|
107
168
|
ForestLiana.apimap << ForestLiana::Model::Collection.new({
|
108
|
-
name:
|
169
|
+
name: "#{model_name}_intercom_attributes",
|
170
|
+
display_name: collection_display_name + ' Attributes',
|
171
|
+
icon: 'intercom',
|
109
172
|
only_for_relationships: true,
|
110
173
|
is_virtual: true,
|
111
174
|
fields: [
|
@@ -134,15 +197,41 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
134
197
|
def intercom_integration?
|
135
198
|
ForestLiana.integrations
|
136
199
|
.try(:[], :intercom)
|
137
|
-
.try(:[], :user_collection)
|
138
200
|
.present?
|
139
201
|
end
|
140
202
|
|
141
|
-
def
|
203
|
+
def intercom_integration_valid?
|
204
|
+
integration = ForestLiana.integrations.try(:[], :intercom)
|
205
|
+
integration.present? && integration.has_key?(:api_key) &&
|
206
|
+
integration.has_key?(:app_id) && integration.has_key?(:mapping)
|
207
|
+
end
|
208
|
+
|
209
|
+
def intercom_integration_deprecated?
|
210
|
+
integration = ForestLiana.integrations.try(:[], :intercom)
|
211
|
+
|
212
|
+
is_deprecated = integration.present? && integration.has_key?(:api_key) &&
|
213
|
+
integration.has_key?(:app_id) && integration.has_key?(:user_collection)
|
214
|
+
|
215
|
+
if is_deprecated
|
216
|
+
@logger.warn "Intercom integration attribute \"user_collection\" is " \
|
217
|
+
"now deprecated, please use \"mapping\" attribute."
|
218
|
+
end
|
219
|
+
|
220
|
+
is_deprecated
|
221
|
+
end
|
222
|
+
|
223
|
+
def setup_stripe_integration(collection_name_and_field)
|
224
|
+
collection_name = collection_name_and_field.split('.')[0]
|
225
|
+
model_name = collection_name.constantize.try(:table_name)
|
226
|
+
collection_display_name = model_name.capitalize
|
227
|
+
|
142
228
|
ForestLiana.apimap << ForestLiana::Model::Collection.new({
|
143
|
-
name:
|
229
|
+
name: "#{model_name}_stripe_payments",
|
230
|
+
display_name: collection_display_name + ' Payments',
|
231
|
+
icon: 'stripe',
|
144
232
|
is_virtual: true,
|
145
233
|
is_read_only: true,
|
234
|
+
pagination_type: 'cursor',
|
146
235
|
fields: [
|
147
236
|
{ field: :id, type: 'String', is_searchable: false },
|
148
237
|
{ field: :created, type: 'Date', is_searchable: false },
|
@@ -154,7 +243,7 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
154
243
|
{
|
155
244
|
field: :customer,
|
156
245
|
type: 'String',
|
157
|
-
reference:
|
246
|
+
reference: "#{model_name}.id",
|
158
247
|
is_searchable: false
|
159
248
|
}
|
160
249
|
],
|
@@ -167,9 +256,12 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
167
256
|
})
|
168
257
|
|
169
258
|
ForestLiana.apimap << ForestLiana::Model::Collection.new({
|
170
|
-
name:
|
259
|
+
name: "#{model_name}_stripe_invoices",
|
260
|
+
display_name: collection_display_name + ' Invoices',
|
261
|
+
icon: 'stripe',
|
171
262
|
is_virtual: true,
|
172
263
|
is_read_only: true,
|
264
|
+
pagination_type: 'cursor',
|
173
265
|
fields: [
|
174
266
|
{ field: :id, type: 'String', is_searchable: false },
|
175
267
|
{ field: :amount_due, type: 'Number', is_searchable: false },
|
@@ -189,17 +281,20 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
189
281
|
{
|
190
282
|
field: :customer,
|
191
283
|
type: 'String',
|
192
|
-
reference:
|
284
|
+
reference: "#{model_name}.id",
|
193
285
|
is_searchable: false
|
194
286
|
}
|
195
287
|
]
|
196
288
|
})
|
197
289
|
|
198
290
|
ForestLiana.apimap << ForestLiana::Model::Collection.new({
|
199
|
-
name:
|
291
|
+
name: "#{model_name}_stripe_cards",
|
292
|
+
display_name: collection_display_name + ' Cards',
|
293
|
+
icon: 'stripe',
|
200
294
|
is_virtual: true,
|
201
295
|
is_read_only: true,
|
202
296
|
only_for_relationships: true,
|
297
|
+
pagination_type: 'cursor',
|
203
298
|
fields: [
|
204
299
|
{ field: :id, type: 'String', is_searchable: false },
|
205
300
|
{ field: :last4, type: 'String', is_searchable: false },
|
@@ -219,7 +314,68 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
219
314
|
{
|
220
315
|
field: :customer,
|
221
316
|
type: 'String',
|
222
|
-
reference:
|
317
|
+
reference: "#{model_name}.id",
|
318
|
+
is_searchable: false
|
319
|
+
}
|
320
|
+
]
|
321
|
+
})
|
322
|
+
|
323
|
+
ForestLiana.apimap << ForestLiana::Model::Collection.new({
|
324
|
+
name: "#{model_name}_stripe_subscriptions",
|
325
|
+
display_name: collection_display_name + ' Subscriptions',
|
326
|
+
icon: 'stripe',
|
327
|
+
is_virtual: true,
|
328
|
+
is_read_only: true,
|
329
|
+
pagination_type: 'cursor',
|
330
|
+
fields: [
|
331
|
+
{ field: :id, type: 'String', is_searchable: false },
|
332
|
+
{ field: :cancel_at_period_end, type: 'Boolean', is_searchable: false },
|
333
|
+
{ field: :canceled_at, type: 'Date', is_searchable: false },
|
334
|
+
{ field: :created, type: 'Date', is_searchable: false },
|
335
|
+
{ field: :current_period_end, type: 'Date', is_searchable: false },
|
336
|
+
{ field: :current_period_start, type: 'Date', is_searchable: false },
|
337
|
+
{ field: :ended_at, type: 'Date', is_searchable: false },
|
338
|
+
{ field: :livemode, type: 'Boolean', is_searchable: false },
|
339
|
+
{ field: :quantity, type: 'Number', is_searchable: false },
|
340
|
+
{ field: :start, type: 'Date', is_searchable: false },
|
341
|
+
{ field: :status, type: 'String', is_searchable: false },
|
342
|
+
{ field: :tax_percent, type: 'Number', is_searchable: false },
|
343
|
+
{ field: :trial_end, type: 'Date', is_searchable: false },
|
344
|
+
{ field: :trial_start, type: 'Date', is_searchable: false },
|
345
|
+
{
|
346
|
+
field: :customer,
|
347
|
+
type: 'String',
|
348
|
+
reference: "#{model_name}.id",
|
349
|
+
is_searchable: false
|
350
|
+
}
|
351
|
+
]
|
352
|
+
})
|
353
|
+
|
354
|
+
ForestLiana.apimap << ForestLiana::Model::Collection.new({
|
355
|
+
name: "#{model_name}_stripe_bank_accounts",
|
356
|
+
display_name: collection_display_name + ' Bank Accounts',
|
357
|
+
icon: 'stripe',
|
358
|
+
is_virtual: true,
|
359
|
+
is_read_only: true,
|
360
|
+
only_for_relationships: true,
|
361
|
+
pagination_type: 'cursor',
|
362
|
+
fields: [
|
363
|
+
{ field: :id, type: 'String', is_searchable: false },
|
364
|
+
{ field: :account, type: 'String', is_searchable: false },
|
365
|
+
{ field: :account_holder_name, type: 'String', is_searchable: false },
|
366
|
+
{ field: :account_holder_type, type: 'String', is_searchable: false },
|
367
|
+
{ field: :bank_name, type: 'String', is_searchable: false },
|
368
|
+
{ field: :country, type: 'String', is_searchable: false },
|
369
|
+
{ field: :currency, type: 'String', is_searchable: false },
|
370
|
+
{ field: :default_for_currency, type: 'Boolean', is_searchable: false },
|
371
|
+
{ field: :fingerprint, type: 'String', is_searchable: false },
|
372
|
+
{ field: :last4, type: 'String', is_searchable: false },
|
373
|
+
{ field: :rooting_number, type: 'String', is_searchable: false },
|
374
|
+
{ field: :status, type: 'String', is_searchable: false },
|
375
|
+
{
|
376
|
+
field: :customer,
|
377
|
+
type: 'String',
|
378
|
+
reference: "#{model_name}.id",
|
223
379
|
is_searchable: false
|
224
380
|
}
|
225
381
|
]
|
@@ -229,10 +385,29 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
229
385
|
def stripe_integration?
|
230
386
|
ForestLiana.integrations
|
231
387
|
.try(:[], :stripe)
|
232
|
-
.try(:[], :api_key)
|
233
388
|
.present?
|
234
389
|
end
|
235
390
|
|
391
|
+
def stripe_integration_valid?
|
392
|
+
integration = ForestLiana.integrations.try(:[], :stripe)
|
393
|
+
integration.present? && integration.has_key?(:api_key) &&
|
394
|
+
integration.has_key?(:mapping)
|
395
|
+
end
|
396
|
+
|
397
|
+
def stripe_integration_deprecated?
|
398
|
+
integration = ForestLiana.integrations.try(:[], :stripe)
|
399
|
+
is_deprecated = integration.present? && integration.has_key?(:api_key) &&
|
400
|
+
integration.has_key?(:user_collection) &&
|
401
|
+
integration.has_key?(:user_field)
|
402
|
+
|
403
|
+
if is_deprecated
|
404
|
+
@logger.warn "Stripe integration attributes \"user_collection\" and " \
|
405
|
+
"\"user_field\" are now deprecated, please use \"mapping\" attribute."
|
406
|
+
end
|
407
|
+
|
408
|
+
is_deprecated
|
409
|
+
end
|
410
|
+
|
236
411
|
def forest_url
|
237
412
|
ENV['FOREST_URL'] || 'https://forestadmin-server.herokuapp.com';
|
238
413
|
end
|
data/lib/forest_liana/version.rb
CHANGED
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: 1.3.
|
4
|
+
version: 1.3.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Munda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -156,9 +156,11 @@ files:
|
|
156
156
|
- app/serializers/forest_liana/serializer_factory.rb
|
157
157
|
- app/serializers/forest_liana/session_serializer.rb
|
158
158
|
- app/serializers/forest_liana/stat_serializer.rb
|
159
|
+
- app/serializers/forest_liana/stripe_bank_account_serializer.rb
|
159
160
|
- app/serializers/forest_liana/stripe_card_serializer.rb
|
160
161
|
- app/serializers/forest_liana/stripe_invoice_serializer.rb
|
161
162
|
- app/serializers/forest_liana/stripe_payment_serializer.rb
|
163
|
+
- app/serializers/forest_liana/stripe_subscription_serializer.rb
|
162
164
|
- app/services/forest_liana/allowed_users_getter.rb
|
163
165
|
- app/services/forest_liana/has_many_getter.rb
|
164
166
|
- app/services/forest_liana/intercom_attributes_getter.rb
|
@@ -174,10 +176,12 @@ files:
|
|
174
176
|
- app/services/forest_liana/schema_adapter.rb
|
175
177
|
- app/services/forest_liana/schema_utils.rb
|
176
178
|
- app/services/forest_liana/search_query_builder.rb
|
179
|
+
- app/services/forest_liana/stripe_bank_accounts_getter.rb
|
177
180
|
- app/services/forest_liana/stripe_cards_getter.rb
|
178
181
|
- app/services/forest_liana/stripe_invoices_getter.rb
|
179
182
|
- app/services/forest_liana/stripe_payment_refunder.rb
|
180
183
|
- app/services/forest_liana/stripe_payments_getter.rb
|
184
|
+
- app/services/forest_liana/stripe_subscriptions_getter.rb
|
181
185
|
- app/services/forest_liana/value_stat_getter.rb
|
182
186
|
- app/views/layouts/forest_liana/application.html.erb
|
183
187
|
- config/initializers/arel-helpers.rb
|