kaui 0.16.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/assets/javascripts/application.js +1 -1
- data/app/assets/javascripts/kaui/kaui.js +78 -1
- data/app/assets/stylesheets/bootstrap_and_overrides.css.less +5 -0
- data/app/assets/stylesheets/kaui/account.less +20 -0
- data/app/assets/stylesheets/kaui/audit.less +38 -0
- data/app/assets/stylesheets/kaui/common.less +103 -0
- data/app/assets/stylesheets/kaui/datatable.less +19 -0
- data/app/assets/stylesheets/kaui/kaui.less +3 -1
- data/app/assets/stylesheets/kaui/subscription.less +15 -0
- data/app/assets/stylesheets/kaui/tags.less +30 -1
- data/app/controllers/kaui/account_custom_fields_controller.rb +24 -0
- data/app/controllers/kaui/account_tags_controller.rb +21 -0
- data/app/controllers/kaui/accounts_controller.rb +43 -16
- data/app/controllers/kaui/admin_tenants_controller.rb +152 -11
- data/app/controllers/kaui/audit_logs_controller.rb +93 -0
- data/app/controllers/kaui/bundles_controller.rb +15 -3
- data/app/controllers/kaui/custom_fields_controller.rb +2 -0
- data/app/controllers/kaui/engine_controller_util.rb +14 -0
- data/app/controllers/kaui/invoice_items_controller.rb +17 -0
- data/app/controllers/kaui/invoices_controller.rb +22 -5
- data/app/controllers/kaui/payment_methods_controller.rb +10 -9
- data/app/controllers/kaui/subscriptions_controller.rb +54 -7
- data/app/controllers/kaui/tag_definitions_controller.rb +1 -0
- data/app/helpers/kaui/account_helper.rb +28 -0
- data/app/helpers/kaui/object_helper.rb +4 -0
- data/app/helpers/kaui/permissions_helper.rb +15 -0
- data/app/helpers/kaui/plugin_helper.rb +58 -0
- data/app/helpers/kaui/subscription_helper.rb +9 -7
- data/app/models/kaui/admin_tenant.rb +20 -6
- data/app/models/kaui/catalog.rb +4 -4
- data/app/models/kaui/tag.rb +1 -1
- data/app/models/kaui/tag_definition.rb +1 -1
- data/app/views/kaui/account_custom_fields/index.html.erb +35 -0
- data/app/views/kaui/account_tags/index.html.erb +35 -0
- data/app/views/kaui/accounts/_account_info.html.erb +5 -0
- data/app/views/kaui/accounts/_billing_info.html.erb +1 -1
- data/app/views/kaui/accounts/_close_account_modal.html.erb +98 -0
- data/app/views/kaui/accounts/index.html.erb +0 -7
- data/app/views/kaui/accounts/show.html.erb +4 -0
- data/app/views/kaui/admin_tenants/_add_allowed_user_modal.html.erb +64 -0
- data/app/views/kaui/admin_tenants/_form_plugin_config.erb +257 -151
- data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +133 -48
- data/app/views/kaui/admin_tenants/_show_catalog_xml.erb +3 -2
- data/app/views/kaui/admin_tenants/show.html.erb +6 -1
- data/app/views/kaui/audit_logs/_show_history_modal.html.erb +177 -0
- data/app/views/kaui/audit_logs/index.html.erb +52 -0
- data/app/views/kaui/bundle_tags/_form_bar.html.erb +4 -2
- data/app/views/kaui/bundles/index.html.erb +21 -14
- data/app/views/kaui/chargebacks/_form.html.erb +1 -9
- data/app/views/kaui/charges/_form.html.erb +2 -10
- data/app/views/kaui/credits/_form.html.erb +1 -9
- data/app/views/kaui/custom_fields/_form.html.erb +1 -1
- data/app/views/kaui/custom_fields/_list_bar.html.erb +1 -1
- data/app/views/kaui/invoices/_invoice_table.html.erb +30 -2
- data/app/views/kaui/layouts/kaui_account_navbar.html.erb +7 -0
- data/app/views/kaui/layouts/kaui_flash.html.erb +13 -2
- data/app/views/kaui/payment_methods/_new_creditcard_payment_method.html.erb +11 -11
- data/app/views/kaui/payment_methods/_plugin_properties.html.erb +1 -1
- data/app/views/kaui/payments/_form.html.erb +1 -9
- data/app/views/kaui/refunds/_form.html.erb +4 -6
- data/app/views/kaui/subscriptions/_cancel_by_date_modal.html.erb +62 -0
- data/app/views/kaui/subscriptions/_form.html.erb +7 -13
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +50 -11
- data/app/views/kaui/subscriptions/new.html.erb +3 -1
- data/app/views/kaui/tag_definitions/_form.html.erb +139 -0
- data/app/views/kaui/tags/index.html.erb +1 -1
- data/app/views/kaui/transactions/_control_plugin_names.html.erb +1 -1
- data/config/routes.rb +18 -2
- data/db/migrate/20130812155313_devise_create_kaui_users.rb +9 -7
- data/db/migrate/20150109214021_create_kaui_tenants.rb +8 -6
- data/db/migrate/20150112232813_create_kaui_allowed_users.rb +15 -11
- data/lib/kaui/engine.rb +1 -0
- data/lib/kaui/version.rb +1 -1
- data/test/dummy/config/database.yml +6 -1
- data/test/fixtures/SpyCarAdvanced.xml +824 -0
- data/test/functional/kaui/account_children_controller_test.rb +1 -1
- data/test/functional/kaui/account_custom_fields_controller_test.rb +29 -0
- data/test/functional/kaui/account_tags_controller_test.rb +19 -0
- data/test/functional/kaui/accounts_controller_test.rb +23 -6
- data/test/functional/kaui/admin_controller_test.rb +2 -2
- data/test/functional/kaui/admin_tenants_controller_test.rb +76 -5
- data/test/functional/kaui/audit_logs_controller_test.rb +71 -0
- data/test/functional/kaui/bundles_controller_test.rb +2 -1
- data/test/functional/kaui/payments_controller_test.rb +1 -1
- data/test/functional/kaui/subscriptions_controller_test.rb +1 -2
- data/test/functional/kaui/tag_definitions_controller_test.rb +2 -1
- data/test/killbill_test_helper.rb +5 -2
- data/test/unit/kaui/admin_tenant_test.rb +100 -0
- data/test/unit/kaui/money_helper_test.rb +1 -1
- metadata +58 -13
- data/app/assets/javascripts/kaui/validation.js +0 -21
- data/test/dummy/log/test.log +0 -0
@@ -50,6 +50,10 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
50
50
|
tenant_model.save!
|
51
51
|
# Make sure at least the current user can access the tenant
|
52
52
|
tenant_model.kaui_allowed_users << Kaui::AllowedUser.where(:kb_username => current_user.kb_username).first_or_create
|
53
|
+
rescue KillBillClient::API::Conflict => e
|
54
|
+
# tenant api_key was found but has a wrong api_secret
|
55
|
+
flash[:error] = "Submitted credentials for #{param_tenant[:api_key]} did not match the expected credentials."
|
56
|
+
redirect_to admin_tenants_path and return
|
53
57
|
rescue => e
|
54
58
|
flash[:error] = "Failed to create the tenant: #{as_string(e)}"
|
55
59
|
redirect_to admin_tenants_path and return
|
@@ -73,18 +77,26 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
73
77
|
options[:api_key] = @tenant.api_key
|
74
78
|
options[:api_secret] = @tenant.api_secret
|
75
79
|
|
76
|
-
|
77
|
-
fetch_catalogs_xml = promise { Kaui::Catalog::get_catalog_xml(options) rescue @catalogs_xml = [] }
|
80
|
+
fetch_catalog_versions = promise { Kaui::Catalog::get_tenant_catalog_versions(options) rescue @catalog_versions = []}
|
78
81
|
fetch_overdue = promise { Kaui::Overdue::get_overdue_json(options) rescue @overdue = nil }
|
79
82
|
fetch_overdue_xml = promise { Kaui::Overdue::get_tenant_overdue_config('xml', options) rescue @overdue_xml = nil }
|
80
83
|
|
81
84
|
plugin_repository = Kaui::AdminTenant::get_plugin_repository
|
85
|
+
# hack:: replace paypal key with paypal_express, to set configuration and allow the ui to find the right configuration inputs
|
86
|
+
plugin_repository = plugin_repository.inject({}) { |p, (k,v)| p[k.to_s.sub(/\Apaypal/, 'paypal_express').to_sym] = v; p }
|
87
|
+
|
82
88
|
|
83
89
|
fetch_plugin_config = promise { Kaui::AdminTenant::get_oss_plugin_info(plugin_repository) }
|
84
90
|
fetch_tenant_plugin_config = promise { Kaui::AdminTenant::get_tenant_plugin_config(plugin_repository, options) }
|
85
91
|
|
86
|
-
@
|
87
|
-
|
92
|
+
@catalog_versions = []
|
93
|
+
wait(fetch_catalog_versions).each_with_index do |effective_date, idx|
|
94
|
+
@catalog_versions << {:version => idx,
|
95
|
+
:version_date => effective_date}
|
96
|
+
end
|
97
|
+
|
98
|
+
@latest_version = @catalog_versions[@catalog_versions.length - 1][:version_date] rescue nil
|
99
|
+
|
88
100
|
@overdue = wait(fetch_overdue)
|
89
101
|
@overdue_xml = wait(fetch_overdue_xml)
|
90
102
|
@plugin_config = wait(fetch_plugin_config) rescue ''
|
@@ -118,7 +130,7 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
118
130
|
options[:api_key] = @tenant.api_key
|
119
131
|
options[:api_secret] = @tenant.api_secret
|
120
132
|
|
121
|
-
latest_catalog = Kaui::Catalog::get_catalog_json(true, options)
|
133
|
+
latest_catalog = Kaui::Catalog::get_catalog_json(true, nil, options)
|
122
134
|
|
123
135
|
@ao_mapping = Kaui::Catalog::build_ao_mapping(latest_catalog)
|
124
136
|
|
@@ -163,7 +175,7 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
163
175
|
options[:api_key] = @tenant.api_key
|
164
176
|
options[:api_secret] = @tenant.api_secret
|
165
177
|
|
166
|
-
catalog = Kaui::Catalog::get_catalog_json(true, options)
|
178
|
+
catalog = Kaui::Catalog::get_catalog_json(true, nil, options)
|
167
179
|
|
168
180
|
# seek if plan id exists
|
169
181
|
catalog.products.each do |product|
|
@@ -300,11 +312,11 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
300
312
|
plugin_name = params[:plugin_name]
|
301
313
|
plugin_properties = params[:plugin_properties]
|
302
314
|
plugin_type = params[:plugin_type]
|
315
|
+
plugin_key = params[:plugin_key]
|
303
316
|
|
304
|
-
plugin_config = Kaui::AdminTenant.format_plugin_config(
|
317
|
+
plugin_config = Kaui::AdminTenant.format_plugin_config(plugin_key, plugin_type, plugin_properties)
|
305
318
|
|
306
|
-
|
307
|
-
Kaui::AdminTenant.upload_tenant_plugin_config(key, plugin_config, options[:username], nil, comment, options)
|
319
|
+
Kaui::AdminTenant.upload_tenant_plugin_config(plugin_name, plugin_config, options[:username], nil, comment, options)
|
308
320
|
|
309
321
|
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Config for plugin was successfully uploaded'
|
310
322
|
end
|
@@ -323,9 +335,53 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
323
335
|
render :json => '{}', :status => 200
|
324
336
|
end
|
325
337
|
|
338
|
+
def add_allowed_user
|
339
|
+
current_tenant = safely_find_tenant_by_id(params[:tenant_id])
|
340
|
+
allowed_user = Kaui::AllowedUser.find_by_kb_username(params.require(:allowed_user).require(:kb_username))
|
341
|
+
|
342
|
+
if !current_user.root?
|
343
|
+
flash[:error] = 'Only the root user can add users from tenants'
|
344
|
+
redirect_to admin_tenant_path(current_tenant.id)
|
345
|
+
return
|
346
|
+
end
|
347
|
+
|
348
|
+
if allowed_user.nil?
|
349
|
+
flash[:error] = "User #{params.require(:allowed_user).require(:kb_username)} does not exist!"
|
350
|
+
redirect_to admin_tenant_path(current_tenant.id)
|
351
|
+
return
|
352
|
+
end
|
353
|
+
|
354
|
+
tenants_ids = allowed_user.kaui_tenants.map(&:id) || []
|
355
|
+
tenants_ids << current_tenant.id
|
356
|
+
allowed_user.kaui_tenant_ids = tenants_ids
|
357
|
+
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Allowed user was successfully added'
|
358
|
+
end
|
359
|
+
|
360
|
+
def allowed_users
|
361
|
+
json_response do
|
362
|
+
tenant = safely_find_tenant_by_id(params[:tenant_id])
|
363
|
+
actual_allowed_users = tenant.kaui_allowed_users.map {|au| au.id}
|
364
|
+
|
365
|
+
retrieve_allowed_users_for_current_user.select {|au| !actual_allowed_users.include? au.id }
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
326
369
|
def display_catalog_xml
|
327
|
-
|
328
|
-
|
370
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
371
|
+
effective_date = params.require(:effective_date)
|
372
|
+
|
373
|
+
options = tenant_options_for_client
|
374
|
+
options[:api_key] = current_tenant.api_key
|
375
|
+
options[:api_secret] = current_tenant.api_secret
|
376
|
+
|
377
|
+
response = Kaui::Catalog.get_catalog_xml(effective_date, options) rescue response = {}
|
378
|
+
|
379
|
+
catalog_xml = {}
|
380
|
+
unless response.nil? && response.size > 0
|
381
|
+
catalog_xml = response[0][:xml]
|
382
|
+
end
|
383
|
+
|
384
|
+
render xml: catalog_xml
|
329
385
|
end
|
330
386
|
|
331
387
|
|
@@ -333,6 +389,56 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
333
389
|
render xml: params.require(:xml)
|
334
390
|
end
|
335
391
|
|
392
|
+
def catalog_by_effective_date
|
393
|
+
json_response do
|
394
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
395
|
+
effective_date = params.require(:effective_date)
|
396
|
+
|
397
|
+
options = tenant_options_for_client
|
398
|
+
options[:api_key] = current_tenant.api_key
|
399
|
+
options[:api_secret] = current_tenant.api_secret
|
400
|
+
|
401
|
+
catalog = []
|
402
|
+
result = Kaui::Catalog::get_catalog_json(false, effective_date, options) rescue catalog = []
|
403
|
+
|
404
|
+
# convert result to a full hash since dynamic attributes of a class are ignored when converting to json
|
405
|
+
result.each do |data|
|
406
|
+
plans = []
|
407
|
+
data[:plans].each do |plan|
|
408
|
+
plans << plan.instance_variables.each_with_object({}) {|var, hash_plan| hash_plan[var.to_s.delete("@")] = plan.instance_variable_get(var) }
|
409
|
+
end
|
410
|
+
|
411
|
+
catalog << {:version_date => data[:version_date],
|
412
|
+
:currencies => data[:currencies],
|
413
|
+
:plans => plans
|
414
|
+
}
|
415
|
+
end
|
416
|
+
|
417
|
+
{:catalog => catalog }
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
def suggest_plugin_name
|
422
|
+
json_response do
|
423
|
+
message = nil
|
424
|
+
entered_plugin_name = params.require(:plugin_name)
|
425
|
+
plugin_repository = view_context.plugin_repository
|
426
|
+
|
427
|
+
found_plugin, weights = fuzzy_match(entered_plugin_name, plugin_repository)
|
428
|
+
|
429
|
+
if weights.size > 0
|
430
|
+
plugin_anchor = view_context.link_to(weights[0][:plugin_name], '#', id: 'suggested',
|
431
|
+
data: {
|
432
|
+
plugin_name: weights[0][:plugin_name],
|
433
|
+
plugin_key: weights[0][:plugin_key],
|
434
|
+
plugin_type: weights[0][:plugin_type],
|
435
|
+
})
|
436
|
+
message = "Similar plugin already installed: '#{plugin_anchor}'" if weights[0][:worth_weight].to_f >= 1.0 && weights[0][:installed]
|
437
|
+
message = "Did you mean '#{plugin_anchor}'?" if weights[0][:worth_weight].to_f < 1.0 || !weights[0][:installed]
|
438
|
+
end
|
439
|
+
{ suggestion: message, plugin: found_plugin }
|
440
|
+
end
|
441
|
+
end
|
336
442
|
|
337
443
|
private
|
338
444
|
|
@@ -365,4 +471,39 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
365
471
|
end
|
366
472
|
end
|
367
473
|
|
474
|
+
def split_camel_dash_underscore_space(data)
|
475
|
+
data.split(/(?=[A-Z])|(?=[_])|(?=[-])|(?=[ ])/).select {|member| !member.gsub(/[_-]/,'').strip.empty?}.map { |member| member.gsub(/[_-]/,'').strip.downcase }
|
476
|
+
end
|
477
|
+
|
478
|
+
def fuzzy_match(entered_plugin_name, plugin_repository)
|
479
|
+
splitted_entered_plugin_name = split_camel_dash_underscore_space(entered_plugin_name)
|
480
|
+
worth_of_non_words = 0.5 / splitted_entered_plugin_name.size.to_i
|
481
|
+
|
482
|
+
weights = []
|
483
|
+
|
484
|
+
plugin_repository.each do |plugin|
|
485
|
+
return plugin, [] if plugin[:plugin_name] == entered_plugin_name || plugin[:plugin_key] == entered_plugin_name
|
486
|
+
|
487
|
+
splitted_plugin_name = split_camel_dash_underscore_space(plugin[:plugin_name])
|
488
|
+
weight = { :plugin_name => plugin[:plugin_name], :plugin_key => plugin[:plugin_key],
|
489
|
+
:plugin_type => plugin[:plugin_type], :installed => plugin[:installed], :worth_weight => 0.0 }
|
490
|
+
splitted_entered_plugin_name.each do |entered|
|
491
|
+
if splitted_plugin_name.include?(entered)
|
492
|
+
weight[:worth_weight] = weight[:worth_weight] + 1.0
|
493
|
+
end
|
494
|
+
|
495
|
+
splitted_plugin_name.each do |splitted|
|
496
|
+
if entered.chars.all? { |ch| splitted.include?(ch) }
|
497
|
+
weight[:worth_weight] = weight[:worth_weight] + worth_of_non_words
|
498
|
+
break
|
499
|
+
end
|
500
|
+
end
|
501
|
+
end
|
502
|
+
weights << weight if weight[:worth_weight] > 0
|
503
|
+
|
504
|
+
end
|
505
|
+
|
506
|
+
weights.sort! { |a,b| b[:worth_weight] <=> a[:worth_weight] } if weights.size > 1
|
507
|
+
return nil, weights
|
508
|
+
end
|
368
509
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
class Kaui::AuditLogsController < Kaui::EngineController
|
2
|
+
OBJECT_WITH_HISTORY = %w[ACCOUNT ACCOUNT_EMAIL CUSTOM_FIELD PAYMENT_ATTEMPT PAYMENT PAYMENT_METHOD TRANSACTION TAG TAG_DEFINITION]
|
3
|
+
|
4
|
+
def index
|
5
|
+
cached_options_for_klient = options_for_klient
|
6
|
+
@account = Kaui::Account::find_by_id_or_key(params.require(:account_id), false, false, cached_options_for_klient)
|
7
|
+
audit_logs = @account.audit(cached_options_for_klient)
|
8
|
+
|
9
|
+
|
10
|
+
formatter = lambda do |log|
|
11
|
+
object_id_text = view_context.content_tag(:span, view_context.truncate_uuid(log.object_id), title: log.object_id )
|
12
|
+
if object_with_history?(log.object_type)
|
13
|
+
object_id_text = view_context.link_to(object_id_text, '#showHistoryModal',
|
14
|
+
data: {
|
15
|
+
toggle: 'modal',
|
16
|
+
object_id: log.object_id,
|
17
|
+
object_type: log.object_type,
|
18
|
+
change_date: log.change_date,
|
19
|
+
change_type: log.change_type,
|
20
|
+
account_id: @account.account_id
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
[
|
25
|
+
log.change_date,
|
26
|
+
object_id_text,
|
27
|
+
log.object_type,
|
28
|
+
log.change_type,
|
29
|
+
log.changed_by,
|
30
|
+
log.reason_code,
|
31
|
+
log.comments,
|
32
|
+
view_context.content_tag(:span, view_context.truncate_uuid(log.user_token), title: log.user_token )
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
@audit_logs_json = []
|
37
|
+
audit_logs.each { |page| @audit_logs_json << formatter.call(page) }
|
38
|
+
|
39
|
+
@audit_logs_json = @audit_logs_json.to_json
|
40
|
+
end
|
41
|
+
|
42
|
+
def history
|
43
|
+
json_response do
|
44
|
+
account_id = params.require(:account_id)
|
45
|
+
object_id = params.require(:object_id)
|
46
|
+
object_type = params.require(:object_type)
|
47
|
+
cached_options_for_klient = options_for_klient
|
48
|
+
|
49
|
+
audit_logs_with_history = []
|
50
|
+
error = nil
|
51
|
+
|
52
|
+
begin
|
53
|
+
if object_type == 'ACCOUNT'
|
54
|
+
account = Kaui::Account::find_by_id_or_key(object_id, false, false, cached_options_for_klient)
|
55
|
+
audit_logs_with_history = account.audit_logs_with_history(cached_options_for_klient)
|
56
|
+
elsif object_type == 'ACCOUNT_EMAIL'
|
57
|
+
account = Kaui::Account::find_by_id_or_key(account_id, false, false, cached_options_for_klient)
|
58
|
+
audit_logs_with_history = account.email_audit_logs_with_history(object_id, cached_options_for_klient)
|
59
|
+
elsif object_type == 'CUSTOM_FIELD'
|
60
|
+
audit_logs_with_history = Kaui::CustomField.new({:custom_field_id => object_id}).audit_logs_with_history(cached_options_for_klient)
|
61
|
+
elsif object_type == 'PAYMENT_ATTEMPT'
|
62
|
+
audit_logs_with_history = Kaui::Payment::attempt_audit_logs_with_history(object_id, cached_options_for_klient)
|
63
|
+
elsif object_type == 'PAYMENT'
|
64
|
+
payment = Kaui::Payment::find_by_id(object_id, false, false, cached_options_for_klient)
|
65
|
+
audit_logs_with_history = payment.audit_logs_with_history(cached_options_for_klient)
|
66
|
+
elsif object_type == 'PAYMENT_METHOD'
|
67
|
+
payment_method = Kaui::PaymentMethod::find_by_id(object_id, false, cached_options_for_klient)
|
68
|
+
audit_logs_with_history = payment_method.audit_logs_with_history(cached_options_for_klient)
|
69
|
+
elsif object_type == 'TRANSACTION'
|
70
|
+
audit_logs_with_history = Kaui::Transaction::new({:transaction_id => object_id}).audit_logs_with_history(cached_options_for_klient)
|
71
|
+
elsif object_type == 'TAG'
|
72
|
+
audit_logs_with_history = Kaui::Tag.new({:tag_id => object_id}).audit_logs_with_history(cached_options_for_klient)
|
73
|
+
elsif object_type == 'TAG_DEFINITION'
|
74
|
+
audit_logs_with_history = Kaui::TagDefinition.new({:id => object_id}).audit_logs_with_history(cached_options_for_klient)
|
75
|
+
else
|
76
|
+
error = "Object [#{object_type}] history is not supported."
|
77
|
+
end
|
78
|
+
rescue Exception => e
|
79
|
+
error = e.message
|
80
|
+
end
|
81
|
+
|
82
|
+
{ audits: audit_logs_with_history, error: error }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def object_with_history?(object_type)
|
89
|
+
return false if object_type.nil?
|
90
|
+
OBJECT_WITH_HISTORY.include?(object_type)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -6,22 +6,34 @@ class Kaui::BundlesController < Kaui::EngineController
|
|
6
6
|
all_bundle_tags = @account.all_tags(:BUNDLE, false, 'NONE', options_for_klient)
|
7
7
|
all_bundle_tags.inject({}) {|hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh}
|
8
8
|
}
|
9
|
+
fetch_subscription_tags = promise {
|
10
|
+
all_subscription_tags = @account.all_tags(:SUBSCRIPTION, false, 'NONE', options_for_klient)
|
11
|
+
all_subscription_tags.inject({}) {|hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh}
|
12
|
+
}
|
9
13
|
fetch_bundle_fields = promise {
|
10
14
|
all_bundle_fields = @account.all_custom_fields(:BUNDLE, 'NONE', options_for_klient)
|
11
15
|
all_bundle_fields.inject({}) {|hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh}
|
12
16
|
}
|
17
|
+
fetch_subscription_fields = promise {
|
18
|
+
all_subscription_fields = @account.all_custom_fields(:SUBSCRIPTION, 'NONE', options_for_klient)
|
19
|
+
all_subscription_fields.inject({}) {|hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh}
|
20
|
+
}
|
13
21
|
fetch_available_tags = promise { Kaui::TagDefinition.all_for_bundle(options_for_klient) }
|
22
|
+
fetch_available_subscription_tags = promise { Kaui::TagDefinition.all_for_subscription(options_for_klient) }
|
14
23
|
|
15
24
|
@bundles = wait(fetch_bundles)
|
16
25
|
@tags_per_bundle = wait(fetch_bundle_tags)
|
26
|
+
@tags_per_subscription = wait(fetch_subscription_tags)
|
17
27
|
@custom_fields_per_bundle = wait(fetch_bundle_fields)
|
28
|
+
@custom_fields_per_subscription = wait(fetch_subscription_fields)
|
18
29
|
@available_tags = wait(fetch_available_tags)
|
30
|
+
@available_subscription_tags = wait(fetch_available_subscription_tags)
|
19
31
|
|
20
|
-
@
|
32
|
+
@subscription = {}
|
21
33
|
@bundles.each do |bundle|
|
22
34
|
bundle.subscriptions.each do |sub|
|
23
|
-
next
|
24
|
-
@
|
35
|
+
next if sub.product_category == 'ADD_ON'
|
36
|
+
@subscription[bundle.bundle_id] = sub
|
25
37
|
break
|
26
38
|
end
|
27
39
|
end
|
@@ -55,6 +55,8 @@ class Kaui::CustomFieldsController < Kaui::EngineController
|
|
55
55
|
Kaui::Invoice.new(:invoice_id => @custom_field.object_id)
|
56
56
|
when :PAYMENT
|
57
57
|
Kaui::Payment.new(:payment_id => @custom_field.object_id)
|
58
|
+
when :INVOICE_ITEM
|
59
|
+
Kaui::InvoiceItem.new(:invoice_item_id => @custom_field.object_id)
|
58
60
|
else
|
59
61
|
flash.now[:error] = "Invalid object type #{@custom_field.object_type}"
|
60
62
|
render :new and return
|
@@ -119,4 +119,18 @@ module Kaui::EngineControllerUtil
|
|
119
119
|
nil
|
120
120
|
end
|
121
121
|
end
|
122
|
+
|
123
|
+
def json_response
|
124
|
+
begin
|
125
|
+
response = yield
|
126
|
+
response_status = 200
|
127
|
+
rescue KillBillClient::API::ResponseError => e
|
128
|
+
response = e.response.message
|
129
|
+
response_status = e.code
|
130
|
+
rescue Exception => e
|
131
|
+
response = e.message
|
132
|
+
response_status = 500
|
133
|
+
end
|
134
|
+
render :json => response, :status => response_status
|
135
|
+
end
|
122
136
|
end
|
@@ -34,4 +34,21 @@ class Kaui::InvoiceItemsController < Kaui::EngineController
|
|
34
34
|
invoice_item.delete(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
35
35
|
redirect_to kaui_engine.account_invoice_path(invoice_item.account_id, invoice_item.invoice_id), :notice => 'CBA item was successfully deleted'
|
36
36
|
end
|
37
|
+
|
38
|
+
def update_tags
|
39
|
+
@invoice_item = Kaui::InvoiceItem.new(:invoice_item_id => params.require(:id))
|
40
|
+
invoice_id = params.require(:invoice_id)
|
41
|
+
account_id = params.require(:account_id)
|
42
|
+
@invoice_item.account_id = account_id
|
43
|
+
|
44
|
+
tags = []
|
45
|
+
params.each do |tag|
|
46
|
+
tag_info = tag.split('_')
|
47
|
+
next if tag_info.size != 2 or tag_info[0] != 'tag'
|
48
|
+
tags << tag_info[1]
|
49
|
+
end
|
50
|
+
|
51
|
+
@invoice_item.set_tags(tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
52
|
+
redirect_to account_invoice_path(account_id, invoice_id), :notice => 'Invoice Item tags successfully set'
|
53
|
+
end
|
37
54
|
end
|
@@ -42,20 +42,37 @@ class Kaui::InvoicesController < Kaui::EngineController
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def show
|
45
|
-
|
45
|
+
# Go to the database once
|
46
|
+
cached_options_for_klient = options_for_klient
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
@invoice = Kaui::Invoice.find_by_id_or_number(params.require(:id), true, 'FULL', cached_options_for_klient)
|
49
|
+
|
50
|
+
fetch_payments = promise { @invoice.payments(true, true, 'FULL', cached_options_for_klient).map { |payment| Kaui::InvoicePayment.build_from_raw_payment(payment) } }
|
51
|
+
fetch_pms = fetch_payments.then { |payments| Kaui::PaymentMethod.payment_methods_for_payments(payments, cached_options_for_klient) }
|
52
|
+
fetch_invoice_fields = promise { @invoice.custom_fields('NONE', cached_options_for_klient).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase } }
|
50
53
|
fetch_payment_fields = promise {
|
51
|
-
all_payment_fields = @account.all_custom_fields(:PAYMENT, 'NONE',
|
54
|
+
all_payment_fields = @account.all_custom_fields(:PAYMENT, 'NONE', cached_options_for_klient)
|
52
55
|
all_payment_fields.inject({}) { |hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh }
|
53
56
|
}
|
54
57
|
|
58
|
+
fetch_available_invoice_item_tags = promise { Kaui::TagDefinition.all_for_invoice_item(cached_options_for_klient) }
|
59
|
+
fetch_tags_per_invoice_item = promise {
|
60
|
+
tags_per_invoice_item = @account.all_tags(:INVOICE_ITEM, false, 'NONE', cached_options_for_klient)
|
61
|
+
tags_per_invoice_item.inject({}) {|hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh}
|
62
|
+
}
|
63
|
+
|
64
|
+
fetch_custom_fields_per_invoice_item = promise {
|
65
|
+
custom_fields_per_invoice_item = @account.all_custom_fields(:INVOICE_ITEM, 'NONE', cached_options_for_klient)
|
66
|
+
custom_fields_per_invoice_item.inject({}) { |hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh }
|
67
|
+
}
|
68
|
+
|
55
69
|
@payments = wait(fetch_payments)
|
56
70
|
@payment_methods = wait(fetch_pms)
|
57
71
|
@custom_fields = wait(fetch_invoice_fields)
|
58
72
|
@payment_custom_fields = wait(fetch_payment_fields)
|
73
|
+
@custom_fields_per_invoice_item = wait(fetch_custom_fields_per_invoice_item)
|
74
|
+
@tags_per_invoice_item = wait(fetch_tags_per_invoice_item)
|
75
|
+
@available_invoice_item_tags = wait(fetch_available_invoice_item_tags)
|
59
76
|
end
|
60
77
|
|
61
78
|
def restful_show
|
@@ -44,7 +44,7 @@ class Kaui::PaymentMethodsController < Kaui::EngineController
|
|
44
44
|
'state' => @state
|
45
45
|
}
|
46
46
|
|
47
|
-
@plugin_properties = params[:plugin_properties].values.select{ |item| !(item['value'].blank? || item['key'].blank?) }
|
47
|
+
@plugin_properties = params[:plugin_properties].values.select{ |item| !(item['value'].blank? || item['key'].blank?) } rescue @plugin_properties = nil
|
48
48
|
@plugin_properties.map! do |property|
|
49
49
|
KillBillClient::Model::PluginPropertyAttributes.new(property)
|
50
50
|
end unless @plugin_properties.blank?
|
@@ -82,16 +82,17 @@ class Kaui::PaymentMethodsController < Kaui::EngineController
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def validate_external_key
|
85
|
-
|
85
|
+
json_response do
|
86
|
+
external_key = params.require(:external_key)
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
render json: {:is_found => !payment_methods.nil?}
|
88
|
+
begin
|
89
|
+
payment_methods = Kaui::PaymentMethod::find_by_external_key(external_key,false,false,'NONE', options_for_klient)
|
90
|
+
rescue KillBillClient::API::NotFound
|
91
|
+
payment_methods = nil
|
92
|
+
end
|
94
93
|
|
94
|
+
{ :is_found => !payment_methods.nil? }
|
95
|
+
end
|
95
96
|
end
|
96
97
|
|
97
98
|
private
|
@@ -32,6 +32,9 @@ class Kaui::SubscriptionsController < Kaui::EngineController
|
|
32
32
|
|
33
33
|
@subscription.plan_name = plan_name
|
34
34
|
requested_date = params[:type_change] == "DATE" ? params[:requested_date].presence : nil
|
35
|
+
|
36
|
+
# un-set product_category since is not needed if plan name exist
|
37
|
+
@subscription.product_category = nil
|
35
38
|
@subscription = @subscription.create(current_user.kb_username, params[:reason], params[:comment], requested_date, false, options_for_klient)
|
36
39
|
redirect_to kaui_engine.account_bundles_path(@subscription.account_id), :notice => 'Subscription was successfully created'
|
37
40
|
rescue => e
|
@@ -126,16 +129,32 @@ class Kaui::SubscriptionsController < Kaui::EngineController
|
|
126
129
|
end
|
127
130
|
|
128
131
|
def validate_external_key
|
129
|
-
|
132
|
+
json_response do
|
133
|
+
external_key = params.require(:external_key)
|
130
134
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
+
begin
|
136
|
+
bundle = Kaui::Bundle.find_by_external_key(external_key, false, options_for_klient)
|
137
|
+
rescue KillBillClient::API::NotFound
|
138
|
+
bundle = nil
|
139
|
+
end
|
140
|
+
|
141
|
+
{ :is_found => !bundle.nil? }
|
135
142
|
end
|
143
|
+
end
|
136
144
|
|
137
|
-
|
145
|
+
def update_tags
|
146
|
+
subscription_id = params.require(:id)
|
147
|
+
subscription = Kaui::Subscription.find_by_id(subscription_id, options_for_klient)
|
138
148
|
|
149
|
+
tags = []
|
150
|
+
params.each do |tag|
|
151
|
+
tag_info = tag.split('_')
|
152
|
+
next if tag_info.size != 2 or tag_info[0] != 'tag'
|
153
|
+
tags << tag_info[1]
|
154
|
+
end
|
155
|
+
|
156
|
+
Kaui::Tag.set_for_subscription(subscription_id, tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
157
|
+
redirect_to kaui_engine.account_bundles_path(subscription.account_id), :notice => 'Subscription tags successfully set'
|
139
158
|
end
|
140
159
|
|
141
160
|
private
|
@@ -154,8 +173,36 @@ class Kaui::SubscriptionsController < Kaui::EngineController
|
|
154
173
|
plans_details = Kaui::Catalog.available_addons(base_product_name, options_for_klient)
|
155
174
|
else
|
156
175
|
bundle = nil
|
157
|
-
plans_details =
|
176
|
+
plans_details = catalog_plans(subscription.product_category == 'BASE' ? nil : subscription.product_category)
|
158
177
|
end
|
159
178
|
[bundle, plans_details]
|
160
179
|
end
|
180
|
+
|
181
|
+
def catalog_plans(product_category = nil)
|
182
|
+
if product_category == 'BASE'
|
183
|
+
return Kaui::Catalog.available_base_plans(options_for_klient)
|
184
|
+
else
|
185
|
+
options = options_for_klient
|
186
|
+
|
187
|
+
catalog = Kaui::Catalog.get_tenant_catalog('json', DateTime.now.to_s, options)
|
188
|
+
|
189
|
+
return [] if catalog.blank?
|
190
|
+
|
191
|
+
plans = []
|
192
|
+
catalog[catalog.size - 1].products.each do |product|
|
193
|
+
next if product.type == 'ADD_ON' || (!product_category.nil? && product.type != product_category)
|
194
|
+
product.plans.each do |plan|
|
195
|
+
class << plan
|
196
|
+
attr_accessor :plan
|
197
|
+
end
|
198
|
+
plan.plan = plan.name
|
199
|
+
|
200
|
+
plans << plan
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
return plans
|
205
|
+
|
206
|
+
end
|
207
|
+
end
|
161
208
|
end
|
@@ -14,6 +14,7 @@ class Kaui::TagDefinitionsController < Kaui::EngineController
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def create
|
17
|
+
params[:tag_definition][:applicable_object_types] = params[:tag_definition][:applicable_object_types].values unless params[:tag_definition][:applicable_object_types].blank?
|
17
18
|
@tag_definition = Kaui::TagDefinition.new(params[:tag_definition])
|
18
19
|
|
19
20
|
begin
|
@@ -12,5 +12,33 @@ module Kaui
|
|
12
12
|
return false
|
13
13
|
end
|
14
14
|
|
15
|
+
def account_closed?
|
16
|
+
return false if @account.nil?
|
17
|
+
blocking_states = @account.blocking_states('ACCOUNT','account-service','NONE', Kaui.current_tenant_user_options(current_user, session))
|
18
|
+
|
19
|
+
is_account_closed = false
|
20
|
+
blocking_states.each do |blocking_state|
|
21
|
+
if blocking_state.state_name.eql?('CLOSE_ACCOUNT')
|
22
|
+
is_account_closed = true
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
is_account_closed
|
27
|
+
end
|
28
|
+
|
29
|
+
def billing_info_margin
|
30
|
+
style = ''
|
31
|
+
unless can?(:trigger, Kaui::Payment) && can?(:credit, Kaui::Account) && can?(:charge, Kaui::Account)
|
32
|
+
style = "#{style}margin-top:15px;"
|
33
|
+
end
|
34
|
+
|
35
|
+
unless can? :trigger, Kaui::Invoice
|
36
|
+
style = "#{style}margin-bottom:15px;"
|
37
|
+
end
|
38
|
+
|
39
|
+
style = "style='#{style}'" unless style.empty?
|
40
|
+
style
|
41
|
+
end
|
42
|
+
|
15
43
|
end
|
16
44
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Kaui
|
2
|
+
module PermissionsHelper
|
3
|
+
|
4
|
+
def can_close_account?
|
5
|
+
isAuthorizedWhen = true
|
6
|
+
isAuthorizedWhen &= can? :cancel, Kaui::Subscription
|
7
|
+
isAuthorizedWhen &= can? :pause_resume, Kaui::Subscription
|
8
|
+
isAuthorizedWhen &= can? :add, Kaui::Tag
|
9
|
+
isAuthorizedWhen &= can? :item_adjust, Kaui::Invoice
|
10
|
+
|
11
|
+
isAuthorizedWhen
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|