Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various changes for 0.22 #255

Merged
merged 6 commits into from Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions .circleci/config.yml
Expand Up @@ -32,7 +32,7 @@ jobs:
<<: *defaults
docker:
- image: killbill/kbbuild:0.5.0
- image: killbill/killbill:0.20.0
- image: killbill/killbill:0.21.8
environment:
- KILLBILL_CATALOG_URI=SpyCarAdvanced.xml
- KILLBILL_DAO_URL=jdbc:mysql://127.0.0.1:3306/killbill
Expand All @@ -41,7 +41,7 @@ jobs:
- KILLBILL_SERVER_TEST_MODE=true
- KILLBILL_INVOICE_SANITY_SAFETY_BOUND_ENABLED=false
- KILLBILL_INVOICE_MAX_DAILY_NUMBER_OF_ITEMS_SAFETY_BOUND=-1
- image: killbill/mariadb:0.20
- image: killbill/mariadb:0.21
environment:
- MYSQL_ROOT_PASSWORD=root
steps:
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
<<: *defaults
docker:
- image: killbill/kbbuild:0.5.0
- image: killbill/killbill:0.20.0
- image: killbill/killbill:0.21.8
environment:
- KILLBILL_CATALOG_URI=SpyCarAdvanced.xml
- KILLBILL_DAO_URL=jdbc:postgresql://127.0.0.1:5432/killbill
Expand All @@ -111,7 +111,7 @@ jobs:
- KILLBILL_SERVER_TEST_MODE=true
- KILLBILL_INVOICE_SANITY_SAFETY_BOUND_ENABLED=false
- KILLBILL_INVOICE_MAX_DAILY_NUMBER_OF_ITEMS_SAFETY_BOUND=-1
- image: killbill/postgresql:0.20
- image: killbill/postgresql:0.21
environment:
- POSTGRES_PASSWORD=postgres
steps:
Expand Down Expand Up @@ -193,7 +193,7 @@ jobs:
<<: *defaults
docker:
- image: killbill/kbbuild:0.5.0
- image: killbill/killbill:0.20.0
- image: killbill/killbill:0.21.8
environment:
- KILLBILL_CATALOG_URI=SpyCarAdvanced.xml
- KILLBILL_DAO_URL=jdbc:mysql://127.0.0.1:3306/killbill
Expand All @@ -202,7 +202,7 @@ jobs:
- KILLBILL_SERVER_TEST_MODE=true
- KILLBILL_INVOICE_SANITY_SAFETY_BOUND_ENABLED=false
- KILLBILL_INVOICE_MAX_DAILY_NUMBER_OF_ITEMS_SAFETY_BOUND=-1
- image: killbill/mariadb:0.20
- image: killbill/mariadb:0.21
environment:
- MYSQL_ROOT_PASSWORD=root
steps:
Expand Down Expand Up @@ -263,7 +263,7 @@ jobs:
<<: *defaults
docker:
- image: killbill/kbbuild:0.5.0
- image: killbill/killbill:0.20.0
- image: killbill/killbill:0.21.8
environment:
- KILLBILL_CATALOG_URI=SpyCarAdvanced.xml
- KILLBILL_DAO_URL=jdbc:mysql://127.0.0.1:3306/killbill
Expand All @@ -272,7 +272,7 @@ jobs:
- KILLBILL_SERVER_TEST_MODE=true
- KILLBILL_INVOICE_SANITY_SAFETY_BOUND_ENABLED=false
- KILLBILL_INVOICE_MAX_DAILY_NUMBER_OF_ITEMS_SAFETY_BOUND=-1
- image: killbill/mariadb:0.20
- image: killbill/mariadb:0.21
environment:
- MYSQL_ROOT_PASSWORD=root
steps:
Expand Down Expand Up @@ -333,7 +333,7 @@ jobs:
<<: *defaults
docker:
- image: killbill/kbbuild:0.5.0
- image: killbill/killbill:0.20.0
- image: killbill/killbill:0.21.8
environment:
- KILLBILL_CATALOG_URI=SpyCarAdvanced.xml
- KILLBILL_DAO_URL=jdbc:postgresql://127.0.0.1:5432/killbill
Expand All @@ -342,7 +342,7 @@ jobs:
- KILLBILL_SERVER_TEST_MODE=true
- KILLBILL_INVOICE_SANITY_SAFETY_BOUND_ENABLED=false
- KILLBILL_INVOICE_MAX_DAILY_NUMBER_OF_ITEMS_SAFETY_BOUND=-1
- image: killbill/postgresql:0.20
- image: killbill/postgresql:0.21
environment:
- POSTGRES_PASSWORD=postgres
steps:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -20,7 +20,7 @@ end

