kaui 2.1.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +8 -7
- data/Rakefile +4 -2
- data/app/assets/config/kaui_manifest.js +45 -0
- data/app/assets/javascripts/jquery.spin.js +76 -0
- data/app/assets/javascripts/kaui/kaui.js +76 -0
- data/app/assets/javascripts/kaui_application.js +25 -0
- data/app/assets/javascripts/spin.js +76 -0
- data/app/assets/stylesheets/bootstrap_and_overrides.scss +240 -0
- data/app/assets/stylesheets/kaui/{account.less → account.scss} +4 -0
- data/app/assets/stylesheets/kaui/{audit.less → audit.scss} +5 -1
- data/app/assets/stylesheets/kaui/{common.less → common.scss} +17 -15
- data/app/assets/stylesheets/kaui/{datatable.less → datatable.scss} +6 -3
- data/app/assets/stylesheets/kaui/{header.less → header.scss} +16 -12
- data/app/assets/stylesheets/kaui/{home.less → home.scss} +7 -4
- data/app/assets/stylesheets/kaui/{invoice.less → invoice.scss} +7 -3
- data/app/assets/stylesheets/kaui/kaui.scss +265 -0
- data/app/assets/stylesheets/kaui/kaui_bootstrap.scss +3 -0
- data/app/assets/stylesheets/kaui/{overdue.less → overdue.scss} +3 -1
- data/app/assets/stylesheets/kaui/{payment.less → payment.scss} +3 -0
- data/app/assets/stylesheets/kaui/{subscription.less → subscription.scss} +4 -1
- data/app/assets/stylesheets/kaui/{tags.less → tags.scss} +9 -5
- data/app/assets/stylesheets/kaui/timeline.scss +7 -0
- data/app/assets/stylesheets/kaui/tooltip.scss +15 -0
- data/app/controllers/kaui/account_children_controller.rb +25 -28
- data/app/controllers/kaui/account_custom_fields_controller.rb +16 -15
- data/app/controllers/kaui/account_emails_controller.rb +28 -25
- data/app/controllers/kaui/account_tags_controller.rb +37 -34
- data/app/controllers/kaui/account_timelines_controller.rb +38 -33
- data/app/controllers/kaui/accounts_controller.rb +268 -250
- data/app/controllers/kaui/admin_allowed_users_controller.rb +105 -99
- data/app/controllers/kaui/admin_controller.rb +32 -31
- data/app/controllers/kaui/admin_tenants_controller.rb +434 -388
- data/app/controllers/kaui/audit_logs_controller.rb +86 -83
- data/app/controllers/kaui/bundle_tags_controller.rb +24 -20
- data/app/controllers/kaui/bundles_controller.rb +96 -82
- data/app/controllers/kaui/chargebacks_controller.rb +36 -33
- data/app/controllers/kaui/charges_controller.rb +23 -20
- data/app/controllers/kaui/credits_controller.rb +28 -25
- data/app/controllers/kaui/custom_fields_controller.rb +172 -38
- data/app/controllers/kaui/engine_controller.rb +2 -1
- data/app/controllers/kaui/engine_controller_util.rb +128 -117
- data/app/controllers/kaui/home_controller.rb +230 -217
- data/app/controllers/kaui/invoice_items_controller.rb +43 -39
- data/app/controllers/kaui/invoice_tags_controller.rb +24 -20
- data/app/controllers/kaui/invoices_controller.rb +132 -117
- data/app/controllers/kaui/login_proxy_controller.rb +2 -1
- data/app/controllers/kaui/payment_methods_controller.rb +102 -94
- data/app/controllers/kaui/payments_controller.rb +95 -92
- data/app/controllers/kaui/queues_controller.rb +47 -14
- data/app/controllers/kaui/refunds_controller.rb +36 -33
- data/app/controllers/kaui/registrations_controller.rb +7 -7
- data/app/controllers/kaui/role_definitions_controller.rb +17 -14
- data/app/controllers/kaui/sessions_controller.rb +7 -4
- data/app/controllers/kaui/subscriptions_controller.rb +197 -187
- data/app/controllers/kaui/tag_definitions_controller.rb +28 -27
- data/app/controllers/kaui/tags_controller.rb +25 -22
- data/app/controllers/kaui/tenants_controller.rb +30 -28
- data/app/controllers/kaui/transactions_controller.rb +43 -38
- data/app/helpers/kaui/account_helper.rb +16 -14
- data/app/helpers/kaui/application_helper.rb +8 -3
- data/app/helpers/kaui/date_helper.rb +4 -3
- data/app/helpers/kaui/home_helper.rb +2 -0
- data/app/helpers/kaui/locale_helper.rb +7 -6
- data/app/helpers/kaui/money_helper.rb +2 -1
- data/app/helpers/kaui/object_helper.rb +11 -10
- data/app/helpers/kaui/payment_helper.rb +7 -6
- data/app/helpers/kaui/payment_method_helper.rb +3 -2
- data/app/helpers/kaui/permissions_helper.rb +9 -9
- data/app/helpers/kaui/plugin_helper.rb +25 -23
- data/app/helpers/kaui/subscription_helper.rb +27 -29
- data/app/helpers/kaui/us_states_helper.rb +7 -6
- data/app/helpers/kaui/uuid_helper.rb +8 -6
- data/app/models/kaui/ability.rb +19 -12
- data/app/models/kaui/account.rb +45 -28
- data/app/models/kaui/account_email.rb +23 -20
- data/app/models/kaui/account_timeline.rb +5 -1
- data/app/models/kaui/admin.rb +65 -64
- data/app/models/kaui/admin_tenant.rb +81 -82
- data/app/models/kaui/allowed_user.rb +13 -9
- data/app/models/kaui/allowed_user_tenant.rb +4 -2
- data/app/models/kaui/application_record.rb +2 -0
- data/app/models/kaui/audit_log.rb +6 -3
- data/app/models/kaui/base.rb +13 -7
- data/app/models/kaui/bundle.rb +41 -24
- data/app/models/kaui/catalog.rb +118 -113
- data/app/models/kaui/chargeback.rb +5 -1
- data/app/models/kaui/credit.rb +4 -1
- data/app/models/kaui/custom_field.rb +9 -6
- data/app/models/kaui/invoice.rb +25 -22
- data/app/models/kaui/invoice_item.rb +9 -6
- data/app/models/kaui/invoice_payment.rb +49 -54
- data/app/models/kaui/killbill_authenticatable.rb +14 -8
- data/app/models/kaui/killbill_registerable.rb +7 -0
- data/app/models/kaui/overdue.rb +64 -65
- data/app/models/kaui/payment.rb +22 -19
- data/app/models/kaui/payment_method.rb +48 -39
- data/app/models/kaui/payment_state.rb +41 -38
- data/app/models/kaui/rails_methods.rb +9 -9
- data/app/models/kaui/refund.rb +7 -1
- data/app/models/kaui/role_definition.rb +5 -1
- data/app/models/kaui/simple_plan.rb +5 -3
- data/app/models/kaui/subscription.rb +10 -7
- data/app/models/kaui/tag.rb +25 -22
- data/app/models/kaui/tag_definition.rb +50 -45
- data/app/models/kaui/tenant.rb +6 -5
- data/app/models/kaui/transaction.rb +43 -31
- data/app/models/kaui/user.rb +10 -16
- data/app/models/kaui/user_role.rb +8 -5
- data/app/views/kaui/accounts/_billing_info.html.erb +1 -1
- data/app/views/kaui/accounts/_form.html.erb +2 -2
- data/app/views/kaui/accounts/index.html.erb +2 -0
- data/app/views/kaui/admin_allowed_users/_form.html.erb +3 -3
- data/app/views/kaui/admin_tenants/_form_catalog_translation.erb +1 -1
- data/app/views/kaui/admin_tenants/_form_invoice_template.erb +1 -1
- data/app/views/kaui/admin_tenants/_form_invoice_translation.erb +1 -1
- data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +11 -5
- data/app/views/kaui/admin_tenants/new_catalog.html.erb +2 -2
- data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +2 -2
- data/app/views/kaui/admin_tenants/new_plan_currency.html.erb +1 -1
- data/app/views/kaui/bundles/index.html.erb +1 -1
- data/app/views/kaui/bundles/transfer.html.erb +13 -5
- data/app/views/kaui/invoices/_invoice_table.html.erb +1 -1
- data/app/views/kaui/layouts/kaui_flash.html.erb +24 -0
- data/app/views/kaui/layouts/kaui_header.html.erb +19 -2
- data/app/views/kaui/payment_methods/_payment_methods_details_table.html.erb +13 -4
- data/app/views/kaui/payments/_payment_table.html.erb +21 -11
- data/app/views/kaui/payments/index.html.erb +9 -9
- data/app/views/kaui/queues/index.html.erb +1 -1
- data/app/views/kaui/subscriptions/_cancel_by_date_modal.html.erb +1 -4
- 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/app/views/kaui/subscriptions/edit_bcd.erb +1 -1
- data/app/views/kaui/tag_definitions/index.html.erb +2 -2
- data/app/views/kaui/tags/index.html.erb +1 -0
- data/config/initializers/bootstrap_datepicker_rails.rb +3 -0
- data/config/initializers/devise.rb +8 -6
- data/config/initializers/js_routes.rb +9 -0
- data/config/initializers/kilbill_client_init.rb +13 -0
- data/config/initializers/killbill_authenticatable.rb +71 -21
- data/config/initializers/killbill_registerable.rb +5 -3
- data/config/initializers/time_formats.rb +6 -4
- data/config/locales/en.yml +78 -1
- data/config/routes.rb +34 -32
- data/db/migrate/20130812155313_devise_create_kaui_users.rb +10 -8
- data/db/migrate/20150109214021_create_kaui_tenants.rb +10 -8
- data/db/migrate/20150112232813_create_kaui_allowed_users.rb +10 -8
- data/lib/generators/kaui/install/install_generator.rb +23 -20
- data/lib/generators/kaui/install/templates/config/initializers/kaui.rb +3 -1
- data/lib/kaui/engine.rb +17 -5
- data/lib/kaui/installer/installer.rb +27 -26
- data/lib/kaui/version.rb +3 -1
- data/lib/kaui.rb +28 -30
- data/lib/tasks/kaui_tasks.rake +1 -0
- metadata +136 -438
- data/app/assets/javascripts/application.js +0 -17
- data/app/assets/javascripts/kaui/bootstrap-tweaks.js +0 -172
- data/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -44
- data/app/assets/stylesheets/kaui/kaui.less +0 -21
- data/app/assets/stylesheets/kaui/timeline.less +0 -4
- data/config/initializers/asset.rb +0 -1
- data/config/initializers/kilbill-client-init.rb +0 -9
- data/db/schema.rb +0 -15
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/controllers/application_controller.rb +0 -9
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/bin/setup +0 -38
- data/test/dummy/bin/update +0 -29
- data/test/dummy/bin/yarn +0 -11
- data/test/dummy/config/application.rb +0 -18
- data/test/dummy/config/boot.rb +0 -3
- data/test/dummy/config/database.yml +0 -27
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -58
- data/test/dummy/config/environments/production.rb +0 -91
- data/test/dummy/config/environments/test.rb +0 -49
- data/test/dummy/config/initializers/application_controller_renderer.rb +0 -6
- data/test/dummy/config/initializers/assets.rb +0 -14
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/killbill_client.rb +0 -1
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/money.rb +0 -2
- data/test/dummy/config/initializers/new_framework_defaults_5_1.rb +0 -14
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -33
- data/test/dummy/config/routes.rb +0 -3
- data/test/dummy/config/secrets.yml +0 -32
- data/test/dummy/config/symmetric-encryption.yml +0 -135
- data/test/dummy/config.ru +0 -4
- data/test/dummy/db/schema.rb +0 -52
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/fixtures/SpyCarAdvanced.xml +0 -824
- data/test/fixtures/catalog-v1.xml +0 -73
- data/test/fixtures/catalog_translation_fr-v1.properties +0 -1
- data/test/fixtures/invoice_template-v1.html +0 -100
- data/test/fixtures/invoice_translation_fr-v1.properties +0 -23
- data/test/fixtures/overdue-v1.xml +0 -49
- data/test/fixtures/stripe.yml +0 -2
- data/test/functional/kaui/account_children_controller_test.rb +0 -32
- data/test/functional/kaui/account_custom_fields_controller_test.rb +0 -29
- data/test/functional/kaui/account_emails_controller_test.rb +0 -55
- data/test/functional/kaui/account_tags_controller_test.rb +0 -48
- data/test/functional/kaui/account_timelines_controller_test.rb +0 -20
- data/test/functional/kaui/accounts_controller_test.rb +0 -297
- data/test/functional/kaui/admin_allowed_users_controller_test.rb +0 -234
- data/test/functional/kaui/admin_controller_test.rb +0 -45
- data/test/functional/kaui/admin_tenants_controller_test.rb +0 -352
- data/test/functional/kaui/audit_logs_controller_test.rb +0 -71
- data/test/functional/kaui/bundle_tags_controller_test.rb +0 -23
- data/test/functional/kaui/bundles_controller_test.rb +0 -130
- data/test/functional/kaui/chargebacks_controller_test.rb +0 -42
- data/test/functional/kaui/charges_controller_test.rb +0 -60
- data/test/functional/kaui/credits_controller_test.rb +0 -54
- data/test/functional/kaui/custom_fields_controller_test.rb +0 -52
- data/test/functional/kaui/functional_test_helper.rb +0 -13
- data/test/functional/kaui/functional_test_helper_nosetup.rb +0 -120
- data/test/functional/kaui/home_controller_test.rb +0 -407
- data/test/functional/kaui/invoice_items_controller_test.rb +0 -82
- data/test/functional/kaui/invoices_controller_test.rb +0 -88
- data/test/functional/kaui/login_proxy_controller_test.rb +0 -12
- data/test/functional/kaui/payment_methods_controller_test.rb +0 -52
- data/test/functional/kaui/payments_controller_test.rb +0 -59
- data/test/functional/kaui/queues_controller_test.rb +0 -17
- data/test/functional/kaui/refunds_controller_test.rb +0 -63
- data/test/functional/kaui/registrations_controller_test.rb +0 -49
- data/test/functional/kaui/role_definitions_controller_test.rb +0 -47
- data/test/functional/kaui/subscriptions_controller_test.rb +0 -194
- data/test/functional/kaui/tag_definitions_controller_test.rb +0 -29
- data/test/functional/kaui/tags_controller_test.rb +0 -21
- data/test/functional/kaui/tenants_controller_test.rb +0 -60
- data/test/functional/kaui/transactions_controller_test.rb +0 -90
- data/test/integration/kaui/date_helper_integration_test.rb +0 -16
- data/test/integration/kaui/integration_test_helper.rb +0 -32
- data/test/integration/kaui/navigation_test.rb +0 -43
- data/test/killbill_test_helper.rb +0 -219
- data/test/test_helper.rb +0 -22
- data/test/unit/helpers/kaui/admin_allowed_users_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/admin_tenants_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/payment_method_helper_test.rb +0 -17
- data/test/unit/helpers/kaui/tenants_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/uuid_helper_test.rb +0 -16
- data/test/unit/kaui/account_email_test.rb +0 -19
- data/test/unit/kaui/account_test.rb +0 -14
- data/test/unit/kaui/admin_tenant_test.rb +0 -132
- data/test/unit/kaui/allowed_user_test.rb +0 -34
- data/test/unit/kaui/base_test.rb +0 -23
- data/test/unit/kaui/date_helper_test.rb +0 -26
- data/test/unit/kaui/invoice_item_test.rb +0 -11
- data/test/unit/kaui/invoice_payment_test.rb +0 -42
- data/test/unit/kaui/invoice_test.rb +0 -20
- data/test/unit/kaui/money_helper_test.rb +0 -16
- data/test/unit/kaui/payment_test.rb +0 -42
- data/test/unit/kaui/tag_definition_test.rb +0 -11
- data/test/unit/kaui/tenant_test.rb +0 -19
- /data/app/assets/stylesheets/{application.css → kaui_application.css} +0 -0
@@ -1,509 +1,555 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
module Kaui
|
4
|
+
class AdminTenantsController < Kaui::EngineController
|
5
|
+
skip_before_action :check_for_redirect_to_tenant_screen
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def new
|
12
|
-
@tenant = Kaui::Tenant.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def create
|
16
|
-
param_tenant = params[:tenant]
|
7
|
+
def index
|
8
|
+
# Display the configured tenants in KAUI (which could be different than the existing tenants known by Kill Bill)
|
9
|
+
tenants_for_current_user = retrieve_tenants_for_current_user
|
10
|
+
@tenants = Kaui::Tenant.all.select { |tenant| tenants_for_current_user.include?(tenant.kb_tenant_id) }
|
11
|
+
end
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
old_tenant.kaui_allowed_users << Kaui::AllowedUser.where(:kb_username => current_user.kb_username).first_or_create
|
21
|
-
redirect_to admin_tenant_path(old_tenant[:id]), :notice => 'Tenant was successfully configured' and return
|
13
|
+
def new
|
14
|
+
@tenant = Kaui::Tenant.new
|
22
15
|
end
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
def create
|
18
|
+
param_tenant = params[:tenant]
|
19
|
+
|
20
|
+
old_tenant = Kaui::Tenant.find_by_name(param_tenant[:name]) || Kaui::Tenant.find_by_api_key(param_tenant[:api_key])
|
21
|
+
if old_tenant
|
22
|
+
old_tenant.kaui_allowed_users << Kaui::AllowedUser.where(kb_username: current_user.kb_username).first_or_create
|
23
|
+
redirect_to admin_tenant_path(old_tenant[:id]), notice: 'Tenant was successfully configured' and return
|
24
|
+
end
|
27
25
|
|
28
26
|
begin
|
29
|
-
options
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
27
|
+
options = tenant_options_for_client
|
28
|
+
new_tenant = nil
|
29
|
+
|
30
|
+
begin
|
31
|
+
options[:api_key] = param_tenant[:api_key]
|
32
|
+
options[:api_secret] = param_tenant[:api_secret]
|
33
|
+
new_tenant = Kaui::AdminTenant.find_by_api_key(param_tenant[:api_key], options)
|
34
|
+
rescue KillBillClient::API::Unauthorized, KillBillClient::API::NotFound
|
35
|
+
# Create the tenant in Kill Bill
|
36
|
+
new_tenant = Kaui::AdminTenant.new
|
37
|
+
new_tenant.external_key = param_tenant[:name]
|
38
|
+
new_tenant.api_key = param_tenant[:api_key]
|
39
|
+
new_tenant.api_secret = param_tenant[:api_secret]
|
40
|
+
new_tenant = new_tenant.create(false, options[:username], nil, comment, options)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Transform object to Kaui model
|
44
|
+
tenant_model = Kaui::Tenant.new
|
45
|
+
tenant_model.name = param_tenant[:name]
|
46
|
+
tenant_model.api_key = param_tenant[:api_key]
|
47
|
+
tenant_model.api_secret = param_tenant[:api_secret]
|
48
|
+
tenant_model.kb_tenant_id = new_tenant.tenant_id
|
49
|
+
|
50
|
+
# Save in KAUI tables
|
51
|
+
tenant_model.save!
|
52
|
+
# Make sure at least the current user can access the tenant
|
53
|
+
tenant_model.kaui_allowed_users << Kaui::AllowedUser.where(kb_username: current_user.kb_username).first_or_create
|
54
|
+
rescue KillBillClient::API::Conflict => _e
|
55
|
+
# tenant api_key was found but has a wrong api_secret
|
56
|
+
flash[:error] = "Submitted credentials for #{param_tenant[:api_key]} did not match the expected credentials."
|
57
|
+
redirect_to admin_tenants_path and return
|
58
|
+
rescue StandardError => e
|
59
|
+
flash[:error] = "Failed to create the tenant: #{as_string(e)}"
|
60
|
+
redirect_to admin_tenants_path and return
|
40
61
|
end
|
41
62
|
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
tenant_model
|
48
|
-
|
49
|
-
# Save in KAUI tables
|
50
|
-
tenant_model.save!
|
51
|
-
# Make sure at least the current user can access the tenant
|
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
|
57
|
-
rescue => e
|
58
|
-
flash[:error] = "Failed to create the tenant: #{as_string(e)}"
|
59
|
-
redirect_to admin_tenants_path and return
|
63
|
+
# Select the tenant, see TenantsController
|
64
|
+
session[:kb_tenant_id] = tenant_model.kb_tenant_id
|
65
|
+
session[:kb_tenant_name] = tenant_model.name
|
66
|
+
session[:tenant_id] = tenant_model.id
|
67
|
+
|
68
|
+
redirect_to admin_tenant_path(tenant_model[:id]), notice: 'Tenant was successfully configured'
|
60
69
|
end
|
61
70
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
session[:tenant_id] = tenant_model.id
|
71
|
+
def show
|
72
|
+
@tenant = safely_find_tenant_by_id(params[:id])
|
73
|
+
@allowed_users = @tenant.kaui_allowed_users & retrieve_allowed_users_for_current_user
|
66
74
|
|
67
|
-
|
68
|
-
end
|
75
|
+
configure_tenant_if_nil(@tenant)
|
69
76
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
set_tenant_if_nil(@tenant)
|
77
|
+
options = tenant_options_for_client
|
78
|
+
options[:api_key] = @tenant.api_key
|
79
|
+
options[:api_secret] = @tenant.api_secret
|
75
80
|
|
76
|
-
|
77
|
-
|
78
|
-
|
81
|
+
fetch_catalog_versions = promise do
|
82
|
+
Kaui::Catalog.get_tenant_catalog_versions(nil, options)
|
83
|
+
rescue StandardError
|
84
|
+
@catalog_versions = []
|
85
|
+
end
|
86
|
+
fetch_overdue = promise do
|
87
|
+
Kaui::Overdue.get_overdue_json(options)
|
88
|
+
rescue StandardError
|
89
|
+
@overdue = nil
|
90
|
+
end
|
91
|
+
fetch_overdue_xml = promise do
|
92
|
+
Kaui::Overdue.get_tenant_overdue_config(options)
|
93
|
+
rescue StandardError
|
94
|
+
@overdue_xml = nil
|
95
|
+
end
|
79
96
|
|
80
|
-
|
81
|
-
fetch_overdue = promise { Kaui::Overdue::get_overdue_json(options) rescue @overdue = nil }
|
82
|
-
fetch_overdue_xml = promise { Kaui::Overdue::get_tenant_overdue_config('xml', options) rescue @overdue_xml = nil }
|
97
|
+
fetch_tenant_plugin_config = promise { Kaui::AdminTenant.get_tenant_plugin_config(options) }
|
83
98
|
|
84
|
-
|
99
|
+
@catalog_versions = []
|
100
|
+
wait(fetch_catalog_versions).each_with_index do |effective_date, idx|
|
101
|
+
@catalog_versions << { version: idx,
|
102
|
+
version_date: effective_date }
|
103
|
+
end
|
85
104
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
105
|
+
@latest_version = begin
|
106
|
+
@catalog_versions[@catalog_versions.length - 1][:version_date]
|
107
|
+
rescue StandardError
|
108
|
+
nil
|
109
|
+
end
|
91
110
|
|
92
|
-
|
111
|
+
@overdue = wait(fetch_overdue)
|
112
|
+
@overdue_xml = wait(fetch_overdue_xml)
|
113
|
+
@tenant_plugin_config = begin
|
114
|
+
wait(fetch_tenant_plugin_config)
|
115
|
+
rescue StandardError
|
116
|
+
''
|
117
|
+
end
|
93
118
|
|
94
|
-
|
95
|
-
|
96
|
-
|
119
|
+
# When reloading page from the view, it sends the last tab that was active
|
120
|
+
@active_tab = params[:active_tab] || 'CatalogShow'
|
121
|
+
end
|
97
122
|
|
98
|
-
|
99
|
-
|
100
|
-
end
|
123
|
+
def upload_catalog
|
124
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
101
125
|
|
102
|
-
|
103
|
-
|
126
|
+
options = tenant_options_for_client
|
127
|
+
options[:api_key] = current_tenant.api_key
|
128
|
+
options[:api_secret] = current_tenant.api_secret
|
104
129
|
|
105
|
-
|
106
|
-
|
107
|
-
options[:api_secret] = current_tenant.api_secret
|
130
|
+
uploaded_catalog = params.require(:catalog)
|
131
|
+
catalog_xml = uploaded_catalog.read
|
108
132
|
|
109
|
-
|
110
|
-
catalog_xml = uploaded_catalog.read
|
133
|
+
Kaui::AdminTenant.upload_catalog(catalog_xml, options[:username], nil, comment, options)
|
111
134
|
|
112
|
-
|
135
|
+
redirect_to admin_tenant_path(current_tenant.id), notice: I18n.translate('flashes.notices.catalog_uploaded_successfully')
|
136
|
+
end
|
113
137
|
|
114
|
-
|
115
|
-
|
138
|
+
def new_catalog
|
139
|
+
options = tenant_options_for_client
|
140
|
+
fetch_state_for_new_catalog_screen(options)
|
141
|
+
@simple_plan = Kaui::SimplePlan.new({
|
142
|
+
product_category: 'BASE',
|
143
|
+
amount: 0,
|
144
|
+
trial_length: 0,
|
145
|
+
currency: 'USD',
|
146
|
+
billing_period: 'MONTHLY'
|
147
|
+
})
|
148
|
+
end
|
116
149
|
|
117
|
-
|
118
|
-
|
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
|
-
})
|
127
|
-
end
|
150
|
+
def delete_catalog
|
151
|
+
tenant = safely_find_tenant_by_id(params[:id])
|
128
152
|
|
129
|
-
|
130
|
-
|
153
|
+
options = tenant_options_for_client
|
154
|
+
options[:api_key] = tenant.api_key
|
155
|
+
options[:api_secret] = tenant.api_secret
|
131
156
|
|
132
|
-
|
133
|
-
|
134
|
-
|
157
|
+
begin
|
158
|
+
Kaui::Catalog.delete_catalog(options[:username], 'KAUI wrong catalog', comment, options)
|
159
|
+
rescue NoMethodError => _e
|
160
|
+
flash[:error] = 'Failed to delete catalog: only available in KB 0.19+ versions'
|
161
|
+
redirect_to admin_tenants_path and return
|
162
|
+
end
|
135
163
|
|
136
|
-
|
137
|
-
Kaui::Catalog.delete_catalog(options[:username], 'KAUI wrong catalog', comment, options)
|
138
|
-
rescue NoMethodError => _
|
139
|
-
flash[:error] = 'Failed to delete catalog: only available in KB 0.19+ versions'
|
140
|
-
redirect_to admin_tenants_path and return
|
164
|
+
redirect_to admin_tenant_path(tenant.id), notice: 'Catalog was successfully deleted'
|
141
165
|
end
|
142
166
|
|
143
|
-
|
144
|
-
|
167
|
+
def new_plan_currency
|
168
|
+
@tenant = safely_find_tenant_by_id(params[:id])
|
145
169
|
|
146
|
-
|
147
|
-
|
170
|
+
is_plan_id_found = false
|
171
|
+
plan_id = params[:plan_id]
|
148
172
|
|
149
|
-
|
150
|
-
|
173
|
+
options = tenant_options_for_client
|
174
|
+
options[:api_key] = @tenant.api_key
|
175
|
+
options[:api_secret] = @tenant.api_secret
|
151
176
|
|
152
|
-
|
153
|
-
options[:api_key] = @tenant.api_key
|
154
|
-
options[:api_secret] = @tenant.api_secret
|
177
|
+
catalog = Kaui::Catalog.get_catalog_json(true, nil, options)
|
155
178
|
|
156
|
-
|
179
|
+
# seek if plan id exists
|
180
|
+
catalog.products.each do |product|
|
181
|
+
product.plans.each { |plan| is_plan_id_found |= plan.name == plan_id }
|
182
|
+
break if is_plan_id_found
|
183
|
+
end
|
157
184
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
end
|
185
|
+
unless is_plan_id_found
|
186
|
+
flash[:error] = "Plan id #{plan_id} was not found."
|
187
|
+
redirect_to admin_tenant_path(@tenant[:id])
|
188
|
+
end
|
163
189
|
|
164
|
-
|
165
|
-
|
166
|
-
redirect_to admin_tenant_path(@tenant[:id])
|
190
|
+
@simple_plan = Kaui::SimplePlan.new
|
191
|
+
@simple_plan.plan_id = params[:plan_id]
|
167
192
|
end
|
168
193
|
|
169
|
-
|
170
|
-
|
171
|
-
|
194
|
+
def create_simple_plan
|
195
|
+
options = tenant_options_for_client
|
196
|
+
fetch_state_for_new_catalog_screen(options)
|
197
|
+
|
198
|
+
simple_plan = params.require(:simple_plan).delete_if { |_e, value| value.blank? }
|
199
|
+
# Fix issue in Rails where first entry in the multi-select array is an empty string
|
200
|
+
simple_plan['available_base_products']&.reject!(&:blank?)
|
201
|
+
|
202
|
+
@simple_plan = Kaui::SimplePlan.new(simple_plan)
|
203
|
+
|
204
|
+
valid = true
|
205
|
+
# Validate new simple plan
|
206
|
+
# https://github.com/killbill/killbill-admin-ui/issues/247
|
207
|
+
if @available_base_products.include?(@simple_plan.plan_id)
|
208
|
+
flash.now[:error] = "Error while creating plan: invalid plan name (#{@simple_plan.plan_id} is a BASE product already)"
|
209
|
+
valid = false
|
210
|
+
elsif @available_ao_products.include?(@simple_plan.plan_id)
|
211
|
+
flash.now[:error] = "Error while creating plan: invalid plan name (#{@simple_plan.plan_id} is an ADD_ON product already)"
|
212
|
+
valid = false
|
213
|
+
elsif @available_standalone_products.include?(@simple_plan.plan_id)
|
214
|
+
flash.now[:error] = "Error while creating plan: invalid plan name (#{@simple_plan.plan_id} is a STANDALONE product already)"
|
215
|
+
valid = false
|
216
|
+
elsif @all_plans.include?(@simple_plan.product_name)
|
217
|
+
flash.now[:error] = "Error while creating plan: invalid product name (#{@simple_plan.product_name} is a plan name already)"
|
218
|
+
valid = false
|
219
|
+
elsif @all_plans.include?(@simple_plan.plan_id)
|
220
|
+
flash.now[:error] = "Error while creating plan: plan #{@simple_plan.plan_id} already exists"
|
221
|
+
valid = false
|
222
|
+
elsif @available_base_products.include?(@simple_plan.product_name) && @simple_plan.product_category != 'BASE'
|
223
|
+
flash.now[:error] = "Error while creating plan: product #{@simple_plan.product_name} is a BASE product"
|
224
|
+
valid = false
|
225
|
+
elsif @available_ao_products.include?(@simple_plan.product_name) && @simple_plan.product_category != 'ADD_ON'
|
226
|
+
flash.now[:error] = "Error while creating plan: product #{@simple_plan.product_name} is an ADD_ON product"
|
227
|
+
valid = false
|
228
|
+
elsif @available_standalone_products.include?(@simple_plan.product_name) && @simple_plan.product_category != 'STANDALONE'
|
229
|
+
flash.now[:error] = "Error while creating plan: product #{@simple_plan.product_name} is a STANDALONE product"
|
230
|
+
valid = false
|
231
|
+
end
|
172
232
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
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
|
233
|
+
if valid
|
234
|
+
begin
|
235
|
+
Kaui::Catalog.add_tenant_catalog_simple_plan(@simple_plan, options[:username], nil, comment, options)
|
236
|
+
redirect_to admin_tenant_path(@tenant.id), notice: 'Catalog plan was successfully added'
|
237
|
+
rescue StandardError => e
|
238
|
+
flash.now[:error] = "Error while creating plan: #{as_string(e)}"
|
239
|
+
render action: :new_catalog
|
240
|
+
end
|
241
|
+
else
|
242
|
+
render action: :new_catalog
|
243
|
+
end
|
210
244
|
end
|
211
245
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
end
|
220
|
-
else
|
221
|
-
render :action => :new_catalog
|
246
|
+
def new_overdue_config
|
247
|
+
@tenant = safely_find_tenant_by_id(params[:id])
|
248
|
+
|
249
|
+
options = tenant_options_for_client
|
250
|
+
options[:api_key] = @tenant.api_key
|
251
|
+
options[:api_secret] = @tenant.api_secret
|
252
|
+
@overdue = Kaui::Overdue.get_overdue_json(options)
|
222
253
|
end
|
223
|
-
end
|
224
254
|
|
225
|
-
|
226
|
-
|
255
|
+
def modify_overdue_config
|
256
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
227
257
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
@overdue = Kaui::Overdue::get_overdue_json(options)
|
232
|
-
end
|
258
|
+
options = tenant_options_for_client
|
259
|
+
options[:api_key] = current_tenant.api_key
|
260
|
+
options[:api_secret] = current_tenant.api_secret
|
233
261
|
|
234
|
-
|
235
|
-
|
262
|
+
view_form_model = params.require(:kill_bill_client_model_overdue).delete_if { |_e, value| value.blank? }
|
263
|
+
view_form_model['states'] = view_form_model['states'].values unless view_form_model['states'].blank?
|
236
264
|
|
237
|
-
|
238
|
-
|
239
|
-
|
265
|
+
overdue = Kaui::Overdue.from_overdue_form_model(view_form_model)
|
266
|
+
Kaui::Overdue.upload_tenant_overdue_config_json(overdue.to_json, options[:username], nil, comment, options)
|
267
|
+
redirect_to admin_tenant_path(current_tenant.id, active_tab: 'OverdueShow'), notice: I18n.translate('flashes.notices.overdue_added_successfully')
|
268
|
+
end
|
240
269
|
|
241
|
-
|
242
|
-
|
270
|
+
def upload_overdue_config
|
271
|
+
uploaded_overdue_config = params.require(:overdue)
|
272
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
243
273
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
end
|
274
|
+
options = tenant_options_for_client
|
275
|
+
options[:api_key] = current_tenant.api_key
|
276
|
+
options[:api_secret] = current_tenant.api_secret
|
248
277
|
|
249
|
-
|
250
|
-
current_tenant = safely_find_tenant_by_id(params[:id])
|
278
|
+
overdue_config_xml = uploaded_overdue_config.read
|
251
279
|
|
252
|
-
|
253
|
-
|
254
|
-
|
280
|
+
begin
|
281
|
+
Nokogiri::XML(overdue_config_xml, &:strict)
|
282
|
+
rescue Nokogiri::XML::SyntaxError => e
|
283
|
+
flash[:error] = I18n.translate('errors.messages.invalid_xml', error: e)
|
284
|
+
redirect_to admin_tenant_path(current_tenant.id) and return
|
285
|
+
end
|
255
286
|
|
256
|
-
|
257
|
-
overdue_config_xml = uploaded_overdue_config.read
|
287
|
+
Kaui::AdminTenant.upload_overdue_config(overdue_config_xml, options[:username], nil, comment, options)
|
258
288
|
|
259
|
-
|
289
|
+
redirect_to admin_tenant_path(current_tenant.id, active_tab: 'OverdueShow'), notice: I18n.translate('flashes.notices.overdue_uploaded_successfully')
|
290
|
+
end
|
260
291
|
|
261
|
-
|
262
|
-
|
292
|
+
def upload_invoice_template
|
293
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
263
294
|
|
264
|
-
|
265
|
-
|
295
|
+
options = tenant_options_for_client
|
296
|
+
options[:api_key] = current_tenant.api_key
|
297
|
+
options[:api_secret] = current_tenant.api_secret
|
266
298
|
|
267
|
-
|
268
|
-
|
269
|
-
|
299
|
+
is_manual_pay = params[:manual_pay]
|
300
|
+
uploaded_invoice_template = params.require(:invoice_template)
|
301
|
+
invoice_template = uploaded_invoice_template.read
|
270
302
|
|
271
|
-
|
272
|
-
uploaded_invoice_template = params[:invoice_template]
|
273
|
-
invoice_template = uploaded_invoice_template.read
|
303
|
+
Kaui::AdminTenant.upload_invoice_template(invoice_template, is_manual_pay, true, options[:username], nil, comment, options)
|
274
304
|
|
275
|
-
|
305
|
+
redirect_to admin_tenant_path(current_tenant.id), notice: I18n.translate('flashes.notices.invoice_template_uploaded_successfully')
|
306
|
+
end
|
276
307
|
|
277
|
-
|
278
|
-
|
308
|
+
def upload_invoice_translation
|
309
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
279
310
|
|
280
|
-
|
281
|
-
|
311
|
+
options = tenant_options_for_client
|
312
|
+
options[:api_key] = current_tenant.api_key
|
313
|
+
options[:api_secret] = current_tenant.api_secret
|
282
314
|
|
283
|
-
|
284
|
-
|
285
|
-
|
315
|
+
locale = params[:translation_locale]
|
316
|
+
uploaded_invoice_translation = params.require(:invoice_translation)
|
317
|
+
invoice_translation = uploaded_invoice_translation.read
|
286
318
|
|
287
|
-
|
288
|
-
uploaded_invoice_translation = params[:invoice_translation]
|
289
|
-
invoice_translation = uploaded_invoice_translation.read
|
319
|
+
Kaui::AdminTenant.upload_invoice_translation(invoice_translation, locale, true, options[:username], nil, comment, options)
|
290
320
|
|
291
|
-
|
321
|
+
redirect_to admin_tenant_path(current_tenant.id), notice: I18n.translate('flashes.notices.invoice_translation_uploaded_successfully')
|
322
|
+
end
|
292
323
|
|
293
|
-
|
294
|
-
|
324
|
+
def upload_catalog_translation
|
325
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
295
326
|
|
296
|
-
|
297
|
-
|
327
|
+
options = tenant_options_for_client
|
328
|
+
options[:api_key] = current_tenant.api_key
|
329
|
+
options[:api_secret] = current_tenant.api_secret
|
298
330
|
|
299
|
-
|
300
|
-
|
301
|
-
|
331
|
+
locale = params[:translation_locale]
|
332
|
+
uploaded_catalog_translation = params.require(:catalog_translation)
|
333
|
+
catalog_translation = uploaded_catalog_translation.read
|
302
334
|
|
303
|
-
|
304
|
-
uploaded_catalog_translation = params[:catalog_translation]
|
305
|
-
catalog_translation = uploaded_catalog_translation.read
|
335
|
+
Kaui::AdminTenant.upload_catalog_translation(catalog_translation, locale, true, options[:username], nil, comment, options)
|
306
336
|
|
307
|
-
|
337
|
+
redirect_to admin_tenant_path(current_tenant.id), notice: I18n.translate('flashes.notices.catalog_translation_uploaded_successfully')
|
338
|
+
end
|
308
339
|
|
309
|
-
|
310
|
-
|
340
|
+
def upload_plugin_config
|
341
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
311
342
|
|
312
|
-
|
313
|
-
|
343
|
+
options = tenant_options_for_client
|
344
|
+
options[:api_key] = current_tenant.api_key
|
345
|
+
options[:api_secret] = current_tenant.api_secret
|
314
346
|
|
315
|
-
|
316
|
-
|
317
|
-
|
347
|
+
plugin_name = params[:plugin_name]
|
348
|
+
plugin_properties = params[:plugin_properties]
|
349
|
+
plugin_type = params[:plugin_type]
|
350
|
+
plugin_key = params[:plugin_key]
|
318
351
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
352
|
+
if plugin_properties.blank?
|
353
|
+
flash[:error] = 'Plugin properties cannot be blank'
|
354
|
+
elsif plugin_name.blank?
|
355
|
+
flash[:error] = 'Plugin name cannot be blank'
|
356
|
+
else
|
357
|
+
plugin_config = Kaui::AdminTenant.format_plugin_config(plugin_key, plugin_type, plugin_properties)
|
323
358
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
flash[:error] = 'Plugin name cannot be blank'
|
328
|
-
else
|
329
|
-
plugin_config = Kaui::AdminTenant.format_plugin_config(plugin_key, plugin_type, plugin_properties)
|
359
|
+
Kaui::AdminTenant.upload_tenant_plugin_config(plugin_name, plugin_config, options[:username], nil, comment, options)
|
360
|
+
flash[:notice] = 'Config for plugin was successfully uploaded'
|
361
|
+
end
|
330
362
|
|
331
|
-
|
332
|
-
flash[:notice] = 'Config for plugin was successfully uploaded'
|
363
|
+
redirect_to admin_tenant_path(current_tenant.id, active_tab: 'PluginConfig')
|
333
364
|
end
|
334
365
|
|
335
|
-
|
336
|
-
|
366
|
+
def remove_allowed_user
|
367
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
368
|
+
au = Kaui::AllowedUser.find(params.require(:allowed_user).require(:id))
|
337
369
|
|
338
|
-
|
339
|
-
|
340
|
-
|
370
|
+
unless current_user.root?
|
371
|
+
render json: { alert: 'Only the root user can remove users from tenants' }.to_json, status: 401
|
372
|
+
return
|
373
|
+
end
|
341
374
|
|
342
|
-
|
343
|
-
|
344
|
-
|
375
|
+
# remove the association
|
376
|
+
au.kaui_tenants.delete current_tenant
|
377
|
+
render json: '{}', status: 200
|
345
378
|
end
|
346
379
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
end
|
380
|
+
def add_allowed_user
|
381
|
+
current_tenant = safely_find_tenant_by_id(params[:tenant_id])
|
382
|
+
allowed_user = Kaui::AllowedUser.find_by_kb_username(params.require(:allowed_user).require(:kb_username))
|
351
383
|
|
352
|
-
|
353
|
-
|
354
|
-
|
384
|
+
unless current_user.root?
|
385
|
+
flash[:error] = 'Only the root user can add users from tenants'
|
386
|
+
redirect_to admin_tenant_path(current_tenant.id)
|
387
|
+
return
|
388
|
+
end
|
355
389
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
390
|
+
if allowed_user.nil?
|
391
|
+
flash[:error] = "User #{params.require(:allowed_user).require(:kb_username)} does not exist!"
|
392
|
+
redirect_to admin_tenant_path(current_tenant.id)
|
393
|
+
return
|
394
|
+
end
|
361
395
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
396
|
+
tenants_ids = allowed_user.kaui_tenants.map(&:id) || []
|
397
|
+
tenants_ids << current_tenant.id
|
398
|
+
allowed_user.kaui_tenant_ids = tenants_ids
|
399
|
+
redirect_to admin_tenant_path(current_tenant.id), notice: 'Allowed user was successfully added'
|
366
400
|
end
|
367
401
|
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
end
|
402
|
+
def allowed_users
|
403
|
+
json_response do
|
404
|
+
tenant = safely_find_tenant_by_id(params[:tenant_id])
|
405
|
+
actual_allowed_users = tenant.kaui_allowed_users.map(&:id)
|
373
406
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
actual_allowed_users = tenant.kaui_allowed_users.map {|au| au.id}
|
407
|
+
retrieve_allowed_users_for_current_user.reject { |au| actual_allowed_users.include? au.id }
|
408
|
+
end
|
409
|
+
end
|
378
410
|
|
379
|
-
|
411
|
+
def display_catalog_xml
|
412
|
+
catalog_xml = fetch_catalog_xml(params[:id], params.require(:effective_date))
|
413
|
+
render xml: catalog_xml
|
380
414
|
end
|
381
|
-
end
|
382
415
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
416
|
+
def download_catalog_xml
|
417
|
+
effective_date = params.require(:effective_date)
|
418
|
+
catalog_xml = fetch_catalog_xml(params[:id], effective_date)
|
419
|
+
send_data catalog_xml, filename: "catalog_#{effective_date}.xml", type: :xml
|
420
|
+
end
|
387
421
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
send_data catalog_xml, filename: "catalog_#{effective_date}.xml", type: :xml
|
392
|
-
end
|
422
|
+
def display_overdue_xml
|
423
|
+
render xml: params.require(:xml)
|
424
|
+
end
|
393
425
|
|
394
|
-
|
395
|
-
|
396
|
-
|
426
|
+
def catalog_by_effective_date
|
427
|
+
json_response do
|
428
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
429
|
+
effective_date = params.require(:effective_date)
|
397
430
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
effective_date = params.require(:effective_date)
|
431
|
+
options = tenant_options_for_client
|
432
|
+
options[:api_key] = current_tenant.api_key
|
433
|
+
options[:api_secret] = current_tenant.api_secret
|
402
434
|
|
403
|
-
|
404
|
-
|
405
|
-
|
435
|
+
catalog = []
|
436
|
+
result = begin
|
437
|
+
Kaui::Catalog.get_catalog_json(false, effective_date, options)
|
438
|
+
rescue StandardError
|
439
|
+
catalog = []
|
440
|
+
end
|
406
441
|
|
407
|
-
|
408
|
-
|
442
|
+
# convert result to a full hash since dynamic attributes of a class are ignored when converting to json
|
443
|
+
result.each do |data|
|
444
|
+
plans = []
|
445
|
+
data[:plans].each do |plan|
|
446
|
+
plans << plan.instance_variables.each_with_object({}) { |var, hash_plan| hash_plan[var.to_s.delete('@')] = plan.instance_variable_get(var) }
|
447
|
+
end
|
409
448
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
data[:plans].each do |plan|
|
414
|
-
plans << plan.instance_variables.each_with_object({}) {|var, hash_plan| hash_plan[var.to_s.delete("@")] = plan.instance_variable_get(var) }
|
449
|
+
catalog << { version_date: data[:version_date],
|
450
|
+
currencies: data[:currencies],
|
451
|
+
plans: }
|
415
452
|
end
|
416
453
|
|
417
|
-
catalog
|
418
|
-
:currencies => data[:currencies],
|
419
|
-
:plans => plans
|
420
|
-
}
|
454
|
+
{ catalog: }
|
421
455
|
end
|
422
|
-
|
423
|
-
{:catalog => catalog }
|
424
456
|
end
|
425
|
-
end
|
426
|
-
|
427
|
-
def switch_tenant
|
428
|
-
tenant = Kaui::Tenant.find_by_kb_tenant_id(params.require(:kb_tenant_id))
|
429
|
-
|
430
|
-
# Select the tenant, see TenantsController
|
431
|
-
session[:kb_tenant_id] = tenant.kb_tenant_id
|
432
|
-
session[:kb_tenant_name] = tenant.name
|
433
|
-
session[:tenant_id] = tenant.id
|
434
|
-
|
435
|
-
redirect_to admin_tenant_path(tenant.id), :notice => "Tenant was switched to #{tenant.name}"
|
436
|
-
end
|
437
457
|
|
438
|
-
|
458
|
+
def switch_tenant
|
459
|
+
tenant = Kaui::Tenant.find_by_kb_tenant_id(params.require(:kb_tenant_id))
|
439
460
|
|
440
|
-
|
441
|
-
|
442
|
-
|
461
|
+
# Select the tenant, see TenantsController
|
462
|
+
session[:kb_tenant_id] = tenant.kb_tenant_id
|
463
|
+
session[:kb_tenant_name] = tenant.name
|
464
|
+
session[:tenant_id] = tenant.id
|
443
465
|
|
444
|
-
|
445
|
-
|
466
|
+
redirect_to admin_tenant_path(tenant.id), notice: "Tenant was switched to #{tenant.name}"
|
467
|
+
end
|
446
468
|
|
447
|
-
|
448
|
-
|
469
|
+
private
|
470
|
+
|
471
|
+
# Share code to handle render on error
|
472
|
+
def fetch_state_for_new_catalog_screen(options)
|
473
|
+
@tenant = safely_find_tenant_by_id(params[:id])
|
474
|
+
|
475
|
+
options[:api_key] = @tenant.api_key
|
476
|
+
options[:api_secret] = @tenant.api_secret
|
477
|
+
|
478
|
+
latest_catalog = Kaui::Catalog.get_catalog_json(true, nil, options)
|
479
|
+
@all_plans = latest_catalog ? (latest_catalog.products || []).map(&:plans).flatten.map(&:name) : []
|
480
|
+
|
481
|
+
@ao_mapping = Kaui::Catalog.build_ao_mapping(latest_catalog)
|
482
|
+
|
483
|
+
@available_base_products = if latest_catalog&.products
|
484
|
+
latest_catalog.products.select { |p| p.type == 'BASE' }.map(&:name)
|
485
|
+
else
|
486
|
+
[]
|
487
|
+
end
|
488
|
+
@available_ao_products = if latest_catalog&.products
|
489
|
+
latest_catalog.products.select { |p| p.type == 'ADD_ON' }.map(&:name)
|
490
|
+
else
|
491
|
+
[]
|
492
|
+
end
|
493
|
+
@available_standalone_products = if latest_catalog&.products
|
494
|
+
latest_catalog.products.select { |p| p.type == 'STANDALONE' }.map(&:name)
|
495
|
+
else
|
496
|
+
[]
|
497
|
+
end
|
498
|
+
@product_categories = %i[BASE ADD_ON STANDALONE]
|
499
|
+
@billing_period = %i[DAILY WEEKLY BIWEEKLY THIRTY_DAYS THIRTY_ONE_DAYS MONTHLY QUARTERLY BIANNUAL ANNUAL SESQUIENNIAL BIENNIAL TRIENNIAL]
|
500
|
+
@time_units = %i[UNLIMITED DAYS WEEKS MONTHS YEARS]
|
501
|
+
end
|
449
502
|
|
450
|
-
|
503
|
+
def safely_find_tenant_by_id(tenant_id)
|
504
|
+
tenant = Kaui::Tenant.find_by_id(tenant_id)
|
505
|
+
raise ActiveRecord::RecordNotFound, "Could not find tenant #{tenant_id}" unless retrieve_tenants_for_current_user.include?(tenant.kb_tenant_id)
|
451
506
|
|
452
|
-
|
453
|
-
|
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
|
507
|
+
tenant
|
508
|
+
end
|
462
509
|
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
510
|
+
def tenant_options_for_client
|
511
|
+
user = current_user
|
512
|
+
{
|
513
|
+
username: user.kb_username,
|
514
|
+
password: user.password,
|
515
|
+
session_id: user.kb_session_id
|
516
|
+
}
|
517
|
+
end
|
468
518
|
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
:username => user.kb_username,
|
473
|
-
:password => user.password,
|
474
|
-
:session_id => user.kb_session_id
|
475
|
-
}
|
476
|
-
end
|
519
|
+
def comment
|
520
|
+
'Multi-tenant Administrative operation'
|
521
|
+
end
|
477
522
|
|
478
|
-
|
479
|
-
|
480
|
-
end
|
523
|
+
def configure_tenant_if_nil(tenant)
|
524
|
+
return unless session[:kb_tenant_id].nil?
|
481
525
|
|
482
|
-
def set_tenant_if_nil(tenant)
|
483
|
-
if session[:kb_tenant_id].nil?
|
484
526
|
session[:kb_tenant_id] = tenant.kb_tenant_id
|
485
527
|
session[:kb_tenant_name] = tenant.name
|
486
528
|
session[:tenant_id] = tenant.id
|
487
529
|
end
|
488
|
-
end
|
489
530
|
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
531
|
+
def split_camel_dash_underscore_space(data)
|
532
|
+
# to_s to handle nil
|
533
|
+
data.to_s.split(/(?=[A-Z])|(?=_)|(?=-)|(?= )/).reject { |member| member.gsub(/[_-]/, '').strip.empty? }.map { |member| member.gsub(/[_-]/, '').strip.downcase }
|
534
|
+
end
|
494
535
|
|
495
|
-
|
496
|
-
|
536
|
+
def fetch_catalog_xml(tenant_id, effective_date)
|
537
|
+
current_tenant = safely_find_tenant_by_id(tenant_id)
|
497
538
|
|
498
|
-
|
499
|
-
|
500
|
-
|
539
|
+
options = tenant_options_for_client
|
540
|
+
options[:api_key] = current_tenant.api_key
|
541
|
+
options[:api_secret] = current_tenant.api_secret
|
501
542
|
|
502
|
-
|
543
|
+
response = begin
|
544
|
+
Kaui::Catalog.get_catalog_xml(effective_date, options)
|
545
|
+
rescue StandardError
|
546
|
+
{}
|
547
|
+
end
|
503
548
|
|
504
|
-
|
505
|
-
|
549
|
+
catalog_xml = {}
|
550
|
+
catalog_xml = response[0][:xml] unless response.blank?
|
506
551
|
|
507
|
-
|
552
|
+
catalog_xml
|
553
|
+
end
|
508
554
|
end
|
509
555
|
end
|