kaui 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/kaui/admin_tenants_controller.rb +4 -78
- data/app/helpers/kaui/payment_method_helper.rb +5 -3
- data/app/helpers/kaui/plugin_helper.rb +9 -48
- data/app/models/kaui/admin_tenant.rb +8 -84
- data/app/views/kaui/admin_tenants/_form_plugin_config.erb +48 -240
- data/app/views/kaui/payments/_payment_table.html.erb +2 -2
- data/config/routes.rb +0 -1
- data/lib/kaui/version.rb +1 -1
- data/test/functional/kaui/admin_tenants_controller_test.rb +2 -22
- data/test/functional/kaui/credits_controller_test.rb +3 -3
- data/test/functional/kaui/home_controller_test.rb +5 -5
- data/test/functional/kaui/subscriptions_controller_test.rb +1 -1
- data/test/killbill_test_helper.rb +6 -6
- data/test/unit/helpers/kaui/payment_method_helper_test.rb +17 -0
- data/test/unit/kaui/admin_tenant_test.rb +10 -47
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 435f5a3c43e225e631222f6342c14a00732cda14be90c36ea499a21a89d4f0dc
|
4
|
+
data.tar.gz: 733ba6cb910b17aaae7764811f1a2861ac0a6e4521fc856e777dcc055fba6e21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2db883f170a25e9996a7d2378aefe648b1807c2799a88e0bdbc2b5d495f4f926030ffdce7c414c6725ca7c9e0e54d0fb8ad981f3cedd90ec06bc532abd0ce346
|
7
|
+
data.tar.gz: 957b7d9f5e0b90d147ed20b6c14907402a30ef4f1bd29acb0d1a70016d0773212b375ef9d81aa7c56af2005ab45e777923a7689f3d53da697e1b4e3b7f2e8db8
|
@@ -81,12 +81,7 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
81
81
|
fetch_overdue = promise { Kaui::Overdue::get_overdue_json(options) rescue @overdue = nil }
|
82
82
|
fetch_overdue_xml = promise { Kaui::Overdue::get_tenant_overdue_config('xml', options) rescue @overdue_xml = nil }
|
83
83
|
|
84
|
-
|
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
|
-
|
88
|
-
fetch_plugin_config = promise { Kaui::AdminTenant::get_oss_plugin_info(plugin_repository) }
|
89
|
-
fetch_tenant_plugin_config = promise { Kaui::AdminTenant::get_tenant_plugin_config(plugin_repository, options) }
|
84
|
+
fetch_tenant_plugin_config = promise { Kaui::AdminTenant::get_tenant_plugin_config(options) }
|
90
85
|
|
91
86
|
@catalog_versions = []
|
92
87
|
wait(fetch_catalog_versions).each_with_index do |effective_date, idx|
|
@@ -98,7 +93,6 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
98
93
|
|
99
94
|
@overdue = wait(fetch_overdue)
|
100
95
|
@overdue_xml = wait(fetch_overdue_xml)
|
101
|
-
@plugin_config = wait(fetch_plugin_config) rescue ''
|
102
96
|
@tenant_plugin_config = wait(fetch_tenant_plugin_config) rescue ''
|
103
97
|
|
104
98
|
# When reloading page from the view, it sends the last tab that was active
|
@@ -307,6 +301,8 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
307
301
|
|
308
302
|
if plugin_properties.blank?
|
309
303
|
flash[:error] = 'Plugin properties cannot be blank'
|
304
|
+
elsif plugin_name.blank?
|
305
|
+
flash[:error] = 'Plugin name cannot be blank'
|
310
306
|
else
|
311
307
|
plugin_config = Kaui::AdminTenant.format_plugin_config(plugin_key, plugin_type, plugin_properties)
|
312
308
|
|
@@ -314,7 +310,7 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
314
310
|
flash[:notice] = 'Config for plugin was successfully uploaded'
|
315
311
|
end
|
316
312
|
|
317
|
-
redirect_to admin_tenant_path(current_tenant.id)
|
313
|
+
redirect_to admin_tenant_path(current_tenant.id, :active_tab => 'PluginConfig')
|
318
314
|
end
|
319
315
|
|
320
316
|
def remove_allowed_user
|
@@ -406,28 +402,6 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
406
402
|
end
|
407
403
|
end
|
408
404
|
|
409
|
-
def suggest_plugin_name
|
410
|
-
json_response do
|
411
|
-
message = nil
|
412
|
-
entered_plugin_name = params.require(:plugin_name)
|
413
|
-
plugin_repository = view_context.plugin_repository
|
414
|
-
|
415
|
-
found_plugin, weights = fuzzy_match(entered_plugin_name, plugin_repository)
|
416
|
-
|
417
|
-
if weights.size > 0
|
418
|
-
plugin_anchor = view_context.link_to(weights[0][:plugin_name], '#', id: 'suggested',
|
419
|
-
data: {
|
420
|
-
plugin_name: weights[0][:plugin_name],
|
421
|
-
plugin_key: weights[0][:plugin_key],
|
422
|
-
plugin_type: weights[0][:plugin_type],
|
423
|
-
})
|
424
|
-
message = "Similar plugin already installed: '#{plugin_anchor}'" if weights[0][:worth_weight].to_f >= 1.0 && weights[0][:installed]
|
425
|
-
message = "Did you mean '#{plugin_anchor}'?" if weights[0][:worth_weight].to_f < 1.0 || !weights[0][:installed]
|
426
|
-
end
|
427
|
-
{ suggestion: message, plugin: found_plugin }
|
428
|
-
end
|
429
|
-
end
|
430
|
-
|
431
405
|
def switch_tenant
|
432
406
|
tenant = Kaui::Tenant.find_by_kb_tenant_id(params.require(:kb_tenant_id))
|
433
407
|
|
@@ -473,54 +447,6 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
473
447
|
data.to_s.split(/(?=[A-Z])|(?=[_])|(?=[-])|(?=[ ])/).select {|member| !member.gsub(/[_-]/,'').strip.empty?}.map { |member| member.gsub(/[_-]/,'').strip.downcase }
|
474
448
|
end
|
475
449
|
|
476
|
-
def fuzzy_match(entered_plugin_name, plugin_repository)
|
477
|
-
splitted_entered_plugin_name = split_camel_dash_underscore_space(entered_plugin_name)
|
478
|
-
worth_of_non_words = 0.5 / splitted_entered_plugin_name.size.to_i
|
479
|
-
|
480
|
-
weights = []
|
481
|
-
|
482
|
-
plugin_repository.each do |plugin|
|
483
|
-
return plugin, [] if plugin[:plugin_name] == entered_plugin_name || plugin[:plugin_key] == entered_plugin_name
|
484
|
-
weight = { :plugin_name => plugin[:plugin_name], :plugin_key => plugin[:plugin_key],
|
485
|
-
:plugin_type => plugin[:plugin_type], :installed => plugin[:installed], :worth_weight => 0.0 }
|
486
|
-
|
487
|
-
splitted_plugin_name = split_camel_dash_underscore_space(plugin[:plugin_name])
|
488
|
-
splitted_entered_plugin_name.each do |entered|
|
489
|
-
if splitted_plugin_name.include?(entered)
|
490
|
-
weight[:worth_weight] = weight[:worth_weight] + 1.0
|
491
|
-
end
|
492
|
-
|
493
|
-
splitted_plugin_name.each do |splitted|
|
494
|
-
if entered.chars.all? { |ch| splitted.include?(ch) }
|
495
|
-
weight[:worth_weight] = weight[:worth_weight] + worth_of_non_words
|
496
|
-
break
|
497
|
-
end
|
498
|
-
end
|
499
|
-
|
500
|
-
# perform a plugin key search, if weight is zero
|
501
|
-
next unless weight[:worth_weight] == 0
|
502
|
-
splitted_plugin_key = split_camel_dash_underscore_space(plugin[:plugin_key])
|
503
|
-
|
504
|
-
if splitted_plugin_key.include?(entered)
|
505
|
-
weight[:worth_weight] = weight[:worth_weight] + 1.0
|
506
|
-
end
|
507
|
-
|
508
|
-
splitted_plugin_key.each do |splitted|
|
509
|
-
if entered.chars.all? { |ch| splitted.include?(ch) }
|
510
|
-
weight[:worth_weight] = weight[:worth_weight] + worth_of_non_words
|
511
|
-
break
|
512
|
-
end
|
513
|
-
end
|
514
|
-
end
|
515
|
-
|
516
|
-
weights << weight if weight[:worth_weight] > 0
|
517
|
-
|
518
|
-
end
|
519
|
-
|
520
|
-
weights.sort! { |a,b| b[:worth_weight] <=> a[:worth_weight] } if weights.size > 1
|
521
|
-
return nil, weights
|
522
|
-
end
|
523
|
-
|
524
450
|
def fetch_catalog_xml(tenant_id, effective_date)
|
525
451
|
current_tenant = safely_find_tenant_by_id(tenant_id)
|
526
452
|
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module Kaui
|
2
2
|
module PaymentMethodHelper
|
3
3
|
|
4
|
-
def is_json?(
|
5
|
-
|
4
|
+
def is_json?(value)
|
5
|
+
result = JSON.parse(value)
|
6
|
+
result.is_a?(Hash) || result.is_a?(Array)
|
7
|
+
rescue JSON::ParserError, TypeError
|
8
|
+
false
|
6
9
|
end
|
7
|
-
|
8
10
|
end
|
9
11
|
end
|
@@ -1,46 +1,13 @@
|
|
1
1
|
module Kaui
|
2
2
|
module PluginHelper
|
3
|
-
# including plugin that are installed
|
4
|
-
def plugin_repository
|
5
|
-
plugins = []
|
6
|
-
plugin_repository = Kaui::AdminTenant.get_plugin_repository
|
7
|
-
plugin_repository.each_pair do |key, info|
|
8
|
-
plugins << {
|
9
|
-
plugin_key: plugin_key(key.to_s, info),
|
10
|
-
plugin_name: plugin_name(key.to_s, info),
|
11
|
-
plugin_type: info[:type],
|
12
|
-
installed: false
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
installed_plugins = installed_plugins(plugins)
|
17
|
-
|
18
|
-
plugins.sort! { |a, b| a[:plugin_key] <=> b[:plugin_key] }
|
19
|
-
plugins.each { |plugin| installed_plugins << plugin }
|
20
3
|
|
4
|
+
def plugin_repository
|
21
5
|
installed_plugins
|
22
6
|
end
|
23
7
|
|
24
8
|
private
|
25
9
|
|
26
|
-
def
|
27
|
-
if info[:artifact_id].nil?
|
28
|
-
"killbill-#{key}"
|
29
|
-
else
|
30
|
-
"killbill-#{info[:artifact_id].gsub('killbill-','').gsub('-plugin','')}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def plugin_key(key, info)
|
35
|
-
# hack:: replace paypal key with paypal_express, to set configuration and allow the ui to find the right configuration inputs
|
36
|
-
if key.eql?('paypal')
|
37
|
-
'paypal_express'
|
38
|
-
else
|
39
|
-
"#{key}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def installed_plugins(plugins)
|
10
|
+
def installed_plugins
|
44
11
|
installed_plugins = []
|
45
12
|
nodes_info = KillBillClient::Model::NodesInfo.nodes_info(Kaui.current_tenant_user_options(current_user, session)) || []
|
46
13
|
plugins_info = nodes_info.first.plugins_info || []
|
@@ -49,11 +16,15 @@ module Kaui
|
|
49
16
|
next if plugin.version.nil?
|
50
17
|
# do not allow duplicate
|
51
18
|
next if installed_plugins.any? { |p| p[:plugin_name].eql?(plugin.plugin_name) }
|
52
|
-
plugin_key =
|
19
|
+
plugin_key = plugin.plugin_key
|
53
20
|
installed_plugins << {
|
21
|
+
# Unique identifier chosen by the user and used for kpm operations
|
54
22
|
plugin_key: plugin_key,
|
55
|
-
|
56
|
-
|
23
|
+
# Notes:
|
24
|
+
# * plugin.plugin_name comes from kpm and is arbitrary (see Utils.get_plugin_name_from_file_path in the kpm codebase for instance)
|
25
|
+
# * plugin_name here is the plugin name as seen by Kill Bill and is typically defined in the Activator.java (this value is the one that matters for plugin configuration)
|
26
|
+
# * The mapping here is a convention we've used over the years and is no way enforced anywhere - it likely won't work for proprietary plugins (the user would need to specify it by toggling the input on the UI)
|
27
|
+
plugin_name: "killbill-#{plugin_key}",
|
57
28
|
installed: true
|
58
29
|
}
|
59
30
|
end
|
@@ -61,15 +32,5 @@ module Kaui
|
|
61
32
|
# to_s to handle nil
|
62
33
|
installed_plugins.sort! { |a,b| a[:plugin_key].to_s <=> b[:plugin_key].to_s }
|
63
34
|
end
|
64
|
-
|
65
|
-
def find_plugin_type(plugins, plugin_key_to_search)
|
66
|
-
plugins.each do |plugin|
|
67
|
-
if plugin[:plugin_key] == plugin_key_to_search
|
68
|
-
return plugin[:plugin_type]
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
return nil
|
73
|
-
end
|
74
35
|
end
|
75
36
|
end
|
@@ -26,81 +26,21 @@ class Kaui::AdminTenant < KillBillClient::Model::Tenant
|
|
26
26
|
KillBillClient::Model::Tenant.upload_tenant_plugin_config(plugin_name, plugin_config, user, reason, comment, options)
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
require 'yaml'
|
32
|
-
|
33
|
-
source = URI.parse('https://raw.githubusercontent.com/killbill/killbill-cloud/master/kpm/lib/kpm/plugins_directory.yml').read
|
34
|
-
YAML.load(source)
|
35
|
-
rescue
|
36
|
-
# Ignore gracefully
|
37
|
-
{}
|
38
|
-
end
|
39
|
-
|
40
|
-
def get_oss_plugin_info(plugin_directory)
|
41
|
-
# Serialize the plugin state for the view:
|
42
|
-
# plugin_name#plugin_type:prop1,prop2,prop3;plugin_name#plugin_type:prop1,prop2,prop3;...
|
43
|
-
#
|
44
|
-
plugin_config = plugin_directory.inject({}) do |hsh, (k,v)|
|
45
|
-
hsh["#{k}##{v[:type]}"] = v[:require] || []
|
46
|
-
hsh
|
47
|
-
end
|
48
|
-
plugin_config.map { |e,v| "#{e}:#{v.join(",")}" }.join(";")
|
49
|
-
end
|
50
|
-
|
51
|
-
def get_tenant_plugin_config(plugin_directory, options)
|
52
|
-
require 'yaml'
|
53
|
-
|
29
|
+
# Return a map of plugin_name => config
|
30
|
+
def get_tenant_plugin_config(options)
|
54
31
|
raw_tenant_config = KillBillClient::Model::Tenant::search_tenant_config("PLUGIN_CONFIG_", options)
|
55
32
|
|
56
33
|
tenant_config = raw_tenant_config.inject({}) do |hsh, e|
|
57
34
|
# Strip prefix '/PLUGIN_CONFIG_'
|
58
|
-
|
59
|
-
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
# hack:: rewrite key, to allow the ui to find the right configuration inputs
|
64
|
-
plugin_key = rewrite_plugin_key(plugin_key) unless plugin_key.nil?
|
65
|
-
# If such key exists, lookup in plugin directory to see if is an official plugin
|
66
|
-
is_an_official_plugin = !plugin_key.nil? && !plugin_directory[plugin_key.to_sym].blank?
|
67
|
-
# Deserialize config based on string possible format, if exist in the official repository
|
68
|
-
if is_an_official_plugin && is_yaml?(e.values[0])
|
69
|
-
yml = YAML.load(e.values[0])
|
70
|
-
# Hash of properties
|
71
|
-
# is plugin key part of the yaml?
|
72
|
-
if yml[plugin_key.to_sym].blank?
|
73
|
-
# if not set it as raw
|
74
|
-
hsh[plugin_key] = {:raw_config => e.values[0]}
|
75
|
-
else
|
76
|
-
hsh[plugin_key] = yml[plugin_key.to_sym]
|
77
|
-
end
|
78
|
-
hsh[plugin_key][:_raw] = e.values[0]
|
79
|
-
elsif is_an_official_plugin && is_kv?(e.values[0])
|
80
|
-
# Construct hash of properties based on java properties (k1=v1\nk2=v2\n...)
|
81
|
-
hsh[plugin_key] = e.values[0].split("\n").inject({}) do |h, p0|
|
82
|
-
k, v = p0.split('=');
|
83
|
-
h[k] = v;
|
84
|
-
h
|
85
|
-
end
|
86
|
-
hsh[plugin_key][:_raw] = e.values[0]
|
87
|
-
else
|
88
|
-
# Construct simple hash with one property :raw_config
|
89
|
-
hsh[killbill_key] = {:raw_config => e.values[0], :_raw => e.values[0]}
|
90
|
-
end
|
35
|
+
plugin_name = e.key.gsub!(/PLUGIN_CONFIG_/, '')
|
36
|
+
|
37
|
+
# Construct simple hash with one property (first value)
|
38
|
+
hsh[plugin_name] = e.values[0]
|
39
|
+
|
91
40
|
hsh
|
92
41
|
end
|
93
42
|
|
94
|
-
|
95
|
-
# plugin_key1::key1=value1|key2=value2|..;plugin_key2::...
|
96
|
-
tenant_config.map do |plugin_key, props|
|
97
|
-
serialized_props = props.inject("") do |s, (k, v)|
|
98
|
-
e="#{k.to_s}=#{v.to_s}";
|
99
|
-
s == "" ? s="#{e}" : s="#{s}|#{e}";
|
100
|
-
s
|
101
|
-
end
|
102
|
-
"#{plugin_key}::#{serialized_props}"
|
103
|
-
end.join(";")
|
43
|
+
tenant_config
|
104
44
|
end
|
105
45
|
|
106
46
|
def format_plugin_config(plugin_key, plugin_type, props)
|
@@ -142,22 +82,6 @@ class Kaui::AdminTenant < KillBillClient::Model::Tenant
|
|
142
82
|
props
|
143
83
|
end
|
144
84
|
|
145
|
-
# hack when the plugin name after killbill is not the same as the plugin key, this mainly affects ruby plugin configuration,
|
146
|
-
# as it use the key to retrieve the configuration.
|
147
|
-
def rewrite_plugin_key(plugin_key)
|
148
|
-
if plugin_key.start_with?('paypal')
|
149
|
-
'paypal_express'
|
150
|
-
elsif plugin_key.start_with?('firstdata')
|
151
|
-
'firstdata_e4'
|
152
|
-
elsif plugin_key.start_with?('bridge')
|
153
|
-
'payment_bridge'
|
154
|
-
elsif plugin_key.start_with?('payu-latam')
|
155
|
-
'payu_latam'
|
156
|
-
else
|
157
|
-
"#{plugin_key}"
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
85
|
# checks if string could be parse as yaml
|
162
86
|
def is_yaml?(candidate_string)
|
163
87
|
is_yaml = false
|
@@ -17,9 +17,10 @@
|
|
17
17
|
|
18
18
|
<div id="plugin" class="form-group">
|
19
19
|
<%= label_tag :entered_plugin_name, 'Plugin name', :class => 'col-sm-2 control-label' %>
|
20
|
+
|
20
21
|
<div class="col-sm-4">
|
21
22
|
<select class="form-control" id="select_plugin_name"></select>
|
22
|
-
<%= text_field_tag :entered_plugin_name, nil, :
|
23
|
+
<%= text_field_tag :entered_plugin_name, nil, :placeholder => 'as defined in the plugin Activator file', :class => 'form-control', :tenant_plugin_config => @tenant_plugin_config.to_json %>
|
23
24
|
<div class="text plugin-suggestion text-danger"></div>
|
24
25
|
</div>
|
25
26
|
<div class="col-sm-1 spinner"><i class="fa fa-cog fa-2x fa-spin"></i></div>
|
@@ -29,7 +30,7 @@
|
|
29
30
|
<span class="slider round"></span>
|
30
31
|
</label>
|
31
32
|
</label>
|
32
|
-
<label class="col-sm-3 control-label toggle-label text-muted">
|
33
|
+
<label class="col-sm-3 control-label toggle-label text-muted">manual entry</label>
|
33
34
|
</div>
|
34
35
|
|
35
36
|
<div id="plugin_config_properties_header" class="form-group">
|
@@ -41,8 +42,11 @@
|
|
41
42
|
</label>
|
42
43
|
</label>
|
43
44
|
</div>
|
44
|
-
|
45
|
-
|
45
|
+
<div class="form-group">
|
46
|
+
<%= label_tag :configuration, 'Configuration', :class => 'col-sm-2 control-label' %>
|
47
|
+
<div class="col-sm-4">
|
48
|
+
<textarea name="plugin_properties[raw_config]" id="raw_config" rows="10" class="form-control"></textarea>
|
49
|
+
</div>
|
46
50
|
</div>
|
47
51
|
|
48
52
|
<div class="form-group">
|
@@ -54,23 +58,6 @@
|
|
54
58
|
</div>
|
55
59
|
<% end %>
|
56
60
|
|
57
|
-
<script id="plugin_config_properties_template" type="text/template">
|
58
|
-
<input type="hidden" id="plugin_key_values" value="{{data_json}}" />
|
59
|
-
{{#plugin_props_with_values}}
|
60
|
-
<div class="form-group">
|
61
|
-
<label class="col-sm-offset-1 col-sm-2 control-label" for="{{property}}">{{property_label}}</label>
|
62
|
-
<div class="col-sm-6">
|
63
|
-
{{#is_raw_config}}
|
64
|
-
<textarea name="plugin_properties[raw_config]" id="raw_config" rows="10" class="form-control">{{value}}</textarea>
|
65
|
-
{{/is_raw_config}}
|
66
|
-
{{^is_raw_config}}
|
67
|
-
<input type="text" name="plugin_properties[{{property}}]" id="{{property}}" class="form-control" value="{{value}}" />
|
68
|
-
{{/is_raw_config}}
|
69
|
-
</div>
|
70
|
-
</div>
|
71
|
-
{{/plugin_props_with_values}}
|
72
|
-
</script>
|
73
|
-
|
74
61
|
<script id="plugin_name_options_template" type="text/template">
|
75
62
|
<option></option>
|
76
63
|
{{#plugin_repository}}
|
@@ -101,48 +88,54 @@
|
|
101
88
|
$('#plugin_config_properties').empty();
|
102
89
|
$('#plugin_config_properties_header').hide();
|
103
90
|
$(".plugin-suggestion").html('');
|
91
|
+
$("#raw_config").val('');
|
104
92
|
});
|
105
93
|
|
106
|
-
|
107
|
-
|
108
|
-
|
94
|
+
/* Intercept TAB and potentially display known properties */
|
95
|
+
$('#entered_plugin_name').keydown(function (e) {
|
96
|
+
if (e.keyCode === 9) {
|
97
|
+
$("#plugin_name").val($('#entered_plugin_name').val());
|
98
|
+
$("#plugin_key").val('');
|
99
|
+
render_plugin_key_values();
|
109
100
|
}
|
101
|
+
});
|
102
|
+
/* Intercept mouseleave and potentially display known properties */
|
103
|
+
$('#entered_plugin_name').on('mouseleave', function() {
|
104
|
+
$("#plugin_name").val($('#entered_plugin_name').val());
|
105
|
+
$("#plugin_key").val('');
|
106
|
+
render_plugin_key_values();
|
107
|
+
});
|
110
108
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
var plugin_name = $('#entered_plugin_name').val();
|
117
|
-
var plugin_key = $("#plugin_key").val();
|
118
|
-
var existing_props = get_tenant_plugin_properties(plugin_key, plugin_name);
|
119
|
-
raw[0].value = existing_props['_raw'];
|
120
|
-
|
121
|
-
render_plugin_key_values(raw, plugin_key_values);
|
122
|
-
} else {
|
123
|
-
render_plugin_key_values(plugin_key_values, plugin_key_values);
|
124
|
-
}
|
109
|
+
$("#toggle_raw").on('change', function(e) {
|
110
|
+
$("#plugin_name").val($('#entered_plugin_name').val());
|
111
|
+
$("#plugin_key").val('');
|
112
|
+
render_plugin_key_values();
|
125
113
|
});
|
126
114
|
|
127
115
|
$('#select_plugin_name').on('change', function(e) {
|
116
|
+
// User has selected a plugin from the dropdown
|
128
117
|
var selectedOption = e.target.selectedOptions;
|
129
118
|
|
130
119
|
if (selectedOption.length > 0) {
|
131
120
|
var plugin_name = selectedOption[0].value;
|
132
121
|
var plugin_key = selectedOption[0].text;
|
122
|
+
|
133
123
|
$("#plugin_name").val(plugin_name);
|
134
124
|
$("#plugin_key").val(plugin_key);
|
135
|
-
$("#plugin_type").val(selectedOption[0].dataset['pluginType']);
|
125
|
+
$("#plugin_type").val(selectedOption[0].dataset['pluginType']); // java or ruby
|
136
126
|
$('#plugin_config_properties').attr('plugin_name', '');
|
137
127
|
$('#plugin_config_properties_header').hide();
|
138
128
|
$("#toggle_raw").prop('checked', false);
|
139
|
-
|
129
|
+
|
130
|
+
render_plugin_key_values();
|
140
131
|
}
|
141
132
|
});
|
142
133
|
|
143
134
|
populate_plugin_name_options();
|
144
135
|
function populate_plugin_name_options(){
|
145
|
-
var
|
136
|
+
var all_plugins = JSON.parse($("#plugin_repository").val());
|
137
|
+
// We only list installed plugins as to not confuse the user
|
138
|
+
var plugin_repository = all_plugins.filter(plugin => plugin.installed);
|
146
139
|
for (var idx = 0, size = plugin_repository.length; idx < size; idx++) {
|
147
140
|
if (idx == 0 && plugin_repository[idx].installed) {
|
148
141
|
plugin_repository[idx]['start_installed'] = true;
|
@@ -163,57 +156,14 @@
|
|
163
156
|
}
|
164
157
|
|
165
158
|
var template = $("#plugin_name_options_template").html();
|
166
|
-
var options_html = Mustache.render( template , { plugin_repository: plugin_repository});
|
159
|
+
var options_html = Mustache.render( template , { plugin_repository: plugin_repository });
|
167
160
|
$("#select_plugin_name").html(options_html);
|
168
161
|
}
|
169
162
|
|
170
163
|
function get_existing_tenant_plugin_properties(entered_plugin_name) {
|
171
164
|
var tenant_plugin_properties = $('#entered_plugin_name').attr('tenant_plugin_config');
|
172
|
-
var res =
|
173
|
-
|
174
|
-
$.each(tenant_plugin_properties.split(';'), function(idx, el) {
|
175
|
-
var el_parts = el.split('::');
|
176
|
-
var el_plugin_name = el_parts[0];
|
177
|
-
var el_props = el_parts[1];
|
178
|
-
if (el_plugin_name === entered_plugin_name) {
|
179
|
-
if (el_props.split('=')[0] == 'raw_config') {
|
180
|
-
res['raw_config'] = el_props.replace("raw_config=", "");
|
181
|
-
} else {
|
182
|
-
$.map(el_props.split('|'), function(el) {
|
183
|
-
var parts = el.split('=');
|
184
|
-
res[parts[0]] = parts.slice(1).join('=');
|
185
|
-
});
|
186
|
-
}
|
187
|
-
return false;
|
188
|
-
}
|
189
|
-
});
|
190
|
-
}
|
191
|
-
return res;
|
192
|
-
}
|
193
|
-
|
194
|
-
function get_selected_plugin_info(plugin_key) {
|
195
|
-
var plugin_config_str = $('#entered_plugin_name').attr('plugin_config');
|
196
|
-
var res = {}
|
197
|
-
/* Deserialize plugin/properties (see AdminTenant model)*/
|
198
|
-
$.each(plugin_config_str.split(';'), function(idx, el) {
|
199
|
-
var el_parts = el.split(':');
|
200
|
-
var el_parts_key = el_parts[0].split('#');
|
201
|
-
var el_plugin_name = el_parts_key[0];
|
202
|
-
var el_plugin_type = el_parts_key[1];
|
203
|
-
var el_plugin_props = el_parts[1];
|
204
|
-
if (el_plugin_name == plugin_key) {
|
205
|
-
res['type'] = el_plugin_type;
|
206
|
-
res['props'] = el_plugin_props == "" ? [] : (el_plugin_type == "" ? ['raw_config'] : el_plugin_props.split(','));
|
207
|
-
return false;
|
208
|
-
}
|
209
|
-
});
|
210
|
-
|
211
|
-
if (isBlank(res['props'])) {
|
212
|
-
res['type'] = '';
|
213
|
-
res['props'] = ['raw_config'];
|
214
|
-
}
|
215
|
-
|
216
|
-
return res;
|
165
|
+
var res = JSON.parse(tenant_plugin_properties);
|
166
|
+
return res[entered_plugin_name];
|
217
167
|
}
|
218
168
|
|
219
169
|
function get_tenant_plugin_properties(plugin_key, plugin_name) {
|
@@ -221,167 +171,25 @@
|
|
221
171
|
var existing_props = get_existing_tenant_plugin_properties(plugin_key);
|
222
172
|
|
223
173
|
// try by plugin name for proprietary plugins
|
224
|
-
if (isBlank(existing_props)) {
|
174
|
+
if (isBlank(existing_props) && !isBlank(plugin_name)) {
|
225
175
|
existing_props = get_existing_tenant_plugin_properties(plugin_name);
|
226
176
|
}
|
227
177
|
|
228
178
|
return existing_props;
|
229
179
|
}
|
230
180
|
|
231
|
-
function
|
232
|
-
var
|
233
|
-
|
234
|
-
if (isBlank(
|
235
|
-
$(
|
236
|
-
$(
|
237
|
-
return;
|
238
|
-
}
|
239
|
-
|
240
|
-
if ($('#plugin_config_properties').attr('plugin_name') == plugin_name) {
|
241
|
-
/* Already set...*/
|
242
|
-
return;
|
243
|
-
}
|
244
|
-
|
245
|
-
var existing_props = get_tenant_plugin_properties(plugin_key, plugin_name);
|
246
|
-
|
247
|
-
var type = plugin_info['type'];
|
248
|
-
var props = plugin_info['props']
|
249
|
-
|
250
|
-
if (isBlank(type)) {
|
251
|
-
$(".switch-half-container").hide();
|
252
|
-
} else {
|
253
|
-
$(".switch-half-container").show();
|
254
|
-
}
|
255
|
-
|
256
|
-
$('#plugin_type').val(type);
|
257
|
-
/* Prune the tree to restart from scratch */
|
258
|
-
$('#plugin_config_properties_header').show();
|
259
|
-
$('#plugin_config_properties').empty();
|
260
|
-
$('#plugin_config_properties').append('<div id="plugin_config_properties_anchor" class="col-sm-12"></div>');
|
261
|
-
|
262
|
-
var merged_props_with_values = existing_props;
|
263
|
-
if (props != undefined) {
|
264
|
-
$.each(props, function(idx, p) {
|
265
|
-
if (merged_props_with_values[p] == undefined) {
|
266
|
-
merged_props_with_values[p] = '';
|
267
|
-
}
|
268
|
-
});
|
269
|
-
}
|
270
|
-
|
271
|
-
add_property_form_entry(merged_props_with_values);
|
272
|
-
|
273
|
-
$('#plugin_config_properties').attr('plugin_name', plugin_name);
|
274
|
-
}
|
275
|
-
|
276
|
-
function format_label(input) {
|
277
|
-
/* Keep latest piece of a system property to keep it short */
|
278
|
-
var label_name = input.split('.').pop();
|
279
|
-
/* Replace underscore with comma */
|
280
|
-
label_name = label_name.replace(/_/g, ',');
|
281
|
-
/* Replace uppercase with comma + uppercase */
|
282
|
-
label_name = label_name.replace(/([A-Z]+)/g, ",$1");
|
283
|
-
/* Split name make sure each word starts with Uppercase */
|
284
|
-
var tmp1 = label_name.split(',');
|
285
|
-
var label_name_array = [];
|
286
|
-
$.map(tmp1, function(el) { label_name_array.push(el.charAt(0).toUpperCase() + el.slice(1)) });
|
287
|
-
label_name = label_name_array.join(' ');
|
288
|
-
return label_name;
|
289
|
-
}
|
290
|
-
|
291
|
-
function add_property_form_entry(merged_props_with_values) {
|
292
|
-
var plugin_props_with_values = [];
|
293
|
-
|
294
|
-
$.each(merged_props_with_values, function(p, v) {
|
295
|
-
if (p != '_raw') {
|
296
|
-
plugin_props_with_values.push({ property_label: format_label(p), property: p, value: v, is_raw_config: p == 'raw_config'});
|
297
|
-
}
|
298
|
-
});
|
299
|
-
|
300
|
-
render_plugin_key_values(plugin_props_with_values, plugin_props_with_values);
|
301
|
-
}
|
302
|
-
|
303
|
-
function render_plugin_key_values(plugin_props_with_values, original) {
|
304
|
-
var template = $("#plugin_config_properties_template").html();
|
305
|
-
var plugin_props_with_values_html = Mustache.render( template ,{ plugin_props_with_values: plugin_props_with_values,
|
306
|
-
data_json: JSON.stringify(original)});
|
307
|
-
$("#plugin_config_properties_anchor").html(plugin_props_with_values_html);
|
308
|
-
}
|
309
|
-
|
310
|
-
// Free text related functions and handlers
|
311
|
-
init_plugin_name_handlers();
|
312
|
-
function init_plugin_name_handlers() {
|
313
|
-
/* Intercept ENTER and potentially display property form if plugin is know */
|
314
|
-
$('#entered_plugin_name').keyup(function (e) {
|
315
|
-
e.preventDefault();
|
316
|
-
if (e.keyCode === 13) {
|
317
|
-
suggest_plugin_name();
|
318
|
-
}
|
319
|
-
});
|
320
|
-
|
321
|
-
/* Intercept mouseleave and potentially display property form if plugin is know */
|
322
|
-
$('#entered_plugin_name').on('mouseleave', function() {
|
323
|
-
suggest_plugin_name();
|
324
|
-
});
|
325
|
-
}
|
326
|
-
|
327
|
-
function suggested_response(response) {
|
328
|
-
$(".spinner").hide();
|
329
|
-
if (!isBlank(response.suggestion)) {
|
330
|
-
$(".plugin-suggestion").html(response.suggestion);
|
331
|
-
|
332
|
-
$("#suggested").click(function(e) {
|
333
|
-
var plugin_name = e.currentTarget.dataset['pluginName'];
|
334
|
-
var plugin_key = e.currentTarget.dataset['pluginKey'];
|
335
|
-
|
336
|
-
$("#entered_plugin_name").val(plugin_name);
|
337
|
-
$("#plugin_key").val(plugin_key);
|
338
|
-
$("#plugin_type").val(e.currentTarget.dataset['pluginType']);
|
339
|
-
$("#entered_plugin_name").data("last", plugin_name);
|
340
|
-
|
341
|
-
$(".plugin-suggestion").html('');
|
342
|
-
add_properties_for_plugin(isBlank(plugin_key) ? plugin_name : plugin_key, plugin_name);
|
343
|
-
});
|
344
|
-
|
181
|
+
function render_plugin_key_values() {
|
182
|
+
var plugin_name = "";
|
183
|
+
var plugin_key = "";
|
184
|
+
if (isBlank($('#entered_plugin_name').val())) {
|
185
|
+
plugin_name = $("#plugin_name").val();
|
186
|
+
plugin_key = $("#plugin_key").val();
|
345
187
|
} else {
|
346
|
-
$("
|
188
|
+
plugin_name = $("#entered_plugin_name").val();
|
347
189
|
}
|
348
190
|
|
349
|
-
var
|
350
|
-
|
351
|
-
$("#plugin_name").val(plugin_name);
|
352
|
-
|
353
|
-
add_properties_for_plugin(isBlank(plugin_key) ? plugin_name : plugin_key, plugin_name);
|
354
|
-
}
|
355
|
-
|
356
|
-
function suggest_plugin_name() {
|
357
|
-
var plugin_name = $("#entered_plugin_name").val();
|
358
|
-
var last_plugin_name = $("#entered_plugin_name").data("last");
|
359
|
-
$("#plugin_key").val(plugin_name);
|
360
|
-
|
361
|
-
if (isBlank(plugin_name)) {
|
362
|
-
return;
|
363
|
-
}
|
364
|
-
|
365
|
-
// no change
|
366
|
-
if ( plugin_name == last_plugin_name) {
|
367
|
-
return;
|
368
|
-
}
|
369
|
-
|
370
|
-
$('#plugin_config_properties').attr('plugin_name', '');
|
371
|
-
$('#plugin_config_properties').empty();
|
372
|
-
$(".plugin-suggestion").html('');
|
373
|
-
$("#entered_plugin_name").data("last", plugin_name);
|
374
|
-
$(".spinner").show();
|
375
|
-
$.ajax({
|
376
|
-
url: '<%= suggest_plugin_name_path() %>',
|
377
|
-
type: "GET",
|
378
|
-
dataType: "json",
|
379
|
-
data: {
|
380
|
-
"plugin_name": plugin_name,
|
381
|
-
},
|
382
|
-
success: suggested_response
|
383
|
-
});
|
191
|
+
var existing_props = get_tenant_plugin_properties(plugin_key, plugin_name);
|
192
|
+
$("#raw_config").val(existing_props);
|
384
193
|
}
|
385
|
-
|
386
194
|
});
|
387
|
-
<% end %>
|
195
|
+
<% end %>
|
@@ -126,8 +126,8 @@
|
|
126
126
|
<% end %>
|
127
127
|
<% (transaction.properties || []).sort_by { |p| p.key }.each do |property| %>
|
128
128
|
<% next if property.value.blank? %>
|
129
|
-
<li><%= property.key
|
130
|
-
|
129
|
+
<li><strong><%= property.key %>:</strong>
|
130
|
+
<%= is_json?(property.value) ? "<pre>#{JSON.pretty_generate(JSON.parse(property.value))}</pre>".html_safe : property.value %></li>
|
131
131
|
<% end %>
|
132
132
|
</ul>
|
133
133
|
</td>
|
data/config/routes.rb
CHANGED
@@ -186,7 +186,6 @@ Kaui::Engine.routes.draw do
|
|
186
186
|
match '/add_allowed_user' => 'admin_tenants#add_allowed_user', :via => :put, :as => 'add_allowed_user'
|
187
187
|
match '/allowed_users' => 'admin_tenants#allowed_users', :via => :get, :as => 'admin_tenant_allowed_users'
|
188
188
|
match '/catalog_by_effective_date' => 'admin_tenants#catalog_by_effective_date', :via => :get, :as => 'catalog_by_effective_date'
|
189
|
-
match '/suggest_plugin_name' => 'admin_tenants#suggest_plugin_name', :via => :get, :as => 'suggest_plugin_name'
|
190
189
|
match '/switch' => 'admin_tenants#switch_tenant', :via => :get, :as => 'switch_tenant'
|
191
190
|
match '/:id/download_catalog' => 'admin_tenants#download_catalog_xml', :via => :get, :as => 'download_catalog_xml'
|
192
191
|
end
|
data/lib/kaui/version.rb
CHANGED
@@ -94,7 +94,7 @@ class Kaui::AdminTenantsControllerTest < Kaui::FunctionalTestHelper
|
|
94
94
|
stripe_yml.each { |k, v| stripe_yml[k] = v.to_s }
|
95
95
|
post :upload_plugin_config, :id => tenant.id, :plugin_name => 'killbill-stripe', :plugin_key => 'stripe', :plugin_type => 'ruby', :plugin_properties => stripe_yml
|
96
96
|
|
97
|
-
assert_redirected_to admin_tenant_path(tenant.id)
|
97
|
+
assert_redirected_to admin_tenant_path(tenant.id, :active_tab => 'PluginConfig')
|
98
98
|
assert_equal 'Config for plugin was successfully uploaded', flash[:notice]
|
99
99
|
end
|
100
100
|
|
@@ -284,26 +284,6 @@ class Kaui::AdminTenantsControllerTest < Kaui::FunctionalTestHelper
|
|
284
284
|
|
285
285
|
end
|
286
286
|
|
287
|
-
test 'should suggest a plugin name' do
|
288
|
-
plugin_anchor = "'<a id=\"suggested\" data-plugin-name=\"killbill-paypal-express\" data-plugin-key=\"paypal_express\" data-plugin-type=\"ruby\" href=\"#\">killbill-paypal-express</a>'"
|
289
|
-
|
290
|
-
# Similar plugin already installed test will run, if there are plugin installed
|
291
|
-
installed_plugins = installed_plugins()
|
292
|
-
unless installed_plugins.blank?
|
293
|
-
installed_plugins.each do |plugin|
|
294
|
-
installed_plugin_anchor = "'<a id=\"suggested\" data-plugin-name=\"#{plugin[:plugin_name]}\" data-plugin-key=\"#{plugin[:plugin_key]}\".*href=\"#\">#{plugin[:plugin_name]}</a>'"
|
295
|
-
|
296
|
-
get :suggest_plugin_name, :plugin_name => plugin[:plugin_name][0, plugin[:plugin_name].length - 1]
|
297
|
-
assert_response :success
|
298
|
-
assert_match /Similar plugin already installed: #{installed_plugin_anchor}/, JSON[@response.body]['suggestion']
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
get :suggest_plugin_name, :plugin_name => 'pypl'
|
303
|
-
assert_response :success
|
304
|
-
assert_equal "Did you mean #{plugin_anchor}?", JSON[@response.body]['suggestion']
|
305
|
-
end
|
306
|
-
|
307
287
|
test 'should switch tenant' do
|
308
288
|
other_tenant = setup_and_create_test_tenant(1)
|
309
289
|
other_tenant_kaui = Kaui::Tenant.find_by_kb_tenant_id(other_tenant.tenant_id)
|
@@ -362,7 +342,7 @@ class Kaui::AdminTenantsControllerTest < Kaui::FunctionalTestHelper
|
|
362
342
|
next if plugin.plugin_key.nil? || plugin.version.nil?
|
363
343
|
next if installed_plugins.any? { |p| p[:plugin_name].eql?(plugin.plugin_name) }
|
364
344
|
installed_plugins << {
|
365
|
-
plugin_key:
|
345
|
+
plugin_key: plugin.plugin_key,
|
366
346
|
plugin_name: plugin.plugin_name
|
367
347
|
}
|
368
348
|
end
|
@@ -25,7 +25,7 @@ class Kaui::CreditsControllerTest < Kaui::FunctionalTestHelper
|
|
25
25
|
:account_id => @account.account_id,
|
26
26
|
:credit => {
|
27
27
|
:invoice_id => invoice_id,
|
28
|
-
:
|
28
|
+
:amount => 5.34
|
29
29
|
}
|
30
30
|
assert_redirected_to account_path(@account.account_id)
|
31
31
|
assert_equal "Error while communicating with the Kill Bill server: Error 404: Object id=#{invoice_id} type=INVOICE doesn't exist!", flash[:error]
|
@@ -35,7 +35,7 @@ class Kaui::CreditsControllerTest < Kaui::FunctionalTestHelper
|
|
35
35
|
post :create,
|
36
36
|
:account_id => @account.account_id,
|
37
37
|
:credit => {
|
38
|
-
:
|
38
|
+
:amount => 5.34
|
39
39
|
}
|
40
40
|
assert_redirected_to account_path(@account.account_id)
|
41
41
|
assert_equal 'Credit was successfully created', flash[:notice]
|
@@ -46,7 +46,7 @@ class Kaui::CreditsControllerTest < Kaui::FunctionalTestHelper
|
|
46
46
|
:account_id => @account.account_id,
|
47
47
|
:credit => {
|
48
48
|
:invoice_id => @invoice_item.invoice_id,
|
49
|
-
:
|
49
|
+
:amount => 5.34
|
50
50
|
}
|
51
51
|
assert_redirected_to account_invoice_path(@account.account_id, @invoice_item.invoice_id)
|
52
52
|
assert_equal 'Credit was successfully created', flash[:notice]
|
@@ -188,7 +188,7 @@ class Kaui::HomeControllerTest < Kaui::FunctionalTestHelper
|
|
188
188
|
dummy_uuid = SecureRandom.uuid.to_s
|
189
189
|
credit = create_credit
|
190
190
|
# search by ID
|
191
|
-
get :search, :q => query_builder('CREDIT',credit.
|
191
|
+
get :search, :q => query_builder('CREDIT',credit.invoice_item_id, 'ID')
|
192
192
|
assert_redirected_to account_invoice_path(credit.account_id, credit.invoice_id)
|
193
193
|
|
194
194
|
# search by ID and fails
|
@@ -202,11 +202,11 @@ class Kaui::HomeControllerTest < Kaui::FunctionalTestHelper
|
|
202
202
|
assert_equal "\"CREDIT\": Search by \"EXTERNAL KEY\" is not supported.", flash[:error]
|
203
203
|
|
204
204
|
# search by BLANK only first
|
205
|
-
get :search, :q => query_builder('CREDIT',credit.
|
205
|
+
get :search, :q => query_builder('CREDIT',credit.invoice_item_id, nil, '1')
|
206
206
|
assert_redirected_to account_invoice_path(credit.account_id, credit.invoice_id)
|
207
207
|
|
208
208
|
# search by BLANK
|
209
|
-
get :search, :q => query_builder('CREDIT',credit.
|
209
|
+
get :search, :q => query_builder('CREDIT',credit.invoice_item_id)
|
210
210
|
assert_redirected_to account_invoice_path(credit.account_id, credit.invoice_id)
|
211
211
|
|
212
212
|
# search by BLANK and fails
|
@@ -376,9 +376,9 @@ class Kaui::HomeControllerTest < Kaui::FunctionalTestHelper
|
|
376
376
|
end
|
377
377
|
|
378
378
|
def create_credit
|
379
|
-
credit = KillBillClient::Model::Credit.new(:invoice_id => nil, :account_id => @account.account_id, :
|
379
|
+
credit = KillBillClient::Model::Credit.new(:invoice_id => nil, :account_id => @account.account_id, :amount => 2.22)
|
380
380
|
credit = credit.create(true, 'kaui search test', nil, nil, build_options(@tenant, USERNAME, PASSWORD))
|
381
|
-
credit
|
381
|
+
credit.first
|
382
382
|
end
|
383
383
|
|
384
384
|
def create_custom_field
|
@@ -96,7 +96,7 @@ class Kaui::SubscriptionsControllerTest < Kaui::FunctionalTestHelper
|
|
96
96
|
|
97
97
|
post :update, :id => @bundle.subscriptions.first.subscription_id, :plan_name => 'not-exists'
|
98
98
|
assert_redirected_to edit_subscription_path(@bundle.subscriptions.first.subscription_id)
|
99
|
-
assert_equal "Error while changing subscription: Error 400: Could not find
|
99
|
+
assert_equal "Error while changing subscription: Error 400: Could not find any plans named 'not-exists'", flash[:error]
|
100
100
|
end
|
101
101
|
|
102
102
|
test 'should update' do
|
@@ -28,7 +28,7 @@ module Kaui
|
|
28
28
|
@bundle = create_bundle(@account, @tenant)
|
29
29
|
@invoice_item = create_charge(@account, @tenant)
|
30
30
|
@paid_invoice_item = create_charge(@account, @tenant, true)
|
31
|
-
@bundle_invoice = @account.invoices(
|
31
|
+
@bundle_invoice = @account.invoices(build_options(@tenant)).first
|
32
32
|
@payment_method = create_payment_method(true, @account, @tenant)
|
33
33
|
@payment = create_payment(@paid_invoice_item, @account, @tenant)
|
34
34
|
|
@@ -159,15 +159,15 @@ module Kaui
|
|
159
159
|
tenant = create_tenant(user, reason, comment) if tenant.nil?
|
160
160
|
account = create_account(tenant, username, password, user, reason, comment) if account.nil?
|
161
161
|
|
162
|
-
credit = KillBillClient::Model::Credit.new(:invoice_id => invoice_id, :account_id => account.account_id, :
|
163
|
-
credit = credit.create(true, user, reason, comment, build_options(tenant, username, password))
|
162
|
+
credit = KillBillClient::Model::Credit.new(:invoice_id => invoice_id, :account_id => account.account_id, :amount => 23.22)
|
163
|
+
credit = credit.create(true, user, reason, comment, build_options(tenant, username, password)).first
|
164
164
|
|
165
|
-
invoice = KillBillClient::Model::Invoice.find_by_id(credit.invoice_id,
|
166
|
-
invoice.items.find { |ii| ii.amount == -credit.
|
165
|
+
invoice = KillBillClient::Model::Invoice.find_by_id(credit.invoice_id, 'NONE', build_options(tenant, username, password))
|
166
|
+
invoice.items.find { |ii| ii.amount == -credit.amount }
|
167
167
|
end
|
168
168
|
|
169
169
|
def commit_invoice(invoice_id, tenant, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil)
|
170
|
-
invoice = KillBillClient::Model::Invoice.find_by_id(invoice_id,
|
170
|
+
invoice = KillBillClient::Model::Invoice.find_by_id(invoice_id, 'NONE', build_options(tenant, username, password))
|
171
171
|
invoice.commit(user, reason, comment, build_options(tenant, username, password))
|
172
172
|
end
|
173
173
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PaymentMethodHelperTest < ActionView::TestCase
|
4
|
+
|
5
|
+
include Kaui::PaymentMethodHelper
|
6
|
+
|
7
|
+
test 'is_json?' do
|
8
|
+
assert !is_json?(5)
|
9
|
+
assert !is_json?('true')
|
10
|
+
assert !is_json?(false)
|
11
|
+
assert !is_json?("")
|
12
|
+
assert !is_json?(nil)
|
13
|
+
assert is_json?('[1, 2, 3]')
|
14
|
+
assert is_json?('{"value": "New", "onclick": "CreateNewDoc()"}')
|
15
|
+
assert !is_json?('{"value" => "New", "onclick": "CreateNewDoc()"}')
|
16
|
+
end
|
17
|
+
end
|
@@ -62,40 +62,6 @@ class Kaui::AdminTenantTest < ActiveSupport::TestCase
|
|
62
62
|
assert_split(splitted)
|
63
63
|
end
|
64
64
|
|
65
|
-
test 'can do a fuzzy match of a plugin to suggest a plugin' do
|
66
|
-
plugins_info = plugins_repo
|
67
|
-
adminTenantController = Kaui::AdminTenantsController.new
|
68
|
-
|
69
|
-
%w(killbill-paypal express paypal pay).each do |plugin_name|
|
70
|
-
found_plugin, weights = adminTenantController.send(:fuzzy_match, plugin_name, plugins_info)
|
71
|
-
assert_nil(found_plugin)
|
72
|
-
assert_equal weights[0][:plugin_name], 'killbill-paypal-express'
|
73
|
-
end
|
74
|
-
|
75
|
-
plugin_name = 'email'
|
76
|
-
found_plugin, weights = adminTenantController.send(:fuzzy_match, plugin_name, plugins_info)
|
77
|
-
assert_nil(found_plugin)
|
78
|
-
assert_equal weights[0][:plugin_name], 'killbill-email-notifications'
|
79
|
-
|
80
|
-
%w(first firstdata firstdata_e4).each do |plugin_name|
|
81
|
-
found_plugin, weights = adminTenantController.send(:fuzzy_match, plugin_name, plugins_info)
|
82
|
-
assert_nil(found_plugin)
|
83
|
-
assert_equal weights[0][:plugin_name], 'killbill-firstdata-e4'
|
84
|
-
end
|
85
|
-
|
86
|
-
%w(braintree brain).each do |plugin_name|
|
87
|
-
found_plugin, weights = adminTenantController.send(:fuzzy_match, plugin_name, plugins_info)
|
88
|
-
assert_nil(found_plugin)
|
89
|
-
assert_equal weights[0][:plugin_name], 'killbill-braintree_blue'
|
90
|
-
end
|
91
|
-
|
92
|
-
# if found weights should be empty
|
93
|
-
plugin_name = 'avatax'
|
94
|
-
found_plugin, weights = adminTenantController.send(:fuzzy_match, plugin_name, plugins_info)
|
95
|
-
assert_equal weights.size, 0
|
96
|
-
assert_equal found_plugin[:plugin_name], 'killbill-avatax'
|
97
|
-
end
|
98
|
-
|
99
65
|
test 'should fetch proprietary plugin config' do
|
100
66
|
tenant = create_tenant()
|
101
67
|
assert_not_nil(tenant)
|
@@ -106,12 +72,11 @@ class Kaui::AdminTenantTest < ActiveSupport::TestCase
|
|
106
72
|
plugin_config = 'key=value'
|
107
73
|
Kaui::AdminTenant.upload_tenant_plugin_config(plugin_name, plugin_config, options[:username], nil, nil, options)
|
108
74
|
|
109
|
-
plugins_config = Kaui::AdminTenant.get_tenant_plugin_config(
|
75
|
+
plugins_config = Kaui::AdminTenant.get_tenant_plugin_config(options)
|
110
76
|
assert_not_nil(plugins_config)
|
111
77
|
|
112
|
-
|
113
|
-
assert_equal
|
114
|
-
assert_equal 'key=value|_raw=key=value', plugin_info[1].gsub('raw_config=','')
|
78
|
+
assert_equal plugin_name, plugins_config.keys.first
|
79
|
+
assert_equal 'key=value', plugins_config[plugin_name]
|
115
80
|
end
|
116
81
|
|
117
82
|
test 'should fetch plugin config' do
|
@@ -130,15 +95,13 @@ class Kaui::AdminTenantTest < ActiveSupport::TestCase
|
|
130
95
|
plugin_config = Kaui::AdminTenant.format_plugin_config(plugin_key, 'ruby', plugin_properties)
|
131
96
|
Kaui::AdminTenant.upload_tenant_plugin_config(plugin_name, plugin_config, options[:username], nil, nil, options)
|
132
97
|
|
133
|
-
plugins_config = Kaui::AdminTenant.get_tenant_plugin_config(
|
134
|
-
'artifact_id' => 'paypal-express-plugin'} }, options)
|
98
|
+
plugins_config = Kaui::AdminTenant.get_tenant_plugin_config(options)
|
135
99
|
assert_not_nil(plugins_config)
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
assert_equal plugin_properties[:
|
140
|
-
assert_equal plugin_properties[:
|
141
|
-
assert_equal plugin_properties[:password], response_plugin_properties[2].split('=')[1]
|
100
|
+
assert_equal plugin_name, plugins_config.keys.first
|
101
|
+
response_plugin_properties = plugins_config[plugin_name].split
|
102
|
+
assert_equal plugin_properties[:signature], response_plugin_properties[3]
|
103
|
+
assert_equal plugin_properties[:login], response_plugin_properties[5]
|
104
|
+
assert_equal plugin_properties[:password], response_plugin_properties[7]
|
142
105
|
end
|
143
106
|
|
144
107
|
private
|
@@ -166,4 +129,4 @@ class Kaui::AdminTenantTest < ActiveSupport::TestCase
|
|
166
129
|
assert_equal 'to', splitted[4]
|
167
130
|
assert_equal 'split', splitted[5]
|
168
131
|
end
|
169
|
-
end
|
132
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Killbill core team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '3.
|
131
|
+
version: '3.2'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '3.
|
138
|
+
version: '3.2'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: devise
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,14 +198,14 @@ dependencies:
|
|
198
198
|
requirements:
|
199
199
|
- - "~>"
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: '
|
201
|
+
version: '2.0'
|
202
202
|
type: :runtime
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version: '
|
208
|
+
version: '2.0'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
name: jquery-ui-rails
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -844,6 +844,7 @@ files:
|
|
844
844
|
- test/test_helper.rb
|
845
845
|
- test/unit/helpers/kaui/admin_allowed_users_helper_test.rb
|
846
846
|
- test/unit/helpers/kaui/admin_tenants_helper_test.rb
|
847
|
+
- test/unit/helpers/kaui/payment_method_helper_test.rb
|
847
848
|
- test/unit/helpers/kaui/tenants_helper_test.rb
|
848
849
|
- test/unit/helpers/kaui/uuid_helper_test.rb
|
849
850
|
- test/unit/kaui/account_email_test.rb
|
@@ -904,6 +905,7 @@ test_files:
|
|
904
905
|
- test/unit/kaui/tenant_test.rb
|
905
906
|
- test/unit/kaui/money_helper_test.rb
|
906
907
|
- test/unit/helpers/kaui/tenants_helper_test.rb
|
908
|
+
- test/unit/helpers/kaui/payment_method_helper_test.rb
|
907
909
|
- test/unit/helpers/kaui/admin_tenants_helper_test.rb
|
908
910
|
- test/unit/helpers/kaui/admin_allowed_users_helper_test.rb
|
909
911
|
- test/unit/helpers/kaui/uuid_helper_test.rb
|