kaui 2.1.0 → 2.2.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 +130 -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 +3 -2
- 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 +7 -5
- 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 +26 -37
- data/lib/tasks/kaui_tasks.rake +1 -0
- metadata +140 -442
- 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,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kaui
|
2
4
|
module UsStatesHelper
|
5
|
+
def all_us_states
|
6
|
+
us_states_yaml_file = File.join(File.dirname(__FILE__), 'us_states_helper.yml')
|
7
|
+
states = YAML.load_file(us_states_yaml_file)
|
3
8
|
|
4
|
-
|
5
|
-
us_states_yaml_file = File.join(File.dirname(__FILE__), 'us_states_helper.yml')
|
6
|
-
states = YAML::load_file(us_states_yaml_file)
|
7
|
-
|
8
|
-
states.map { |state| [state[:state_name],state[:abbreviation]]}
|
9
|
+
states.map { |state| [state[:state_name], state[:abbreviation]] }
|
9
10
|
end
|
10
11
|
end
|
11
|
-
end
|
12
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kaui
|
2
4
|
module UuidHelper
|
3
|
-
|
4
5
|
def truncate_uuid(uuid)
|
5
6
|
return uuid unless uuid =~ /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/
|
7
|
+
|
6
8
|
split = uuid.split('-')
|
7
|
-
split[0]
|
9
|
+
"#{split[0]}-...-#{split[4]}"
|
8
10
|
end
|
9
11
|
module_function :truncate_uuid
|
10
12
|
|
@@ -12,9 +14,9 @@ module Kaui
|
|
12
14
|
content_tag(:span, truncate_uuid(object_id),
|
13
15
|
id: "#{object_id}-popover", class: 'object-id-popover', title: title,
|
14
16
|
data: {
|
15
|
-
|
16
|
-
|
17
|
-
}
|
17
|
+
id: object_id,
|
18
|
+
placement: placement
|
19
|
+
})
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
data/app/models/kaui/ability.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kaui
|
2
4
|
class Ability
|
3
5
|
include CanCan::Ability
|
@@ -14,19 +16,28 @@ module Kaui
|
|
14
16
|
# permission is something like invoice:item_adjust or payment:refund
|
15
17
|
# We rely on a naming convention where the left part refers to a Kaui model
|
16
18
|
model, action = permission_to_model_action(permission)
|
17
|
-
if model == '*'
|
19
|
+
if (model == '*') && (action == '*')
|
18
20
|
# All permissions!
|
19
21
|
can :manage, :all
|
20
|
-
elsif model == '*'
|
22
|
+
elsif (model == '*') && (action != '*')
|
21
23
|
# TODO
|
22
24
|
elsif action == '*'
|
23
|
-
# TODO Not sure the :all is really working (but we don't use it)
|
24
|
-
|
25
|
+
# TODO: Not sure the :all is really working (but we don't use it)
|
26
|
+
begin
|
27
|
+
can :all, "Kaui::#{model.camelize}".constantize
|
28
|
+
rescue StandardError
|
29
|
+
nil
|
30
|
+
end
|
25
31
|
else
|
26
|
-
|
32
|
+
begin
|
33
|
+
can action.to_sym, "Kaui::#{model.camelize}".constantize
|
34
|
+
rescue StandardError
|
35
|
+
nil
|
36
|
+
end
|
27
37
|
end
|
28
38
|
end
|
29
|
-
rescue KillBillClient::API::Unauthorized =>
|
39
|
+
rescue KillBillClient::API::Unauthorized => _e
|
40
|
+
nil
|
30
41
|
end
|
31
42
|
|
32
43
|
def permission_to_model_action(permission)
|
@@ -39,12 +50,8 @@ module Kaui
|
|
39
50
|
#
|
40
51
|
to_be_model, action = permission.split(':')
|
41
52
|
# Currently the only actions implemented for overdue and catalog (upload_config) are those implemented at the tenant level:
|
42
|
-
if %w
|
43
|
-
|
44
|
-
end
|
45
|
-
if to_be_model == 'entitlement'
|
46
|
-
to_be_model = 'subscription'
|
47
|
-
end
|
53
|
+
to_be_model = 'admin_tenant' if %w[tenant overdue catalog].include?(to_be_model)
|
54
|
+
to_be_model = 'subscription' if to_be_model == 'entitlement'
|
48
55
|
|
49
56
|
[to_be_model, action]
|
50
57
|
end
|
data/app/models/kaui/account.rb
CHANGED
@@ -1,40 +1,57 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Kaui
|
4
|
+
class Account < KillBillClient::Model::Account
|
5
|
+
attr_accessor :phone, :bill_cycle_day_local
|
6
|
+
|
7
|
+
def check_account_details_phone
|
8
|
+
return true if phone =~ /\A(?:\+?\d{1,3}\s*-?)?\(?(?:\d{3})?\)?[- ]?\d{3}[- ]?\d{4}\z/i
|
9
|
+
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_account_details_bill_cycle_day_local
|
14
|
+
return true if bill_cycle_day_local.to_i.between?(1, 31)
|
15
|
+
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.find_by_id_or_key(account_id_or_key, with_balance, with_balance_and_cba, options = {})
|
20
|
+
if account_id_or_key =~ /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/
|
8
21
|
begin
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
22
|
+
find_by_id(account_id_or_key, with_balance, with_balance_and_cba, options)
|
23
|
+
rescue StandardError => e
|
24
|
+
begin
|
25
|
+
# account_id_or_key looked like an id, but maybe it's an external key (this will happen in tests)?
|
26
|
+
find_by_external_key(account_id_or_key, with_balance, with_balance_and_cba, options)
|
27
|
+
rescue StandardError => _
|
28
|
+
# Nope - raise the initial exception
|
29
|
+
raise e
|
30
|
+
end
|
14
31
|
end
|
32
|
+
else
|
33
|
+
find_by_external_key(account_id_or_key, with_balance, with_balance_and_cba, options)
|
15
34
|
end
|
16
|
-
else
|
17
|
-
find_by_external_key(account_id_or_key, with_balance, with_balance_and_cba, options)
|
18
35
|
end
|
19
|
-
end
|
20
36
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
37
|
+
def self.list_or_search(search_key = nil, offset = 0, limit = 10, options = {})
|
38
|
+
if search_key.present?
|
39
|
+
find_in_batches_by_search_key(search_key, offset, limit, true, false, options)
|
40
|
+
else
|
41
|
+
find_in_batches(offset, limit, true, false, options)
|
42
|
+
end
|
26
43
|
end
|
27
|
-
end
|
28
44
|
|
29
|
-
|
30
|
-
|
31
|
-
|
45
|
+
def balance_to_money
|
46
|
+
Kaui::Base.to_money(account_balance.abs, currency)
|
47
|
+
end
|
32
48
|
|
33
|
-
|
34
|
-
|
35
|
-
|
49
|
+
def cba_to_money
|
50
|
+
Kaui::Base.to_money(account_cba.abs, currency)
|
51
|
+
end
|
36
52
|
|
37
|
-
|
38
|
-
|
53
|
+
def persisted?
|
54
|
+
!account_id.blank?
|
55
|
+
end
|
39
56
|
end
|
40
57
|
end
|
@@ -1,27 +1,30 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module Kaui
|
4
|
+
class AccountEmail < KillBillClient::Model::AccountEmailAttributes
|
5
|
+
def self.find_all_sorted_by_account_id(account_id, audit = 'NONE', options = {})
|
6
|
+
emails = Kaui::Account.new(account_id: account_id).emails(audit, options)
|
7
|
+
emails.map { |email| Kaui::AccountEmail.new(email.to_hash) }.sort
|
8
|
+
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def create(user = nil, reason = nil, comment = nil, options = {})
|
11
|
+
account = Kaui::Account.new(account_id: account_id)
|
12
|
+
account.add_email(email, user, reason, comment, options)
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def destroy(user = nil, reason = nil, comment = nil, options = {})
|
16
|
+
account = Kaui::Account.new(account_id: account_id)
|
17
|
+
account.remove_email(email, user, reason, comment, options)
|
18
|
+
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
def <=>(other)
|
21
|
+
if other.nil?
|
22
|
+
-1
|
23
|
+
elsif other.email.nil?
|
24
|
+
email.nil? ? 0 : 1
|
25
|
+
else
|
26
|
+
email.to_s <=> other.email.to_s
|
27
|
+
end
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
data/app/models/kaui/admin.rb
CHANGED
@@ -1,80 +1,81 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Kaui
|
4
|
+
class Admin < KillBillClient::Model::Resource
|
5
|
+
KILLBILL_API_ADMIN_PREFIX = "#{KILLBILL_API_PREFIX}/admin".freeze
|
6
|
+
KILLBILL_API_QUEUES_PREFIX = "#{KILLBILL_API_ADMIN_PREFIX}/queues".freeze
|
5
7
|
|
6
|
-
|
8
|
+
KILLBILL_API_CLOCK_PREFIX = "#{KILLBILL_API_PREFIX}/test/clock".freeze
|
7
9
|
|
8
|
-
|
10
|
+
class << self
|
11
|
+
def get_queues_entries(account_id, options = {})
|
12
|
+
res = KillBillClient::API.get KILLBILL_API_QUEUES_PREFIX,
|
13
|
+
{
|
14
|
+
accountId: account_id,
|
15
|
+
withHistory: options[:withHistory],
|
16
|
+
minDate: options[:minDate],
|
17
|
+
maxDate: options[:maxDate]
|
18
|
+
},
|
19
|
+
{
|
20
|
+
accept: 'application/octet-stream'
|
21
|
+
}.merge(options)
|
22
|
+
JSON.parse res.body
|
23
|
+
end
|
9
24
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}.merge(options)
|
21
|
-
JSON.parse res.body
|
22
|
-
end
|
23
|
-
|
24
|
-
def fix_transaction_state(payment_id, transaction_id, transaction_status, user = nil, reason = nil, comment = nil, options = {})
|
25
|
-
KillBillClient::API.put "#{KILLBILL_API_ADMIN_PREFIX}/payments/#{payment_id}/transactions/#{transaction_id}",
|
26
|
-
{:transactionStatus => transaction_status}.to_json,
|
27
|
-
{},
|
28
|
-
{
|
29
|
-
:user => user,
|
30
|
-
:reason => reason,
|
31
|
-
:comment => comment,
|
32
|
-
}.merge(options)
|
33
|
-
end
|
25
|
+
def fix_transaction_state(payment_id, transaction_id, transaction_status, user = nil, reason = nil, comment = nil, options = {})
|
26
|
+
KillBillClient::API.put "#{KILLBILL_API_ADMIN_PREFIX}/payments/#{payment_id}/transactions/#{transaction_id}",
|
27
|
+
{ transactionStatus: transaction_status }.to_json,
|
28
|
+
{},
|
29
|
+
{
|
30
|
+
user: user,
|
31
|
+
reason: reason,
|
32
|
+
comment: comment
|
33
|
+
}.merge(options)
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def get_clock(time_zone, options)
|
37
|
+
params = {}
|
38
|
+
params[:timeZone] = time_zone unless time_zone.nil?
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
res = KillBillClient::API.get KILLBILL_API_CLOCK_PREFIX,
|
41
|
+
params,
|
42
|
+
options
|
43
|
+
JSON.parse res.body
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
def set_clock(requested_date, time_zone, options)
|
47
|
+
params = {}
|
48
|
+
params[:requestedDate] = requested_date unless requested_date.nil?
|
49
|
+
params[:timeZone] = time_zone unless time_zone.nil?
|
49
50
|
|
50
|
-
|
51
|
-
|
51
|
+
# The default 5s is not always enough
|
52
|
+
params[:timeoutSec] ||= 10
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
res = KillBillClient::API.post KILLBILL_API_CLOCK_PREFIX,
|
55
|
+
{},
|
56
|
+
params,
|
57
|
+
{}.merge(options)
|
58
|
+
JSON.parse res.body
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
def increment_kb_clock(days, weeks, months, years, time_zone, options)
|
62
|
+
params = {}
|
63
|
+
params[:days] = days unless days.nil?
|
64
|
+
params[:weeks] = weeks unless weeks.nil?
|
65
|
+
params[:months] = months unless months.nil?
|
66
|
+
params[:years] = years unless years.nil?
|
67
|
+
params[:timeZone] = time_zone unless time_zone.nil?
|
67
68
|
|
68
|
-
|
69
|
-
|
69
|
+
# The default 5s is not always enough
|
70
|
+
params[:timeoutSec] ||= 10
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
res = KillBillClient::API.put KILLBILL_API_CLOCK_PREFIX,
|
73
|
+
{},
|
74
|
+
params,
|
75
|
+
{}.merge(options)
|
75
76
|
|
76
|
-
|
77
|
+
JSON.parse res.body
|
78
|
+
end
|
77
79
|
end
|
78
|
-
|
79
80
|
end
|
80
81
|
end
|
@@ -1,109 +1,108 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module Kaui
|
4
|
+
class AdminTenant < KillBillClient::Model::Tenant
|
5
|
+
class << self
|
6
|
+
def upload_catalog(catalog_xml, user = nil, reason = nil, comment = nil, options = {})
|
7
|
+
KillBillClient::Model::Catalog.upload_tenant_catalog(catalog_xml, user, reason, comment, options)
|
8
|
+
end
|
3
9
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def upload_overdue_config(overdue_config_xml, user = nil, reason = nil, comment = nil, options = {})
|
10
|
-
KillBillClient::Model::Overdue.upload_tenant_overdue_config_xml(overdue_config_xml, user, reason, comment, options)
|
11
|
-
end
|
12
|
-
|
13
|
-
def upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})
|
14
|
-
KillBillClient::Model::Invoice.upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user, reason, comment, options)
|
15
|
-
end
|
10
|
+
def upload_overdue_config(overdue_config_xml, user = nil, reason = nil, comment = nil, options = {})
|
11
|
+
KillBillClient::Model::Overdue.upload_tenant_overdue_config_xml(overdue_config_xml, user, reason, comment, options)
|
12
|
+
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
def upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})
|
15
|
+
KillBillClient::Model::Invoice.upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user, reason, comment, options)
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
def upload_invoice_translation(invoice_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})
|
19
|
+
KillBillClient::Model::Invoice.upload_invoice_translation(invoice_translation, locale, delete_if_exists, user, reason, comment, options)
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
def upload_catalog_translation(catalog_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})
|
23
|
+
KillBillClient::Model::Invoice.upload_catalog_translation(catalog_translation, locale, delete_if_exists, user, reason, comment, options)
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
def upload_tenant_plugin_config(plugin_name, plugin_config, user = nil, reason = nil, comment = nil, options = {})
|
27
|
+
KillBillClient::Model::Tenant.upload_tenant_plugin_config(plugin_name, plugin_config, user, reason, comment, options)
|
28
|
+
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
# Return a map of plugin_name => config
|
31
|
+
def get_tenant_plugin_config(options)
|
32
|
+
raw_tenant_config = KillBillClient::Model::Tenant.search_tenant_config('PLUGIN_CONFIG_', options)
|
36
33
|
|
37
|
-
|
38
|
-
|
34
|
+
raw_tenant_config.each_with_object({}) do |e, hsh|
|
35
|
+
# Strip prefix '/PLUGIN_CONFIG_'
|
36
|
+
plugin_name = e.key.gsub!(/PLUGIN_CONFIG_/, '')
|
39
37
|
|
40
|
-
|
38
|
+
# Construct simple hash with one property (first value)
|
39
|
+
hsh[plugin_name] = e.values[0]
|
40
|
+
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
43
|
+
def format_plugin_config(plugin_key, plugin_type, props)
|
44
|
+
return nil unless props.present?
|
45
|
+
return props['raw_config'].gsub(/\r\n?/, "\n") if props['raw_config']
|
46
|
+
|
47
|
+
if plugin_type == 'ruby'
|
48
|
+
require 'yaml'
|
49
|
+
props = reformat_plugin_config(plugin_type, props)
|
50
|
+
hsh = {}
|
51
|
+
hsh[plugin_key.to_sym] = {}
|
52
|
+
props.each do |k, v|
|
53
|
+
hsh[plugin_key.to_sym][k.to_sym] = v
|
54
|
+
end
|
55
|
+
hsh.to_yaml
|
56
|
+
elsif plugin_type == 'java'
|
57
|
+
props = reformat_plugin_config(plugin_type, props)
|
58
|
+
res = ''
|
59
|
+
props.each do |k, v|
|
60
|
+
res = "#{res}#{k}=#{v}\n"
|
61
|
+
end
|
62
|
+
res
|
63
|
+
else
|
64
|
+
props['raw_config']
|
57
65
|
end
|
58
|
-
hsh.to_yaml
|
59
|
-
elsif plugin_type == 'java'
|
60
|
-
props = reformat_plugin_config(plugin_type, props)
|
61
|
-
res = ""
|
62
|
-
props.each do |k, v|
|
63
|
-
res = "#{res}#{k.to_s}=#{v.to_s}\n"
|
64
|
-
end
|
65
|
-
res
|
66
|
-
else
|
67
|
-
props['raw_config']
|
68
66
|
end
|
69
|
-
end
|
70
67
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
68
|
+
def reformat_plugin_config(_plugin_type, props)
|
69
|
+
unless props['raw_config'].blank?
|
70
|
+
new_props = {}
|
71
|
+
props['raw_config'].split("\n").each do |p|
|
72
|
+
line = p.split('=')
|
73
|
+
new_props[line[0]] = line[1].blank? ? '' : line[1].delete("\r")
|
74
|
+
end
|
75
|
+
|
76
|
+
return new_props
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
props
|
80
80
|
end
|
81
81
|
|
82
|
-
|
83
|
-
|
82
|
+
# checks if string could be parse as yaml
|
83
|
+
def yaml?(candidate_string)
|
84
|
+
is_yaml = false
|
85
|
+
return is_yaml if candidate_string.blank?
|
84
86
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
87
|
+
begin
|
88
|
+
is_yaml = !YAML.load(candidate_string).nil?
|
89
|
+
is_yaml &&= YAML.load(candidate_string).instance_of?(Hash)
|
90
|
+
rescue StandardError
|
91
|
+
is_yaml = false
|
92
|
+
end
|
89
93
|
|
90
|
-
|
91
|
-
is_yaml = !!YAML::load(candidate_string)
|
92
|
-
is_yaml = is_yaml && YAML.load(candidate_string).instance_of?(Hash)
|
93
|
-
rescue
|
94
|
-
is_yaml = false
|
94
|
+
is_yaml
|
95
95
|
end
|
96
96
|
|
97
|
-
|
98
|
-
|
97
|
+
# checks if string could be parse as key value pair
|
98
|
+
def kv?(candidate_string)
|
99
|
+
return false if candidate_string.blank? || yaml?(candidate_string)
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
return false if candidate_string.blank? || is_yaml?(candidate_string)
|
103
|
-
lines = candidate_string.split("\n")
|
104
|
-
return false if lines.blank?
|
101
|
+
lines = candidate_string.split("\n")
|
102
|
+
return false if lines.blank?
|
105
103
|
|
106
|
-
|
104
|
+
lines.all? { |kv| kv.split('=').count >= 1 }
|
105
|
+
end
|
107
106
|
end
|
108
107
|
end
|
109
108
|
end
|
@@ -1,13 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kaui
|
2
4
|
class AllowedUser < ApplicationRecord
|
3
|
-
|
4
5
|
has_many :kaui_allowed_user_tenants,
|
5
|
-
:
|
6
|
-
:
|
6
|
+
class_name: 'Kaui::AllowedUserTenant',
|
7
|
+
foreign_key: 'kaui_allowed_user_id'
|
7
8
|
|
8
9
|
has_many :kaui_tenants, -> { distinct },
|
9
|
-
:
|
10
|
-
:
|
10
|
+
through: :kaui_allowed_user_tenants,
|
11
|
+
source: :kaui_tenant
|
11
12
|
|
12
13
|
# Create the user locally and in Kill Bill (if needed)
|
13
14
|
def create_in_kb!(password, roles = [], user = nil, reason = nil, comment = nil, options = {})
|
@@ -20,8 +21,12 @@ module Kaui
|
|
20
21
|
begin
|
21
22
|
kb_user.create(user, reason, comment, options)
|
22
23
|
rescue KillBillClient::API::BadRequest => e
|
23
|
-
error_code =
|
24
|
-
|
24
|
+
error_code = begin
|
25
|
+
JSON.parse(e.response.body)['code']
|
26
|
+
rescue StandardError
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
raise e unless error_code == 40_002 # SECURITY_USER_ALREADY_EXISTS
|
25
30
|
end
|
26
31
|
|
27
32
|
# Save locally
|
@@ -30,7 +35,6 @@ module Kaui
|
|
30
35
|
|
31
36
|
# Update the user locally and in Kill Bill (if needed)
|
32
37
|
def update_in_kb!(password, roles, user = nil, reason = nil, comment = nil, options = {})
|
33
|
-
|
34
38
|
user_role = KillBillClient::Model::UserRoles.new
|
35
39
|
user_role.username = kb_username
|
36
40
|
|
@@ -55,7 +59,7 @@ module Kaui
|
|
55
59
|
|
56
60
|
begin
|
57
61
|
user_role.destroy(user, reason, comment, options)
|
58
|
-
rescue KillBillClient::API::BadRequest =>
|
62
|
+
rescue KillBillClient::API::BadRequest => _e
|
59
63
|
# User already deactivated in Kill Bill
|
60
64
|
end
|
61
65
|
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kaui
|
2
4
|
class AllowedUserTenant < ApplicationRecord
|
3
|
-
belongs_to :kaui_allowed_user, :
|
4
|
-
belongs_to :kaui_tenant, :
|
5
|
+
belongs_to :kaui_allowed_user, class_name: 'Kaui::AllowedUser', foreign_key: 'kaui_allowed_user_id'
|
6
|
+
belongs_to :kaui_tenant, class_name: 'Kaui::Tenant', foreign_key: 'kaui_tenant_id'
|
5
7
|
end
|
6
8
|
end
|