kaui 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +5 -29
- data/app/assets/javascripts/kaui/kaui.js +1 -1
- data/app/assets/stylesheets/kaui/account.less +9 -1
- data/app/assets/stylesheets/kaui/common.less +46 -3
- data/app/controllers/kaui/accounts_controller.rb +11 -15
- data/app/controllers/kaui/admin_tenants_controller.rb +77 -106
- data/app/controllers/kaui/audit_logs_controller.rb +3 -3
- data/app/controllers/kaui/bundles_controller.rb +4 -0
- data/app/controllers/kaui/engine_controller_util.rb +25 -17
- data/app/controllers/kaui/invoice_tags_controller.rb +28 -0
- data/app/controllers/kaui/invoices_controller.rb +65 -14
- data/app/controllers/kaui/payment_methods_controller.rb +14 -3
- data/app/controllers/kaui/sessions_controller.rb +6 -0
- data/app/controllers/kaui/subscriptions_controller.rb +13 -4
- data/app/helpers/kaui/account_helper.rb +10 -2
- data/app/helpers/kaui/payment_method_helper.rb +5 -3
- data/app/helpers/kaui/plugin_helper.rb +10 -49
- data/app/helpers/kaui/subscription_helper.rb +26 -9
- data/app/helpers/kaui/uuid_helper.rb +1 -0
- data/app/models/kaui/admin_tenant.rb +8 -84
- data/app/models/kaui/catalog.rb +28 -2
- data/app/models/kaui/tag.rb +1 -1
- data/app/views/kaui/account_emails/_form.html.erb +1 -1
- data/app/views/kaui/accounts/_billing_info.html.erb +4 -0
- data/app/views/kaui/accounts/_form.html.erb +1 -1
- data/app/views/kaui/accounts/_payment_methods.html.erb +3 -0
- data/app/views/kaui/accounts/index.html.erb +7 -4
- data/app/views/kaui/admin_tenants/_form_plugin_config.erb +59 -241
- data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +2 -2
- data/app/views/kaui/admin_tenants/new_catalog.html.erb +16 -15
- data/app/views/kaui/bundles/_bundle_details.html.erb +12 -0
- data/app/views/kaui/bundles/index.html.erb +3 -14
- data/app/views/kaui/chargebacks/_form.html.erb +1 -1
- data/app/views/kaui/charges/_form.html.erb +1 -1
- data/app/views/kaui/invoice_tags/_form.html.erb +33 -0
- data/app/views/kaui/invoice_tags/_form_bar.html.erb +21 -0
- data/app/views/kaui/invoice_tags/edit.html.erb +10 -0
- data/app/views/kaui/invoices/_invoice_table.html.erb +30 -9
- data/app/views/kaui/invoices/index.html.erb +6 -4
- data/app/views/kaui/invoices/show.html.erb +11 -2
- data/app/views/kaui/layouts/kaui_flash.html.erb +8 -1
- data/app/views/kaui/payments/_form.html.erb +1 -1
- data/app/views/kaui/payments/_payment_table.html.erb +2 -2
- data/app/views/kaui/payments/index.html.erb +3 -1
- data/app/views/kaui/subscriptions/_edit_form.html.erb +1 -1
- data/app/views/kaui/subscriptions/_form.html.erb +1 -1
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +3 -3
- data/config/routes.rb +6 -1
- data/lib/kaui.rb +55 -0
- data/lib/kaui/version.rb +1 -1
- data/test/dummy/config/database.yml +2 -2
- data/test/dummy/config/initializers/cookies_serializer.rb +1 -1
- data/test/dummy/config/initializers/money.rb +2 -0
- data/test/functional/kaui/account_emails_controller_test.rb +2 -2
- data/test/functional/kaui/account_tags_controller_test.rb +1 -1
- data/test/functional/kaui/accounts_controller_test.rb +4 -4
- data/test/functional/kaui/admin_tenants_controller_test.rb +3 -23
- data/test/functional/kaui/bundle_tags_controller_test.rb +1 -1
- data/test/functional/kaui/bundles_controller_test.rb +3 -3
- data/test/functional/kaui/chargebacks_controller_test.rb +2 -2
- data/test/functional/kaui/charges_controller_test.rb +2 -2
- data/test/functional/kaui/credits_controller_test.rb +5 -5
- data/test/functional/kaui/home_controller_test.rb +5 -5
- data/test/functional/kaui/invoice_items_controller_test.rb +3 -3
- data/test/functional/kaui/invoices_controller_test.rb +2 -2
- data/test/functional/kaui/refunds_controller_test.rb +2 -2
- data/test/functional/kaui/subscriptions_controller_test.rb +6 -6
- data/test/killbill_test_helper.rb +8 -6
- data/test/unit/helpers/kaui/payment_method_helper_test.rb +17 -0
- data/test/unit/kaui/account_test.rb +2 -2
- data/test/unit/kaui/admin_tenant_test.rb +10 -47
- data/test/unit/kaui/invoice_item_test.rb +1 -1
- data/test/unit/kaui/invoice_payment_test.rb +7 -7
- data/test/unit/kaui/invoice_test.rb +4 -4
- data/test/unit/kaui/payment_test.rb +7 -7
- metadata +110 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e5d858912d18a92b6d29b430c5abcef292407e21
|
4
|
+
data.tar.gz: c9fb2496bc22b4c176cbf491d914be4f2ff794fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b9de048f13170e6ca37fd7656f5c4524e6c72f1820efb4c16d9778f61890fd613a4ab31daa25216792396d636d4df9215638e153f411f7e49fc1f3a17d479cc
|
7
|
+
data.tar.gz: c1f5fca064ec6d5e671f69ab21fccc35d63f02f24c9b05ff897b20466a2980f1c470a3bc11b14df8060b368dc77646d03307ed87b21eac94f828033cae40e295
|
data/README.md
CHANGED
@@ -22,35 +22,15 @@ Ruby 2.4.2+ or JRuby 9.1.14.0+ required.
|
|
22
22
|
Running Kaui locally
|
23
23
|
---------------------
|
24
24
|
|
25
|
+
Note: use Ruby, not JRuby, for running the app locally.
|
26
|
+
|
25
27
|
You can run Kaui locally by using the test/dummy app provided:
|
26
28
|
|
27
29
|
```
|
28
|
-
export RAILS_ENV=development
|
29
|
-
export DATABASE_URL=mysql://root:killbill@<MySQL Host IP>/killbill
|
30
|
+
export RAILS_ENV=development DB_HOST=127.0.0.1 DB_USER=root DB_PASSWORD=root DB_PORT=3306
|
30
31
|
bundle install
|
31
|
-
rails db:migrate
|
32
|
-
rails s
|
33
|
-
```
|
34
|
-
If you experience an error of;
|
35
|
-
|
36
|
-
```
|
37
|
-
You must use Bundler 2 or greater with this lockfile.
|
38
|
-
```
|
39
|
-
|
40
|
-
Then run the following commands to update your environment.
|
41
|
-
|
42
|
-
Update Rubygems;
|
43
|
-
|
44
|
-
```
|
45
|
-
gem update --system
|
46
|
-
```
|
47
|
-
Update bundler;
|
48
|
-
```
|
49
|
-
gem install bundler
|
50
|
-
```
|
51
|
-
Update the Gemfile.lock file;
|
52
|
-
```
|
53
|
-
bundler update --bundler
|
32
|
+
bundle exec rails db:migrate
|
33
|
+
bundle exec rails s
|
54
34
|
```
|
55
35
|
|
56
36
|
The Kill Bill URL can be configured through the `KILLBILL_URL` environment variable, e.g.
|
@@ -111,10 +91,6 @@ Alternatively, you can run the `kaui` script under `bin` by setting your loadpat
|
|
111
91
|
|
112
92
|
ruby -Ilib bin/kaui /path/to/rails/app --path=$PWD --skip-bundle
|
113
93
|
|
114
|
-
Releases
|
115
|
-
========
|
116
|
-
|
117
|
-
The releases are done using Jruby and require the following property `export JRUBY_OPTS='--2.0 -J-Xmx1024m'`
|
118
94
|
|
119
95
|
Multi-Tenancy
|
120
96
|
=============
|
@@ -205,7 +205,7 @@ jQuery(document).ready(function ($) {
|
|
205
205
|
return;
|
206
206
|
}
|
207
207
|
|
208
|
-
var message = 'Request
|
208
|
+
var message = 'Request error: ' + getMessageFromResponse(jqxhr);
|
209
209
|
|
210
210
|
if (jqxhr.status == 200) {
|
211
211
|
message = thrownError.message == undefined ? thrownError : thrownError.message;
|
@@ -99,7 +99,7 @@ span {
|
|
99
99
|
font-weight: normal;
|
100
100
|
color: rgb(119, 119, 119);
|
101
101
|
|
102
|
-
&.label-success, &.label-warning, &.label-danger {
|
102
|
+
&.label-default, &.label-success, &.label-warning, &.label-danger {
|
103
103
|
color: #fff;
|
104
104
|
}
|
105
105
|
}
|
@@ -497,7 +497,7 @@ table.subtitle {
|
|
497
497
|
}
|
498
498
|
|
499
499
|
a {
|
500
|
-
margin: 0
|
500
|
+
margin: 0 5px;
|
501
501
|
text-transform: uppercase;
|
502
502
|
font-size: 12px;
|
503
503
|
|
@@ -717,4 +717,47 @@ form[id^="new_tag_definition"] {
|
|
717
717
|
|
718
718
|
.switch-tenant-active {
|
719
719
|
color: #00919d;
|
720
|
-
}
|
720
|
+
}
|
721
|
+
|
722
|
+
/* Required for https://github.com/killbill/killbill-admin-ui/issues/262 */
|
723
|
+
.ui-autocomplete {
|
724
|
+
position: absolute;
|
725
|
+
z-index: 1000;
|
726
|
+
float: left;
|
727
|
+
display: none;
|
728
|
+
min-width: 160px;
|
729
|
+
padding: 4px 0;
|
730
|
+
margin: 2px 0 0 0;
|
731
|
+
list-style: none;
|
732
|
+
background-color: #ffffff;
|
733
|
+
border-color: rgba(0, 0, 0, 0.2);
|
734
|
+
border-style: solid;
|
735
|
+
border-width: 1px;
|
736
|
+
border-radius: 5px;
|
737
|
+
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
|
738
|
+
background-clip: padding-box;
|
739
|
+
|
740
|
+
.ui-menu-item {
|
741
|
+
display: block;
|
742
|
+
padding: 3px 15px;
|
743
|
+
clear: both;
|
744
|
+
font-weight: normal;
|
745
|
+
line-height: 18px;
|
746
|
+
color: #555555;
|
747
|
+
white-space: nowrap;
|
748
|
+
|
749
|
+
.ui-state-active, .ui-state-hover {
|
750
|
+
color: #ffffff;
|
751
|
+
text-decoration: none;
|
752
|
+
background-color: #0088cc;
|
753
|
+
border-radius: 0px;
|
754
|
+
-webkit-border-radius: 0px;
|
755
|
+
-moz-border-radius: 0px;
|
756
|
+
background-image: none;
|
757
|
+
}
|
758
|
+
}
|
759
|
+
}
|
760
|
+
|
761
|
+
.ui-helper-hidden-accessible {
|
762
|
+
display: none;
|
763
|
+
}
|
@@ -29,12 +29,9 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
29
29
|
data_extractor = lambda do |account, column|
|
30
30
|
[
|
31
31
|
account.parent_account_id,
|
32
|
-
account.name,
|
33
32
|
account.account_id,
|
34
33
|
account.external_key,
|
35
|
-
account.account_balance
|
36
|
-
account.city,
|
37
|
-
account.country
|
34
|
+
account.account_balance
|
38
35
|
][column]
|
39
36
|
end
|
40
37
|
|
@@ -44,12 +41,9 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
44
41
|
child_label = account.parent_account_id.nil? ? '' : view_context.content_tag(:span, 'Child', class: ['label', 'label-info', 'account-child-label'])
|
45
42
|
end
|
46
43
|
|
47
|
-
[
|
48
|
-
|
49
|
-
|
50
|
-
account.external_key,
|
51
|
-
view_context.humanized_money_with_symbol(account.balance_to_money)
|
52
|
-
]
|
44
|
+
row = [child_label, view_context.link_to(account.account_id, view_context.url_for(:action => :show, :account_id => account.account_id))]
|
45
|
+
row += Kaui.account_search_columns.call(account, view_context)[1]
|
46
|
+
row
|
53
47
|
end
|
54
48
|
|
55
49
|
paginate searcher, data_extractor, formatter
|
@@ -83,17 +77,17 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
83
77
|
@account = Kaui::Account::find_by_id_or_key(params.require(:account_id), true, true, cached_options_for_klient)
|
84
78
|
|
85
79
|
fetch_children = promise { @account.children(false, false, 'NONE',cached_options_for_klient)}
|
86
|
-
fetch_parent =
|
80
|
+
fetch_parent = @account.parent_account_id.nil? ? nil : promise { Kaui::Account::find_by_id(@account.parent_account_id,false,false,cached_options_for_klient) }
|
87
81
|
fetch_overdue_state = promise { @account.overdue(cached_options_for_klient) }
|
88
82
|
fetch_account_tags = promise { @account.tags(false, 'NONE', cached_options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b } }
|
89
83
|
fetch_account_fields = promise { @account.custom_fields('NONE', cached_options_for_klient).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase } }
|
90
84
|
fetch_account_emails = promise { Kaui::AccountEmail.find_all_sorted_by_account_id(@account.account_id, 'NONE', cached_options_for_klient) }
|
91
85
|
fetch_payments = promise { @account.payments(cached_options_for_klient).map! { |payment| Kaui::Payment.build_from_raw_payment(payment) } }
|
92
|
-
fetch_payment_methods = promise
|
86
|
+
fetch_payment_methods = promise { Kaui::PaymentMethod.find_all_by_account_id(@account.account_id, false, cached_options_for_klient) }
|
93
87
|
|
94
88
|
# is email notification plugin available
|
95
89
|
is_email_notifications_plugin_available = Kenui::EmailNotificationService.email_notification_plugin_available?(cached_options_for_klient).first
|
96
|
-
fetch_email_notification_configuration =
|
90
|
+
fetch_email_notification_configuration = !is_email_notifications_plugin_available ? nil : promise do
|
97
91
|
Kenui::EmailNotificationService.get_configuration_per_account(params.require(:account_id),cached_options_for_klient)
|
98
92
|
end.then do |configuration|
|
99
93
|
if configuration.first.is_a?(FalseClass)
|
@@ -106,7 +100,7 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
106
100
|
fetch_payment_methods_with_details = fetch_payment_methods.then do |pms|
|
107
101
|
ops = []
|
108
102
|
pms.each do |pm|
|
109
|
-
ops << promise
|
103
|
+
ops << promise {
|
110
104
|
begin
|
111
105
|
Kaui::PaymentMethod.find_by_id(pm.payment_method_id, true, cached_options_for_klient)
|
112
106
|
rescue => e
|
@@ -125,7 +119,7 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
125
119
|
@custom_fields = wait(fetch_account_fields)
|
126
120
|
@account_emails = wait(fetch_account_emails)
|
127
121
|
wait(fetch_payment_methods)
|
128
|
-
@payment_methods = wait(fetch_payment_methods_with_details).map
|
122
|
+
@payment_methods = wait(fetch_payment_methods_with_details).map{ |pm_f| wait(pm_f) }.reject { |pm| pm.nil? }
|
129
123
|
@available_tags = wait(fetch_available_tags)
|
130
124
|
@children = wait(fetch_children)
|
131
125
|
@account_parent = @account.parent_account_id.nil? ? nil : wait(fetch_parent)
|
@@ -183,6 +177,8 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
183
177
|
redirect_to account_path(account_id), :notice => "Nothing to generate for target date #{target_date.nil? ? 'today' : target_date}"
|
184
178
|
elsif dry_run
|
185
179
|
@invoice = Kaui::Invoice.build_from_raw_invoice(invoice)
|
180
|
+
@invoice_tags = []
|
181
|
+
@available_invoice_tags = []
|
186
182
|
@payments = []
|
187
183
|
@payment_methods = nil
|
188
184
|
@account = Kaui::Account.find_by_id(account_id, false, false, options_for_klient)
|
@@ -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
|
@@ -121,27 +115,15 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
121
115
|
end
|
122
116
|
|
123
117
|
def new_catalog
|
124
|
-
@tenant = safely_find_tenant_by_id(params[:id])
|
125
|
-
|
126
118
|
options = tenant_options_for_client
|
127
|
-
options
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
latest_catalog.products.select { |p| p.type == 'BASE' }.map { |p| p.name } : []
|
136
|
-
@available_ao_products = latest_catalog && latest_catalog.products ?
|
137
|
-
latest_catalog.products.select { |p| p.type == 'ADD_ON' }.map { |p| p.name } : []
|
138
|
-
@available_standalone_products = latest_catalog && latest_catalog.products ?
|
139
|
-
latest_catalog.products.select { |p| p.type == 'STANDALONE' }.map { |p| p.name } : []
|
140
|
-
@product_categories = [:BASE, :ADD_ON, :STANDALONE]
|
141
|
-
@billing_period = [:DAILY, :WEEKLY, :BIWEEKLY, :THIRTY_DAYS, :MONTHLY, :QUARTERLY, :BIANNUAL, :ANNUAL, :BIENNIAL]
|
142
|
-
@time_units = [:UNLIMITED, :DAYS, :WEEKS, :MONTHS, :YEARS]
|
143
|
-
|
144
|
-
@simple_plan = Kaui::SimplePlan.new
|
119
|
+
fetch_state_for_new_catalog_screen(options)
|
120
|
+
@simple_plan = Kaui::SimplePlan.new({
|
121
|
+
:product_category => 'BASE',
|
122
|
+
:amount => 0,
|
123
|
+
:trial_length => 0,
|
124
|
+
:currency => 'USD',
|
125
|
+
:billing_period => 'MONTHLY'
|
126
|
+
})
|
145
127
|
end
|
146
128
|
|
147
129
|
def delete_catalog
|
@@ -189,21 +171,55 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
189
171
|
end
|
190
172
|
|
191
173
|
def create_simple_plan
|
192
|
-
current_tenant = safely_find_tenant_by_id(params[:id])
|
193
|
-
|
194
174
|
options = tenant_options_for_client
|
195
|
-
options
|
196
|
-
options[:api_secret] = current_tenant.api_secret
|
175
|
+
fetch_state_for_new_catalog_screen(options)
|
197
176
|
|
198
177
|
simple_plan = params.require(:simple_plan).delete_if { |e, value| value.blank? }
|
199
178
|
# Fix issue in Rails where first entry in the multi-select array is an empty string
|
200
179
|
simple_plan["available_base_products"].reject!(&:blank?) if simple_plan["available_base_products"]
|
201
180
|
|
202
|
-
simple_plan =
|
203
|
-
|
204
|
-
|
181
|
+
@simple_plan = Kaui::SimplePlan.new(simple_plan)
|
182
|
+
|
183
|
+
valid = true
|
184
|
+
# Validate new simple plan
|
185
|
+
# https://github.com/killbill/killbill-admin-ui/issues/247
|
186
|
+
if @available_base_products.include?(@simple_plan.plan_id)
|
187
|
+
flash.now[:error] = "Error while creating plan: invalid plan name (#{@simple_plan.plan_id} is a BASE product already)"
|
188
|
+
valid = false
|
189
|
+
elsif @available_ao_products.include?(@simple_plan.plan_id)
|
190
|
+
flash.now[:error] = "Error while creating plan: invalid plan name (#{@simple_plan.plan_id} is an ADD_ON product already)"
|
191
|
+
valid = false
|
192
|
+
elsif @available_standalone_products.include?(@simple_plan.plan_id)
|
193
|
+
flash.now[:error] = "Error while creating plan: invalid plan name (#{@simple_plan.plan_id} is a STANDALONE product already)"
|
194
|
+
valid = false
|
195
|
+
elsif @all_plans.include?(@simple_plan.product_name)
|
196
|
+
flash.now[:error] = "Error while creating plan: invalid product name (#{@simple_plan.product_name} is a plan name already)"
|
197
|
+
valid = false
|
198
|
+
elsif @all_plans.include?(@simple_plan.plan_id)
|
199
|
+
flash.now[:error] = "Error while creating plan: plan #{@simple_plan.plan_id} already exists"
|
200
|
+
valid = false
|
201
|
+
elsif @available_base_products.include?(@simple_plan.product_name) && @simple_plan.product_category != 'BASE'
|
202
|
+
flash.now[:error] = "Error while creating plan: product #{@simple_plan.product_name} is a BASE product"
|
203
|
+
valid = false
|
204
|
+
elsif @available_ao_products.include?(@simple_plan.product_name) && @simple_plan.product_category != 'ADD_ON'
|
205
|
+
flash.now[:error] = "Error while creating plan: product #{@simple_plan.product_name} is an ADD_ON product"
|
206
|
+
valid = false
|
207
|
+
elsif @available_standalone_products.include?(@simple_plan.product_name) && @simple_plan.product_category != 'STANDALONE'
|
208
|
+
flash.now[:error] = "Error while creating plan: product #{@simple_plan.product_name} is a STANDALONE product"
|
209
|
+
valid = false
|
210
|
+
end
|
205
211
|
|
206
|
-
|
212
|
+
if valid
|
213
|
+
begin
|
214
|
+
Kaui::Catalog.add_tenant_catalog_simple_plan(@simple_plan, options[:username], nil, comment, options)
|
215
|
+
redirect_to admin_tenant_path(@tenant.id), :notice => 'Catalog plan was successfully added'
|
216
|
+
rescue => e
|
217
|
+
flash.now[:error] = "Error while creating plan: #{as_string(e)}"
|
218
|
+
render :action => :new_catalog
|
219
|
+
end
|
220
|
+
else
|
221
|
+
render :action => :new_catalog
|
222
|
+
end
|
207
223
|
end
|
208
224
|
|
209
225
|
def new_overdue_config
|
@@ -307,6 +323,8 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
307
323
|
|
308
324
|
if plugin_properties.blank?
|
309
325
|
flash[:error] = 'Plugin properties cannot be blank'
|
326
|
+
elsif plugin_name.blank?
|
327
|
+
flash[:error] = 'Plugin name cannot be blank'
|
310
328
|
else
|
311
329
|
plugin_config = Kaui::AdminTenant.format_plugin_config(plugin_key, plugin_type, plugin_properties)
|
312
330
|
|
@@ -314,7 +332,7 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
314
332
|
flash[:notice] = 'Config for plugin was successfully uploaded'
|
315
333
|
end
|
316
334
|
|
317
|
-
redirect_to admin_tenant_path(current_tenant.id)
|
335
|
+
redirect_to admin_tenant_path(current_tenant.id, :active_tab => 'PluginConfig')
|
318
336
|
end
|
319
337
|
|
320
338
|
def remove_allowed_user
|
@@ -406,28 +424,6 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
406
424
|
end
|
407
425
|
end
|
408
426
|
|
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
427
|
def switch_tenant
|
432
428
|
tenant = Kaui::Tenant.find_by_kb_tenant_id(params.require(:kb_tenant_id))
|
433
429
|
|
@@ -441,6 +437,29 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
441
437
|
|
442
438
|
private
|
443
439
|
|
440
|
+
# Share code to handle render on error
|
441
|
+
def fetch_state_for_new_catalog_screen(options)
|
442
|
+
@tenant = safely_find_tenant_by_id(params[:id])
|
443
|
+
|
444
|
+
options[:api_key] = @tenant.api_key
|
445
|
+
options[:api_secret] = @tenant.api_secret
|
446
|
+
|
447
|
+
latest_catalog = Kaui::Catalog::get_catalog_json(true, nil, options)
|
448
|
+
@all_plans = latest_catalog ? (latest_catalog.products || []).map(&:plans).flatten.map(&:name) : []
|
449
|
+
|
450
|
+
@ao_mapping = Kaui::Catalog::build_ao_mapping(latest_catalog)
|
451
|
+
|
452
|
+
@available_base_products = latest_catalog && latest_catalog.products ?
|
453
|
+
latest_catalog.products.select { |p| p.type == 'BASE' }.map { |p| p.name } : []
|
454
|
+
@available_ao_products = latest_catalog && latest_catalog.products ?
|
455
|
+
latest_catalog.products.select { |p| p.type == 'ADD_ON' }.map { |p| p.name } : []
|
456
|
+
@available_standalone_products = latest_catalog && latest_catalog.products ?
|
457
|
+
latest_catalog.products.select { |p| p.type == 'STANDALONE' }.map { |p| p.name } : []
|
458
|
+
@product_categories = [:BASE, :ADD_ON, :STANDALONE]
|
459
|
+
@billing_period = [:DAILY, :WEEKLY, :BIWEEKLY, :THIRTY_DAYS, :MONTHLY, :QUARTERLY, :BIANNUAL, :ANNUAL, :BIENNIAL]
|
460
|
+
@time_units = [:UNLIMITED, :DAYS, :WEEKS, :MONTHS, :YEARS]
|
461
|
+
end
|
462
|
+
|
444
463
|
def safely_find_tenant_by_id(tenant_id)
|
445
464
|
tenant = Kaui::Tenant.find_by_id(tenant_id)
|
446
465
|
raise ActiveRecord::RecordNotFound.new('Could not find tenant ' + tenant_id) unless retrieve_tenants_for_current_user.include?(tenant.kb_tenant_id)
|
@@ -473,54 +492,6 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
473
492
|
data.to_s.split(/(?=[A-Z])|(?=[_])|(?=[-])|(?=[ ])/).select {|member| !member.gsub(/[_-]/,'').strip.empty?}.map { |member| member.gsub(/[_-]/,'').strip.downcase }
|
474
493
|
end
|
475
494
|
|
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
495
|
def fetch_catalog_xml(tenant_id, effective_date)
|
525
496
|
current_tenant = safely_find_tenant_by_id(tenant_id)
|
526
497
|
|