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,35 +1,38 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Kaui
|
4
|
+
class CreditsController < Kaui::EngineController
|
5
|
+
def new
|
6
|
+
invoice_id = params[:invoice_id]
|
7
|
+
amount = params[:amount]
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
if invoice_id.present?
|
10
|
+
@invoice = Kaui::Invoice.find_by_id(invoice_id, 'NONE', options_for_klient)
|
11
|
+
amount ||= @invoice.balance
|
12
|
+
currency = @invoice.currency
|
13
|
+
else
|
14
|
+
@invoice = nil
|
15
|
+
currency = params[:currency] || 'USD'
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
@credit = Kaui::Credit.new(account_id: params.require(:account_id), invoice_id:, amount:, currency:)
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
def create
|
22
|
+
credit = Kaui::Credit.new(params[:credit].delete_if { |_key, value| value.blank? })
|
23
|
+
credit.account_id ||= params.require(:account_id)
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
# No need to show the newly created invoice for account level credits
|
26
|
+
should_redirect_to_invoice = credit.invoice_id.present?
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
+
credits = credit.create(true, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
29
|
+
flash[:notice] = 'Credit was successfully created'
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
if should_redirect_to_invoice
|
32
|
+
redirect_to kaui_engine.account_invoice_path(credits[0].account_id, credits[0].invoice_id)
|
33
|
+
else
|
34
|
+
redirect_to kaui_engine.account_path(credits[0].account_id)
|
35
|
+
end
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
@@ -1,68 +1,202 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Kaui
|
4
|
+
class CustomFieldsController < Kaui::EngineController
|
5
|
+
def index
|
6
|
+
@search_query = params[:q]
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
@ordering = params[:ordering] || (@search_query.blank? ? 'desc' : 'asc')
|
9
|
+
@offset = params[:offset] || 0
|
10
|
+
@limit = params[:limit] || 50
|
9
11
|
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def pagination
|
14
|
-
searcher = lambda do |search_key, offset, limit|
|
15
|
-
Kaui::CustomField.list_or_search(search_key, offset, limit, options_for_klient)
|
12
|
+
@max_nb_records = @search_query.blank? ? Kaui::CustomField.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records : 0
|
16
13
|
end
|
17
14
|
|
18
|
-
|
19
|
-
|
15
|
+
def pagination
|
16
|
+
searcher = lambda do |search_key, offset, limit|
|
17
|
+
Kaui::CustomField.list_or_search(search_key, offset, limit, options_for_klient)
|
18
|
+
end
|
19
|
+
|
20
|
+
data_extractor = lambda do |custom_field, column|
|
21
|
+
[
|
20
22
|
custom_field.object_id,
|
21
23
|
custom_field.object_type,
|
22
24
|
custom_field.name,
|
23
25
|
custom_field.value
|
24
|
-
|
25
|
-
|
26
|
+
][column]
|
27
|
+
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
formatter = lambda do |custom_field|
|
30
|
+
url_for_object = view_context.url_for_object(custom_field.object_id, custom_field.object_type)
|
31
|
+
[
|
30
32
|
url_for_object ? view_context.link_to(custom_field.object_id, url_for_object) : custom_field.object_id,
|
31
33
|
custom_field.object_type,
|
32
34
|
custom_field.name,
|
33
35
|
custom_field.value
|
34
|
-
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
paginate searcher, data_extractor, formatter
|
35
40
|
end
|
36
41
|
|
37
|
-
|
38
|
-
|
42
|
+
def new
|
43
|
+
@custom_field = Kaui::CustomField.new
|
44
|
+
end
|
39
45
|
|
40
|
-
|
41
|
-
|
42
|
-
|
46
|
+
def check_object_exist
|
47
|
+
param_uuid = params[:uuid]
|
48
|
+
param_object_type = params[:object_type]
|
49
|
+
|
50
|
+
_check_object_exist(param_uuid, param_object_type)
|
51
|
+
end
|
43
52
|
|
44
|
-
|
45
|
-
|
53
|
+
def create
|
54
|
+
@custom_field = Kaui::CustomField.new(params.require(:custom_field))
|
46
55
|
|
47
|
-
|
56
|
+
param_uuid = @custom_field.object_id
|
57
|
+
|
58
|
+
test_uuid = nil
|
59
|
+
case @custom_field.object_type.to_sym
|
60
|
+
when :ACCOUNT
|
61
|
+
begin
|
62
|
+
test_uuid = Kaui::Account.find_by_id_or_key(param_uuid, false, false, options_for_klient)
|
63
|
+
rescue StandardError
|
64
|
+
# Ignore
|
65
|
+
end
|
66
|
+
when :BUNDLE
|
67
|
+
begin
|
68
|
+
test_uuid = Kaui::Bundle.find_by_id_or_key(param_uuid, options_for_klient)
|
69
|
+
rescue StandardError
|
70
|
+
# Ignore
|
71
|
+
end
|
72
|
+
when :SUBSCRIPTION
|
73
|
+
begin
|
74
|
+
test_uuid = Kaui::Subscription.find_by_id(param_uuid, options_for_klient)
|
75
|
+
rescue StandardError
|
76
|
+
# Ignore
|
77
|
+
end
|
78
|
+
when :INVOICE
|
79
|
+
begin
|
80
|
+
test_uuid = Kaui::Invoice.find_by_id(param_uuid, false, 'NONE', options_for_klient)
|
81
|
+
rescue StandardError
|
82
|
+
# Ignore
|
83
|
+
end
|
84
|
+
when :PAYMENT
|
85
|
+
begin
|
86
|
+
test_uuid = Kaui::InvoicePayment.find_by_id(param_uuid, false, true, options_for_klient)
|
87
|
+
rescue StandardError
|
88
|
+
# Ignore
|
89
|
+
end
|
90
|
+
begin
|
91
|
+
test_uuid = Kaui::Payment.find_by_external_key(param_uuid, false, true, options_for_klient)
|
92
|
+
rescue StandardError
|
93
|
+
# Ignore
|
94
|
+
end
|
95
|
+
when :INVOICE_ITEM
|
96
|
+
begin
|
97
|
+
test_uuid = Kaui::Invoice.find_by_invoice_item_id(param_uuid, false, 'NONE', options_for_klient)
|
98
|
+
rescue StandardError
|
99
|
+
# Ignore
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
if test_uuid.blank?
|
104
|
+
flash[:error] = I18n.translate('object_invalid_dont_exist')
|
105
|
+
redirect_to custom_fields_path
|
106
|
+
return
|
107
|
+
end
|
108
|
+
|
109
|
+
model = case @custom_field.object_type.to_sym
|
48
110
|
when :ACCOUNT
|
49
|
-
Kaui::Account.new(:
|
111
|
+
Kaui::Account.new(account_id: @custom_field.object_id)
|
50
112
|
when :BUNDLE
|
51
|
-
Kaui::Bundle.new(:
|
113
|
+
Kaui::Bundle.new(bundle_id: @custom_field.object_id)
|
52
114
|
when :SUBSCRIPTION
|
53
|
-
Kaui::Subscription.new(:
|
115
|
+
Kaui::Subscription.new(subscription_id: @custom_field.object_id)
|
54
116
|
when :INVOICE
|
55
|
-
Kaui::Invoice.new(:
|
117
|
+
Kaui::Invoice.new(invoice_id: @custom_field.object_id)
|
56
118
|
when :PAYMENT
|
57
|
-
Kaui::Payment.new(:
|
119
|
+
Kaui::Payment.new(payment_id: @custom_field.object_id)
|
58
120
|
when :INVOICE_ITEM
|
59
|
-
Kaui::InvoiceItem.new(:
|
121
|
+
Kaui::InvoiceItem.new(invoice_item_id: @custom_field.object_id)
|
60
122
|
else
|
61
|
-
flash.now[:error] =
|
123
|
+
flash.now[:error] = I18n.translate('invalid_object_type', error: @custom_field.object_type)
|
62
124
|
render :new and return
|
63
|
-
|
64
|
-
|
125
|
+
end
|
126
|
+
model.add_custom_field(@custom_field, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
127
|
+
|
128
|
+
redirect_to custom_fields_path, notice: I18n.translate('custom_field_created_success')
|
129
|
+
end
|
65
130
|
|
66
|
-
|
131
|
+
private
|
132
|
+
|
133
|
+
def _check_object_exist(uuid, object_type)
|
134
|
+
param_uuid = uuid
|
135
|
+
param_object_type = object_type
|
136
|
+
|
137
|
+
test_uuid = nil
|
138
|
+
msg = nil
|
139
|
+
case param_object_type
|
140
|
+
when 'INVOICE_ITEM'
|
141
|
+
begin
|
142
|
+
test_uuid = Kaui::Invoice.find_by_invoice_item_id(param_uuid, false, 'NONE', options_for_klient)
|
143
|
+
rescue StandardError
|
144
|
+
# Ignore
|
145
|
+
ensure
|
146
|
+
msg = { status: '200', message: I18n.translate('custom_field_uuid_exist_in_invoice_item_db') } unless test_uuid.blank?
|
147
|
+
end
|
148
|
+
when 'ACCOUNT'
|
149
|
+
begin
|
150
|
+
test_uuid = Kaui::Account.find_by_id_or_key(param_uuid, false, false, options_for_klient)
|
151
|
+
rescue StandardError
|
152
|
+
# Ignore
|
153
|
+
ensure
|
154
|
+
msg = { status: '200', message: I18n.translate('custom_field_uuid_exist_in_account_db') } if !test_uuid.blank? && (test_uuid.account_id == param_uuid)
|
155
|
+
end
|
156
|
+
when 'BUNDLE'
|
157
|
+
begin
|
158
|
+
test_uuid = Kaui::Bundle.find_by_id_or_key(param_uuid, options_for_klient)
|
159
|
+
rescue StandardError
|
160
|
+
# Ignore
|
161
|
+
ensure
|
162
|
+
msg = { status: '200', message: I18n.translate('custom_field_uuid_exist_in_bundle_db') } if !test_uuid.blank? && (test_uuid.bundle_id == param_uuid)
|
163
|
+
end
|
164
|
+
when 'SUBSCRIPTION'
|
165
|
+
begin
|
166
|
+
test_uuid = Kaui::Subscription.find_by_id(param_uuid, options_for_klient)
|
167
|
+
rescue StandardError
|
168
|
+
# Ignore
|
169
|
+
ensure
|
170
|
+
msg = { status: '200', message: I18n.translate('custom_field_uuid_exist_in_subscription_db') } if !test_uuid.blank? && (test_uuid.subscription_id == param_uuid)
|
171
|
+
end
|
172
|
+
when 'INVOICE'
|
173
|
+
begin
|
174
|
+
cached_options_for_klient = options_for_klient
|
175
|
+
test_uuid = Kaui::Invoice.find_by_id(param_uuid, 'FULL', cached_options_for_klient)
|
176
|
+
rescue StandardError
|
177
|
+
# Ignore
|
178
|
+
ensure
|
179
|
+
msg = { status: '200', message: I18n.translate('custom_field_uuid_exist_in_invoice_db') } if !test_uuid.blank? && (test_uuid.invoice_id == param_uuid)
|
180
|
+
end
|
181
|
+
when 'PAYMENT'
|
182
|
+
begin
|
183
|
+
test_uuid = Kaui::InvoicePayment.find_by_id(param_uuid, false, true, options_for_klient)
|
184
|
+
rescue StandardError
|
185
|
+
# Ignore
|
186
|
+
ensure
|
187
|
+
msg = { status: '200', message: I18n.translate('custom_field_uuid_exist_in_invoice_payment_db') } if !test_uuid.blank? && (test_uuid.payment_id == param_uuid)
|
188
|
+
end
|
189
|
+
begin
|
190
|
+
test_uuid = Kaui::Payment.find_by_external_key(param_uuid, false, true, options_for_klient)
|
191
|
+
rescue StandardError
|
192
|
+
# Ignore
|
193
|
+
ensure
|
194
|
+
msg = { status: '200', message: I18n.translate('custom_field_uuid_exist_in_payment_db') } if !test_uuid.blank? && (test_uuid.payment_id == param_uuid)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
msg ||= { status: '431', message: I18n.translate('custom_field_uuid_do_not_exist_in_db') }
|
199
|
+
render json: msg
|
200
|
+
end
|
67
201
|
end
|
68
202
|
end
|
@@ -21,13 +21,14 @@ class Kaui::EngineController < ApplicationController
|
|
21
21
|
super
|
22
22
|
end
|
23
23
|
|
24
|
+
# Called lazily by the can? helper
|
24
25
|
def current_ability
|
25
26
|
# Redefined here to namespace Ability in the correct module
|
26
27
|
@current_ability ||= Kaui::Ability.new(current_user)
|
27
28
|
end
|
28
29
|
|
29
30
|
def check_for_redirect_to_tenant_screen
|
30
|
-
unless Kaui.
|
31
|
+
unless Kaui.user_assigned_valid_tenant?(current_user, session)
|
31
32
|
session[:kb_tenant_id] = nil
|
32
33
|
redirect_to Kaui.tenant_home_path.call
|
33
34
|
end
|
@@ -1,144 +1,155 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Kaui
|
4
|
+
module EngineControllerUtil
|
5
|
+
# See DefaultPaginationSqlDaoHelper.java
|
6
|
+
SIMPLE_PAGINATION_THRESHOLD = 20_000
|
5
7
|
|
6
|
-
|
8
|
+
protected
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def paginate(searcher, data_extractor, formatter)
|
13
|
-
search_key = (params[:search] || {})[:value].presence
|
14
|
-
offset = (params[:start] || 0).to_i
|
15
|
-
limit = (params[:length] || 10).to_i
|
16
|
-
|
17
|
-
limit = -limit if params[:ordering] == 'desc'
|
18
|
-
begin
|
19
|
-
pages = searcher.call(search_key, offset, limit)
|
20
|
-
rescue => e
|
21
|
-
error = e.to_s
|
10
|
+
# rubocop:disable Lint/UselessAssignment, Naming/AccessorMethodName
|
11
|
+
def get_layout
|
12
|
+
layout ||= Kaui.config[:layout]
|
22
13
|
end
|
14
|
+
# rubocop:enable Lint/UselessAssignment, Naming/AccessorMethodName
|
15
|
+
|
16
|
+
def paginate(searcher, data_extractor, formatter)
|
17
|
+
search_key = (params[:search] || {})[:value].presence
|
18
|
+
offset = (params[:start] || 0).to_i
|
19
|
+
limit = (params[:length] || 10).to_i
|
20
|
+
|
21
|
+
limit = -limit if params[:ordering] == 'desc'
|
22
|
+
begin
|
23
|
+
pages = searcher.call(search_key, offset, limit)
|
24
|
+
rescue StandardError => e
|
25
|
+
error = e.to_s
|
26
|
+
end
|
23
27
|
|
24
|
-
|
25
|
-
:
|
28
|
+
json = {
|
29
|
+
draw: (params[:draw] || 0).to_i,
|
26
30
|
# We need to fill-in a number to make DataTables happy
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
31
|
+
recordsTotal: pages.nil? ? 0 : (pages.pagination_max_nb_records || SIMPLE_PAGINATION_THRESHOLD),
|
32
|
+
recordsFiltered: pages.nil? ? 0 : (pages.pagination_total_nb_records || SIMPLE_PAGINATION_THRESHOLD),
|
33
|
+
data: []
|
34
|
+
}
|
35
|
+
json[:error] = error unless error.nil?
|
36
|
+
|
37
|
+
pages ||= []
|
38
|
+
|
39
|
+
# Until we support server-side sorting
|
40
|
+
ordering = ((params[:order] || {})[:'0'] || {})
|
41
|
+
ordering_column = (ordering[:column] || 0).to_i
|
42
|
+
ordering_dir = ordering[:dir] || 'asc'
|
43
|
+
unless search_key.nil?
|
44
|
+
pages.sort! do |a, b|
|
45
|
+
a = data_extractor.call(a, ordering_column)
|
46
|
+
b = data_extractor.call(b, ordering_column)
|
47
|
+
sort = a <=> b
|
48
|
+
sort.nil? ? -1 : sort
|
49
|
+
end
|
50
|
+
end
|
51
|
+
pages.reverse! if (ordering_dir == 'desc' && limit >= 0) || (ordering_dir == 'asc' && limit.negative?)
|
52
|
+
|
53
|
+
pages.each { |page| json[:data] << formatter.call(page) }
|
54
|
+
|
55
|
+
respond_to do |format|
|
56
|
+
format.json { render json: }
|
57
|
+
end
|
51
58
|
end
|
52
|
-
end
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
yield
|
60
|
+
def promise(&)
|
61
|
+
# Evaluation starts immediately
|
62
|
+
::Concurrent::Promises.future do
|
63
|
+
# https://github.com/rails/rails/issues/26847
|
64
|
+
Rails.application.executor.wrap(&)
|
60
65
|
end
|
61
66
|
end
|
62
|
-
end
|
63
67
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
68
|
+
def wait(promise)
|
69
|
+
# https://github.com/rails/rails/issues/26847
|
70
|
+
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
71
|
+
# Make sure to set a timeout to avoid infinite wait
|
72
|
+
value = promise.value!(60)
|
73
|
+
raise promise.reason unless promise.reason.nil?
|
74
|
+
|
75
|
+
if value.nil? && promise.state != :fulfilled
|
76
|
+
# Could be https://github.com/ruby-concurrency/concurrent-ruby/issues/585
|
77
|
+
Rails.logger.warn("Unable to run promise #{promise_as_string(promise)}")
|
78
|
+
raise Timeout::Error
|
79
|
+
end
|
80
|
+
value
|
74
81
|
end
|
75
|
-
value
|
76
82
|
end
|
77
|
-
end
|
78
83
|
|
79
|
-
|
80
|
-
|
81
|
-
executor = promise.instance_variable_get('@executor')
|
82
|
-
executor_as_string = "queue_length=#{executor.queue_length}, pool_size=#{executor.length}"
|
83
|
-
"#{promise.instance_variable_get('@promise_body')}[state=#{promise.state}, parent=#{promise_as_string(promise.instance_variable_get('@parent'))}, executor=[#{executor_as_string}]]"
|
84
|
-
end
|
84
|
+
def promise_as_string(promise)
|
85
|
+
return 'nil' if promise.nil?
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
as_string_from_response(e.response.body)
|
90
|
-
elsif e.respond_to?(:cause) && !e.cause.nil?
|
91
|
-
as_string(e.cause)
|
92
|
-
else
|
93
|
-
log_rescue_error(e)
|
94
|
-
e.message
|
87
|
+
executor = promise.instance_variable_get('@executor')
|
88
|
+
executor_as_string = "queue_length=#{executor.queue_length}, pool_size=#{executor.length}"
|
89
|
+
"#{promise.instance_variable_get('@promise_body')}[state=#{promise.state}, parent=#{promise_as_string(promise.instance_variable_get('@parent'))}, executor=[#{executor_as_string}]]"
|
95
90
|
end
|
96
|
-
end
|
97
91
|
|
98
|
-
|
99
|
-
|
100
|
-
|
92
|
+
# Used to format flash error messages
|
93
|
+
def as_string(exception)
|
94
|
+
if exception.is_a?(KillBillClient::API::ResponseError)
|
95
|
+
as_string_from_response(exception.response.body)
|
96
|
+
elsif exception.is_a?(ActionController::ParameterMissing)
|
97
|
+
# e.message contains corrections, which we don't want
|
98
|
+
"missing parameter #{exception.param}"
|
99
|
+
elsif exception.respond_to?(:cause) && !exception.cause.nil?
|
100
|
+
as_string(exception.cause)
|
101
|
+
else
|
102
|
+
log_rescue_error(exception)
|
103
|
+
exception.message
|
104
|
+
end
|
105
|
+
end
|
101
106
|
|
102
|
-
|
103
|
-
|
104
|
-
begin
|
105
|
-
# BillingExceptionJson?
|
106
|
-
error_message = JSON.parse response
|
107
|
-
rescue => _
|
107
|
+
def log_rescue_error(error)
|
108
|
+
Rails.logger.warn "#{error.class} #{error}. #{error.backtrace.join("\n")}"
|
108
109
|
end
|
109
110
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
111
|
+
def as_string_from_response(response)
|
112
|
+
error_message = response
|
113
|
+
begin
|
114
|
+
# BillingExceptionJson?
|
115
|
+
error_message = JSON.parse response
|
116
|
+
rescue StandardError => _e
|
117
|
+
# Ignore
|
118
|
+
end
|
119
|
+
|
120
|
+
if error_message.respond_to?(:[]) && error_message['message'].present?
|
121
|
+
# Likely BillingExceptionJson
|
122
|
+
error_message = error_message['message']
|
123
|
+
error_message += " (code=#{error_message['code']})" unless error_message['code'].blank?
|
124
|
+
end
|
125
|
+
# Limit the error size to avoid ActionDispatch::Cookies::CookieOverflow
|
126
|
+
error_message[0..1000]
|
114
127
|
end
|
115
|
-
# Limit the error size to avoid ActionDispatch::Cookies::CookieOverflow
|
116
|
-
error_message[0..1000]
|
117
|
-
end
|
118
128
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
129
|
+
def nested_hash_value(obj, key)
|
130
|
+
if obj.respond_to?(:key?) && obj.key?(key)
|
131
|
+
obj[key]
|
132
|
+
elsif obj.is_a?(Hash) || obj.is_a?(Array)
|
133
|
+
r = nil
|
134
|
+
obj.find { |*a| r = nested_hash_value(a.last, key) }
|
135
|
+
r
|
136
|
+
else
|
137
|
+
nil
|
138
|
+
end
|
128
139
|
end
|
129
|
-
end
|
130
140
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
+
def json_response
|
142
|
+
begin
|
143
|
+
response = yield
|
144
|
+
response_status = 200
|
145
|
+
rescue KillBillClient::API::ResponseError => e
|
146
|
+
response = as_string_from_response(e.response.body)
|
147
|
+
response_status = e.code
|
148
|
+
rescue StandardError => e
|
149
|
+
response = e.message
|
150
|
+
response_status = 500
|
151
|
+
end
|
152
|
+
render json: response, status: response_status
|
141
153
|
end
|
142
|
-
render :json => response, :status => response_status
|
143
154
|
end
|
144
155
|
end
|