#gem 'killbill-client', :path => '../killbill-client-ruby'
#gem 'killbill-client', :git => 'https://github.com/killbill/killbill-client-ruby.git', :branch => 'work-for-release-0.21.x'
gem 'killbill-client', '3.1.0'
gem 'killbill-client', '3.2.0'

#gem 'kenui', :path => '../killbill-email-notifications-ui'
gem 'kenui', :git => 'https://github.com/killbill/killbill-email-notifications-ui.git', :branch => 'work-for-release-0.21.x'
Expand Down
70 changes: 0 additions & 70 deletions app/controllers/kaui/admin_tenants_controller.rb
Expand Up @@ -406,28 +406,6 @@ def catalog_by_effective_date
end
end

def suggest_plugin_name
json_response do
message = nil
entered_plugin_name = params.require(:plugin_name)
plugin_repository = view_context.plugin_repository

found_plugin, weights = fuzzy_match(entered_plugin_name, plugin_repository)

if weights.size > 0
plugin_anchor = view_context.link_to(weights[0][:plugin_name], '#', id: 'suggested',
data: {
plugin_name: weights[0][:plugin_name],
plugin_key: weights[0][:plugin_key],
plugin_type: weights[0][:plugin_type],
})
message = "Similar plugin already installed: '#{plugin_anchor}'" if weights[0][:worth_weight].to_f >= 1.0 && weights[0][:installed]
message = "Did you mean '#{plugin_anchor}'?" if weights[0][:worth_weight].to_f < 1.0 || !weights[0][:installed]
end
{ suggestion: message, plugin: found_plugin }
end
end

def switch_tenant
tenant = Kaui::Tenant.find_by_kb_tenant_id(params.require(:kb_tenant_id))

Expand Down Expand Up @@ -473,54 +451,6 @@ def split_camel_dash_underscore_space(data)
data.to_s.split(/(?=[A-Z])|(?=[_])|(?=[-])|(?=[ ])/).select {|member| !member.gsub(/[_-]/,'').strip.empty?}.map { |member| member.gsub(/[_-]/,'').strip.downcase }
end

def fuzzy_match(entered_plugin_name, plugin_repository)
splitted_entered_plugin_name = split_camel_dash_underscore_space(entered_plugin_name)
worth_of_non_words = 0.5 / splitted_entered_plugin_name.size.to_i

weights = []

plugin_repository.each do |plugin|
return plugin, [] if plugin[:plugin_name] == entered_plugin_name || plugin[:plugin_key] == entered_plugin_name
weight = { :plugin_name => plugin[:plugin_name], :plugin_key => plugin[:plugin_key],
:plugin_type => plugin[:plugin_type], :installed => plugin[:installed], :worth_weight => 0.0 }

splitted_plugin_name = split_camel_dash_underscore_space(plugin[:plugin_name])
splitted_entered_plugin_name.each do |entered|
if splitted_plugin_name.include?(entered)
weight[:worth_weight] = weight[:worth_weight] + 1.0
end

splitted_plugin_name.each do |splitted|
if entered.chars.all? { |ch| splitted.include?(ch) }
weight[:worth_weight] = weight[:worth_weight] + worth_of_non_words
break
end
end

# perform a plugin key search, if weight is zero
next unless weight[:worth_weight] == 0
splitted_plugin_key = split_camel_dash_underscore_space(plugin[:plugin_key])

if splitted_plugin_key.include?(entered)
weight[:worth_weight] = weight[:worth_weight] + 1.0
end

splitted_plugin_key.each do |splitted|
if entered.chars.all? { |ch| splitted.include?(ch) }
weight[:worth_weight] = weight[:worth_weight] + worth_of_non_words
break
end
end
end

weights << weight if weight[:worth_weight] > 0

end

weights.sort! { |a,b| b[:worth_weight] <=> a[:worth_weight] } if weights.size > 1
return nil, weights
end

def fetch_catalog_xml(tenant_id, effective_date)
current_tenant = safely_find_tenant_by_id(tenant_id)

Expand Down
8 changes: 5 additions & 3 deletions app/helpers/kaui/payment_method_helper.rb
@@ -1,9 +1,11 @@
module Kaui
module PaymentMethodHelper

def is_json?(string)
!string.blank? && !!JSON.parse(string) rescue false
def is_json?(value)
result = JSON.parse(value)
result.is_a?(Hash) || result.is_a?(Array)
rescue JSON::ParserError, TypeError
false
end

end
end
2 changes: 1 addition & 1 deletion app/helpers/kaui/plugin_helper.rb
Expand Up @@ -49,7 +49,7 @@ def installed_plugins(plugins)
next if plugin.version.nil?
# do not allow duplicate
next if installed_plugins.any? { |p| p[:plugin_name].eql?(plugin.plugin_name) }
plugin_key = Kaui::AdminTenant.rewrite_plugin_key(plugin.plugin_key) unless plugin.plugin_key.nil?
plugin_key = plugin.plugin_key
installed_plugins << {
plugin_key: plugin_key,
plugin_name: plugin.plugin_name,
Expand Down
68 changes: 7 additions & 61 deletions app/models/kaui/admin_tenant.rb
Expand Up @@ -48,59 +48,21 @@ def get_oss_plugin_info(plugin_directory)
plugin_config.map { |e,v| "#{e}:#{v.join(",")}" }.join(";")
end

# Return a map of plugin_name => config
def get_tenant_plugin_config(plugin_directory, options)
require 'yaml'

raw_tenant_config = KillBillClient::Model::Tenant::search_tenant_config("PLUGIN_CONFIG_", options)

tenant_config = raw_tenant_config.inject({}) do |hsh, e|
# Strip prefix '/PLUGIN_CONFIG_'
killbill_key = e.key.gsub!(/PLUGIN_CONFIG_/, '')

# Extract killbill key for oss plugins based on convention 'killbill-KEY'
plugin_key = killbill_key.gsub(/killbill-/, '') if killbill_key.start_with?('killbill-')

# hack:: rewrite key, to allow the ui to find the right configuration inputs
plugin_key = rewrite_plugin_key(plugin_key) unless plugin_key.nil?
# If such key exists, lookup in plugin directory to see if is an official plugin
is_an_official_plugin = !plugin_key.nil? && !plugin_directory[plugin_key.to_sym].blank?
# Deserialize config based on string possible format, if exist in the official repository
if is_an_official_plugin && is_yaml?(e.values[0])
yml = YAML.load(e.values[0])
# Hash of properties
# is plugin key part of the yaml?
if yml[plugin_key.to_sym].blank?
# if not set it as raw
hsh[plugin_key] = {:raw_config => e.values[0]}
else
hsh[plugin_key] = yml[plugin_key.to_sym]
end
hsh[plugin_key][:_raw] = e.values[0]
elsif is_an_official_plugin && is_kv?(e.values[0])
# Construct hash of properties based on java properties (k1=v1\nk2=v2\n...)
hsh[plugin_key] = e.values[0].split("\n").inject({}) do |h, p0|
k, v = p0.split('=');
h[k] = v;
h
end
hsh[plugin_key][:_raw] = e.values[0]
else
# Construct simple hash with one property :raw_config
hsh[killbill_key] = {:raw_config => e.values[0], :_raw => e.values[0]}
end
plugin_name = e.key.gsub!(/PLUGIN_CONFIG_/, '')

# Construct simple hash with one property (first value)
hsh[plugin_name] = e.values[0]

hsh
end

# Serialize the whole thing a as string of the form:
# plugin_key1::key1=value1|key2=value2|..;plugin_key2::...
tenant_config.map do |plugin_key, props|
serialized_props = props.inject("") do |s, (k, v)|
e="#{k.to_s}=#{v.to_s}";
s == "" ? s="#{e}" : s="#{s}|#{e}";
s
end
"#{plugin_key}::#{serialized_props}"
end.join(";")
tenant_config
end

def format_plugin_config(plugin_key, plugin_type, props)
Expand Down Expand Up @@ -142,22 +104,6 @@ def reformat_plugin_config(plugin_type, props)
props
end

# hack when the plugin name after killbill is not the same as the plugin key, this mainly affects ruby plugin configuration,
# as it use the key to retrieve the configuration.
def rewrite_plugin_key(plugin_key)
if plugin_key.start_with?('paypal')
'paypal_express'
elsif plugin_key.start_with?('firstdata')
'firstdata_e4'
elsif plugin_key.start_with?('bridge')
'payment_bridge'
elsif plugin_key.start_with?('payu-latam')
'payu_latam'
else
"#{plugin_key}"
end
end

# checks if string could be parse as yaml
def is_yaml?(candidate_string)
is_yaml = false
Expand Down