kaui 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile +1 -1
- data/README.md +10 -15
- data/app/assets/images/kaui/duck.png +0 -0
- data/app/assets/images/kaui/logo.png +0 -0
- data/app/assets/images/kaui/search.png +0 -0
- data/app/assets/images/kaui/search_white.png +0 -0
- data/app/assets/javascripts/application.js +3 -0
- data/app/assets/javascripts/kaui/bootstrap-tweaks.js +3 -0
- data/app/assets/javascripts/kaui/kaui.js +99 -0
- data/app/assets/stylesheets/application.css +3 -1
- data/app/assets/stylesheets/bootstrap_and_overrides.less +39 -0
- data/app/assets/stylesheets/kaui/common.less +538 -0
- data/app/assets/stylesheets/kaui/datatable.less +75 -0
- data/app/assets/stylesheets/kaui/header.less +186 -0
- data/app/assets/stylesheets/kaui/home.less +82 -0
- data/app/assets/stylesheets/kaui/invoice.less +54 -0
- data/app/assets/stylesheets/kaui/kaui.less +16 -0
- data/app/assets/stylesheets/kaui/payment.less +29 -0
- data/app/assets/stylesheets/kaui/subscription.less +5 -0
- data/app/assets/stylesheets/kaui/tags.less +175 -0
- data/app/assets/stylesheets/kaui/timeline.less +4 -0
- data/app/controllers/kaui/account_emails_controller.rb +18 -18
- data/app/controllers/kaui/account_tags_controller.rb +8 -30
- data/app/controllers/kaui/account_timelines_controller.rb +13 -23
- data/app/controllers/kaui/accounts_controller.rb +65 -62
- data/app/controllers/kaui/admin_allowed_users_controller.rb +48 -32
- data/app/controllers/kaui/admin_tenants_controller.rb +147 -142
- data/app/controllers/kaui/bundle_tags_controller.rb +9 -33
- data/app/controllers/kaui/bundles_controller.rb +23 -62
- data/app/controllers/kaui/chargebacks_controller.rb +5 -11
- data/app/controllers/kaui/charges_controller.rb +11 -18
- data/app/controllers/kaui/credits_controller.rb +19 -22
- data/app/controllers/kaui/custom_fields_controller.rb +44 -16
- data/app/controllers/kaui/engine_controller.rb +56 -3
- data/app/controllers/kaui/engine_controller_util.rb +75 -1
- data/app/controllers/kaui/home_controller.rb +19 -0
- data/app/controllers/kaui/invoice_items_controller.rb +16 -21
- data/app/controllers/kaui/invoices_controller.rb +31 -53
- data/app/controllers/kaui/payment_methods_controller.rb +14 -46
- data/app/controllers/kaui/payments_controller.rb +60 -69
- data/app/controllers/kaui/refunds_controller.rb +11 -25
- data/app/controllers/kaui/registrations_controller.rb +38 -0
- data/app/controllers/kaui/subscriptions_controller.rb +82 -95
- data/app/controllers/kaui/tag_definitions_controller.rb +1 -5
- data/app/controllers/kaui/tags_controller.rb +17 -17
- data/app/controllers/kaui/tenants_controller.rb +38 -55
- data/app/controllers/kaui/transactions_controller.rb +8 -15
- data/app/helpers/kaui/application_helper.rb +4 -0
- data/app/helpers/kaui/object_helper.rb +24 -0
- data/app/helpers/kaui/payment_method_helper.rb +9 -0
- data/app/helpers/kaui/subscription_helper.rb +1 -1
- data/app/helpers/kaui/uuid_helper.rb +1 -0
- data/app/models/kaui/ability.rb +7 -1
- data/app/models/kaui/account.rb +6 -2
- data/app/models/kaui/account_email.rb +10 -0
- data/app/models/kaui/allowed_user.rb +16 -4
- data/app/models/kaui/audit_log.rb +5 -3
- data/app/models/kaui/bundle.rb +6 -11
- data/app/models/kaui/credit.rb +3 -0
- data/app/models/kaui/invoice.rb +10 -15
- data/app/models/kaui/invoice_payment.rb +10 -13
- data/app/models/kaui/killbill_registerable.rb +7 -0
- data/app/models/kaui/payment.rb +19 -12
- data/app/models/kaui/payment_method.rb +9 -0
- data/app/models/kaui/payment_state.rb +52 -0
- data/app/models/kaui/tag.rb +14 -0
- data/app/models/kaui/tag_definition.rb +8 -2
- data/app/models/kaui/user.rb +5 -4
- data/app/views/kaui/account_emails/_account_emails_table.html.erb +12 -9
- data/app/views/kaui/account_emails/_form.html.erb +9 -9
- data/app/views/kaui/account_emails/new.html.erb +9 -2
- data/app/views/kaui/account_tags/_form.html.erb +20 -29
- data/app/views/kaui/account_tags/_form_bar.html.erb +21 -0
- data/app/views/kaui/account_tags/edit.html.erb +9 -4
- data/app/views/kaui/account_timelines/show.html.erb +204 -287
- data/app/views/kaui/accounts/_account_info.html.erb +108 -0
- data/app/views/kaui/accounts/_billing_info.html.erb +129 -0
- data/app/views/kaui/accounts/_form.html.erb +127 -115
- data/app/views/kaui/accounts/_payment_methods.html.erb +28 -0
- data/app/views/kaui/accounts/edit.html.erb +10 -0
- data/app/views/kaui/accounts/index.html.erb +38 -23
- data/app/views/kaui/accounts/new.html.erb +9 -4
- data/app/views/kaui/accounts/show.html.erb +4 -106
- data/app/views/kaui/admin_allowed_users/_form.html.erb +19 -0
- data/app/views/kaui/admin_allowed_users/index.html.erb +35 -18
- data/app/views/kaui/admin_allowed_users/new.html.erb +9 -21
- data/app/views/kaui/admin_allowed_users/show.html.erb +42 -50
- data/app/views/kaui/admin_tenants/_form.html.erb +25 -0
- data/app/views/kaui/admin_tenants/_tenants_table.html.erb +27 -0
- data/app/views/kaui/admin_tenants/index.html.erb +14 -23
- data/app/views/kaui/admin_tenants/new.html.erb +8 -37
- data/app/views/kaui/admin_tenants/show.html.erb +128 -113
- data/app/views/kaui/bundle_tags/_form.html.erb +20 -28
- data/app/views/kaui/bundle_tags/_form_bar.html.erb +21 -0
- data/app/views/kaui/bundle_tags/edit.html.erb +9 -4
- data/app/views/kaui/bundles/index.html.erb +76 -29
- data/app/views/kaui/bundles/transfer.html.erb +28 -28
- data/app/views/kaui/chargebacks/_form.html.erb +31 -29
- data/app/views/kaui/chargebacks/new.html.erb +9 -4
- data/app/views/kaui/charges/_form.html.erb +35 -59
- data/app/views/kaui/charges/new.html.erb +9 -4
- data/app/views/kaui/credits/_form.html.erb +32 -59
- data/app/views/kaui/credits/new.html.erb +9 -4
- data/app/views/kaui/custom_fields/_form.html.erb +31 -0
- data/app/views/kaui/custom_fields/index.html.erb +33 -20
- data/app/views/kaui/custom_fields/new.html.erb +10 -0
- data/app/views/kaui/home/index.html.erb +12 -9
- data/app/views/kaui/invoice_items/_edit_form.html.erb +30 -0
- data/app/views/kaui/invoice_items/edit.html.erb +10 -91
- data/app/views/kaui/invoices/_invoice_table.html.erb +113 -0
- data/app/views/kaui/invoices/index.html.erb +31 -22
- data/app/views/kaui/invoices/show.html.erb +77 -91
- data/app/views/kaui/layouts/kaui_account_navbar.html.erb +11 -0
- data/app/views/kaui/layouts/kaui_application.html.erb +14 -53
- data/app/views/kaui/layouts/kaui_flash.html.erb +17 -0
- data/app/views/kaui/layouts/kaui_footer.html.erb +2 -0
- data/app/views/kaui/layouts/kaui_header.html.erb +17 -0
- data/app/views/kaui/layouts/kaui_navbar.html.erb +75 -0
- data/app/views/kaui/payment_methods/_form.html.erb +26 -23
- data/app/views/kaui/payment_methods/_new_creditcard_payment_method.html.erb +46 -41
- data/app/views/kaui/payment_methods/_payment_methods_details_table.html.erb +25 -0
- data/app/views/kaui/payment_methods/_payment_methods_table.html.erb +50 -52
- data/app/views/kaui/payment_methods/new.html.erb +9 -4
- data/app/views/kaui/payments/_form.html.erb +55 -0
- data/app/views/kaui/payments/_payment_table.html.erb +117 -0
- data/app/views/kaui/payments/index.html.erb +31 -22
- data/app/views/kaui/payments/new.html.erb +9 -92
- data/app/views/kaui/payments/show.html.erb +38 -2
- data/app/views/kaui/refunds/_form.html.erb +240 -0
- data/app/views/kaui/refunds/new.html.erb +8 -280
- data/app/views/kaui/registrations/_form.html.erb +19 -0
- data/app/views/kaui/registrations/new.html.erb +10 -0
- data/app/views/kaui/sessions/_form.html.erb +19 -0
- data/app/views/kaui/sessions/new.html.erb +7 -18
- data/app/views/kaui/subscriptions/_edit_form.html.erb +26 -0
- data/app/views/kaui/subscriptions/_form.html.erb +34 -31
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +37 -24
- data/app/views/kaui/subscriptions/edit.html.erb +10 -30
- data/app/views/kaui/subscriptions/new.html.erb +14 -11
- data/app/views/kaui/tag_definitions/_form.html.erb +14 -11
- data/app/views/kaui/tag_definitions/index.html.erb +56 -30
- data/app/views/kaui/tag_definitions/new.html.erb +9 -2
- data/app/views/kaui/tags/_tags_table.html.erb +7 -10
- data/app/views/kaui/tags/index.html.erb +29 -20
- data/app/views/kaui/tenants/_form.html.erb +13 -0
- data/app/views/kaui/tenants/index.html.erb +9 -16
- data/app/views/kaui/transactions/_form.html.erb +47 -67
- data/app/views/kaui/transactions/new.html.erb +9 -2
- data/config/initializers/killbill_registerable.rb +4 -0
- data/config/routes.rb +88 -93
- data/kaui.gemspec +11 -2
- data/lib/kaui/engine.rb +6 -4
- data/lib/kaui/version.rb +1 -1
- data/lib/kaui.rb +24 -1
- data/test/dummy/config/application.rb +2 -0
- data/test/dummy/config/database.yml +6 -3
- data/test/dummy/config/initializers/killbill_client.rb +0 -2
- data/test/fixtures/catalog-v1.xml +74 -0
- data/test/fixtures/catalog_translation_fr-v1.properties +1 -0
- data/test/fixtures/invoice_template-v1.html +100 -0
- data/test/fixtures/invoice_translation_fr-v1.properties +23 -0
- data/test/fixtures/overdue-v1.xml +49 -0
- data/test/fixtures/stripe.yml +2 -0
- data/test/functional/kaui/account_emails_controller_test.rb +35 -8
- data/test/functional/kaui/account_tags_controller_test.rb +8 -8
- data/test/functional/kaui/account_timelines_controller_test.rb +6 -7
- data/test/functional/kaui/accounts_controller_test.rb +72 -10
- data/test/functional/kaui/admin_allowed_users_controller_test.rb +6 -5
- data/test/functional/kaui/admin_tenants_controller_test.rb +104 -48
- data/test/functional/kaui/bundle_tags_controller_test.rb +14 -9
- data/test/functional/kaui/bundles_controller_test.rb +59 -23
- data/test/functional/kaui/chargebacks_controller_test.rb +29 -7
- data/test/functional/kaui/charges_controller_test.rb +31 -10
- data/test/functional/kaui/credits_controller_test.rb +25 -6
- data/test/functional/kaui/custom_fields_controller_test.rb +25 -1
- data/test/functional/kaui/functional_test_helper_nosetup.rb +6 -4
- data/test/functional/kaui/home_controller_test.rb +24 -0
- data/test/functional/kaui/invoice_items_controller_test.rb +56 -8
- data/test/functional/kaui/invoices_controller_test.rb +27 -18
- data/test/functional/kaui/payment_methods_controller_test.rb +2 -22
- data/test/functional/kaui/payments_controller_test.rb +8 -3
- data/test/functional/kaui/refunds_controller_test.rb +40 -21
- data/test/functional/kaui/subscriptions_controller_test.rb +77 -24
- data/test/functional/kaui/tag_definitions_controller_test.rb +1 -7
- data/test/functional/kaui/tags_controller_test.rb +1 -1
- data/test/functional/kaui/tenants_controller_test.rb +9 -9
- data/test/functional/kaui/transactions_controller_test.rb +41 -16
- data/test/integration/kaui/integration_test_helper.rb +0 -1
- data/test/integration/kaui/navigation_test.rb +4 -6
- data/test/test_helper.rb +2 -0
- metadata +155 -28
- data/Gemfile.lock +0 -210
- data/app/assets/stylesheets/bootstrap_and_overrides.css +0 -7
- data/app/assets/stylesheets/datatables.scss +0 -14
- data/app/assets/stylesheets/layout.scss +0 -19
- data/app/views/kaui/account_emails/show.html.erb +0 -25
- data/app/views/kaui/account_tags/_account_tags_table.html.erb +0 -32
- data/app/views/kaui/account_tags/show.html.erb +0 -6
- data/app/views/kaui/account_timelines/index.html.erb +0 -14
- data/app/views/kaui/bundle_tags/_bundle_tags_table.html.erb +0 -31
- data/app/views/kaui/bundle_tags/show.html.erb +0 -6
- data/app/views/kaui/bundles/show.html.erb +0 -18
- data/app/views/kaui/payment_methods/index.html.erb +0 -30
- data/app/views/kaui/payment_methods/show.html.erb +0 -3
- data/app/views/kaui/payments/_payments_table.html.erb +0 -41
- data/app/views/kaui/subscriptions/index.html.erb +0 -15
- data/app/views/kaui/subscriptions/show.html.erb +0 -33
- data/app/views/kaui/tag_definitions/show.html.erb +0 -15
- data/vendor/assets/images/img/glyphicons-halflings-white.png +0 -0
- data/vendor/assets/images/img/glyphicons-halflings.png +0 -0
- data/vendor/assets/stylesheets/css/bootstrap-datepicker.cd46d38.css +0 -274
@@ -1,195 +1,200 @@
|
|
1
|
-
|
2
|
-
class AdminTenantsController < Kaui::EngineController
|
1
|
+
class Kaui::AdminTenantsController < Kaui::EngineController
|
3
2
|
|
4
|
-
|
3
|
+
skip_before_filter :check_for_redirect_to_tenant_screen
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
def index
|
6
|
+
# Display the configured tenants in KAUI (which could be different than the existing tenants known by Kill Bill)
|
7
|
+
tenants_for_current_user = retrieve_tenants_for_current_user
|
8
|
+
@tenants = Kaui::Tenant.all.select { |tenant| tenants_for_current_user.include?(tenant.kb_tenant_id) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def new
|
12
|
+
@tenant = Kaui::Tenant.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
param_tenant = params[:tenant]
|
17
|
+
old_tenant = Kaui::Tenant.find_by_name(param_tenant[:name])
|
18
|
+
if old_tenant
|
19
|
+
flash.now[:error] = "Tenant with name #{param_tenant[:name]} already exists!"
|
20
|
+
@tenant = Kaui::Tenant.new
|
21
|
+
render :new and return
|
10
22
|
end
|
11
23
|
|
12
|
-
|
24
|
+
old_tenant = Kaui::Tenant.find_by_api_key(param_tenant[:api_key])
|
25
|
+
if old_tenant
|
26
|
+
flash.now[:error] = "Tenant with api key #{param_tenant[:api_key]} already exists!"
|
13
27
|
@tenant = Kaui::Tenant.new
|
28
|
+
render :new and return
|
14
29
|
end
|
15
30
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
if old_tenant
|
20
|
-
flash[:error] = "Tenant with name #{param_tenant[:name]} already exists!"
|
21
|
-
redirect_to admin_tenants_path and return
|
22
|
-
end
|
31
|
+
begin
|
32
|
+
options = tenant_options_for_client
|
33
|
+
new_tenant = nil
|
23
34
|
|
24
35
|
begin
|
25
|
-
|
26
|
-
options =
|
27
|
-
new_tenant =
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
new_tenant = new_tenant.create(options[:username], nil, comment, options)
|
36
|
-
else
|
37
|
-
options[:api_key] = param_tenant[:api_key]
|
38
|
-
options[:api_secret] = param_tenant[:api_secret]
|
39
|
-
new_tenant = Kaui::AdminTenant.find_by_api_key(param_tenant[:api_key], options)
|
40
|
-
end
|
41
|
-
|
42
|
-
# Transform object to Kaui model
|
43
|
-
tenant_model = Kaui::Tenant.new
|
44
|
-
tenant_model.name = new_tenant.external_key
|
45
|
-
tenant_model.kb_tenant_id = new_tenant.tenant_id
|
46
|
-
tenant_model.api_key = new_tenant.api_key
|
47
|
-
tenant_model.api_secret = param_tenant[:api_secret]
|
48
|
-
|
49
|
-
# Save in KAUI tables
|
50
|
-
tenant_model.save!
|
51
|
-
rescue => e
|
52
|
-
flash[:error] = "Failed to create the tenant : #{as_string(e)}"
|
53
|
-
redirect_to admin_tenants_path and return
|
36
|
+
options[:api_key] = param_tenant[:api_key]
|
37
|
+
options[:api_secret] = param_tenant[:api_secret]
|
38
|
+
new_tenant = Kaui::AdminTenant.find_by_api_key(param_tenant[:api_key], options)
|
39
|
+
rescue KillBillClient::API::Unauthorized, KillBillClient::API::NotFound
|
40
|
+
# Create the tenant in Kill Bill
|
41
|
+
new_tenant = Kaui::AdminTenant.new
|
42
|
+
new_tenant.external_key = param_tenant[:name]
|
43
|
+
new_tenant.api_key = param_tenant[:api_key]
|
44
|
+
new_tenant.api_secret = param_tenant[:api_secret]
|
45
|
+
new_tenant = new_tenant.create(options[:username], nil, comment, options)
|
54
46
|
end
|
55
47
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
48
|
+
# Transform object to Kaui model
|
49
|
+
tenant_model = Kaui::Tenant.new
|
50
|
+
tenant_model.name = new_tenant.external_key
|
51
|
+
tenant_model.kb_tenant_id = new_tenant.tenant_id
|
52
|
+
tenant_model.api_key = new_tenant.api_key
|
53
|
+
tenant_model.api_secret = param_tenant[:api_secret]
|
54
|
+
|
55
|
+
# Save in KAUI tables
|
56
|
+
tenant_model.save!
|
57
|
+
|
58
|
+
# Make sure at least the current user can access the tenant
|
59
|
+
tenant_model.kaui_allowed_users << Kaui::AllowedUser.where(:kb_username => current_user.kb_username).first_or_create
|
60
|
+
rescue => e
|
61
|
+
flash[:error] = "Failed to create the tenant: #{as_string(e)}"
|
62
|
+
redirect_to admin_tenants_path and return
|
67
63
|
end
|
68
64
|
|
69
|
-
|
65
|
+
# Select the tenant, see TenantsController
|
66
|
+
session[:kb_tenant_id] = tenant_model.kb_tenant_id
|
67
|
+
session[:kb_tenant_name] = tenant_model.name
|
70
68
|
|
71
|
-
|
72
|
-
|
73
|
-
options = tenant_options_for_client
|
74
|
-
options[:api_key] = current_tenant.api_key
|
75
|
-
options[:api_secret] = current_tenant.api_secret
|
76
|
-
|
77
|
-
uploaded_catalog = params[:catalog]
|
78
|
-
catalog_xml = uploaded_catalog.read
|
79
|
-
|
80
|
-
Kaui::AdminTenant.upload_catalog(catalog_xml, options[:username], nil, comment, options)
|
81
|
-
|
82
|
-
redirect_to admin_tenants_path, :notice => 'Catalog was successfully uploaded'
|
83
|
-
end
|
69
|
+
redirect_to admin_tenant_path(tenant_model[:id]), :notice => 'Tenant was successfully configured'
|
70
|
+
end
|
84
71
|
|
85
|
-
|
86
|
-
|
72
|
+
def show
|
73
|
+
@tenant = safely_find_tenant_by_id(params[:id])
|
74
|
+
@allowed_users = retrieve_allowed_users_for_current_user
|
75
|
+
end
|
87
76
|
|
88
|
-
|
89
|
-
|
90
|
-
options[:api_secret] = current_tenant.api_secret
|
77
|
+
def upload_catalog
|
78
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
91
79
|
|
92
|
-
|
93
|
-
|
80
|
+
options = tenant_options_for_client
|
81
|
+
options[:api_key] = current_tenant.api_key
|
82
|
+
options[:api_secret] = current_tenant.api_secret
|
94
83
|
|
95
|
-
|
84
|
+
uploaded_catalog = params[:catalog]
|
85
|
+
catalog_xml = uploaded_catalog.read
|
96
86
|
|
97
|
-
|
98
|
-
end
|
87
|
+
Kaui::AdminTenant.upload_catalog(catalog_xml, options[:username], nil, comment, options)
|
99
88
|
|
89
|
+
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Catalog was successfully uploaded'
|
90
|
+
end
|
100
91
|
|
101
|
-
|
102
|
-
|
92
|
+
def upload_overdue_config
|
93
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
103
94
|
|
104
|
-
|
105
|
-
|
106
|
-
|
95
|
+
options = tenant_options_for_client
|
96
|
+
options[:api_key] = current_tenant.api_key
|
97
|
+
options[:api_secret] = current_tenant.api_secret
|
107
98
|
|
108
|
-
|
109
|
-
|
110
|
-
invoice_template = uploaded_invoice_template.read
|
99
|
+
uploaded_overdue_config = params[:overdue]
|
100
|
+
overdue_config_xml = uploaded_overdue_config.read
|
111
101
|
|
112
|
-
|
102
|
+
Kaui::AdminTenant.upload_overdue_config(overdue_config_xml, options[:username], nil, comment, options)
|
113
103
|
|
114
|
-
|
104
|
+
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Overdue config was successfully uploaded'
|
105
|
+
end
|
115
106
|
|
116
|
-
end
|
117
107
|
|
118
|
-
|
119
|
-
|
108
|
+
def upload_invoice_template
|
109
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
120
110
|
|
121
|
-
|
122
|
-
|
123
|
-
|
111
|
+
options = tenant_options_for_client
|
112
|
+
options[:api_key] = current_tenant.api_key
|
113
|
+
options[:api_secret] = current_tenant.api_secret
|
124
114
|
|
125
|
-
|
126
|
-
|
127
|
-
|
115
|
+
is_manual_pay = params[:manual_pay]
|
116
|
+
uploaded_invoice_template = params[:invoice_template]
|
117
|
+
invoice_template = uploaded_invoice_template.read
|
128
118
|
|
129
|
-
|
119
|
+
Kaui::AdminTenant.upload_invoice_template(invoice_template, is_manual_pay, true, options[:username], nil, comment, options)
|
130
120
|
|
131
|
-
|
121
|
+
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Invoice template was successfully uploaded'
|
122
|
+
end
|
132
123
|
|
133
|
-
|
124
|
+
def upload_invoice_translation
|
125
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
134
126
|
|
135
|
-
|
127
|
+
options = tenant_options_for_client
|
128
|
+
options[:api_key] = current_tenant.api_key
|
129
|
+
options[:api_secret] = current_tenant.api_secret
|
136
130
|
|
137
|
-
|
131
|
+
locale = params[:translation_locale]
|
132
|
+
uploaded_invoice_translation = params[:invoice_translation]
|
133
|
+
invoice_translation = uploaded_invoice_translation.read
|
138
134
|
|
139
|
-
|
140
|
-
options[:api_key] = current_tenant.api_key
|
141
|
-
options[:api_secret] = current_tenant.api_secret
|
135
|
+
Kaui::AdminTenant.upload_invoice_translation(invoice_translation, locale, true, options[:username], nil, comment, options)
|
142
136
|
|
143
|
-
|
144
|
-
|
145
|
-
catalog_translation = uploaded_catalog_translation.read
|
137
|
+
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Invoice translation was successfully uploaded'
|
138
|
+
end
|
146
139
|
|
147
|
-
|
140
|
+
def upload_catalog_translation
|
141
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
148
142
|
|
149
|
-
|
150
|
-
|
143
|
+
options = tenant_options_for_client
|
144
|
+
options[:api_key] = current_tenant.api_key
|
145
|
+
options[:api_secret] = current_tenant.api_secret
|
151
146
|
|
147
|
+
locale = params[:translation_locale]
|
148
|
+
uploaded_catalog_translation = params[:catalog_translation]
|
149
|
+
catalog_translation = uploaded_catalog_translation.read
|
152
150
|
|
153
|
-
|
151
|
+
Kaui::AdminTenant.upload_catalog_translation(catalog_translation, locale, true, options[:username], nil, comment, options)
|
154
152
|
|
155
|
-
|
153
|
+
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Catalog translation was successfully uploaded'
|
154
|
+
end
|
156
155
|
|
157
|
-
|
158
|
-
|
159
|
-
options[:api_secret] = current_tenant.api_secret
|
156
|
+
def upload_plugin_config
|
157
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
160
158
|
|
161
|
-
|
162
|
-
|
163
|
-
|
159
|
+
options = tenant_options_for_client
|
160
|
+
options[:api_key] = current_tenant.api_key
|
161
|
+
options[:api_secret] = current_tenant.api_secret
|
164
162
|
|
165
|
-
|
163
|
+
plugin_name = params[:plugin_name]
|
164
|
+
uploaded_plugin_config = params[:plugin_config]
|
165
|
+
plugin_config = uploaded_plugin_config.read
|
166
166
|
|
167
|
-
|
167
|
+
Kaui::AdminTenant.upload_tenant_plugin_config(plugin_name, plugin_config, options[:username], nil, comment, options)
|
168
168
|
|
169
|
-
|
169
|
+
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Config for plugin was successfully uploaded'
|
170
|
+
end
|
170
171
|
|
171
|
-
|
172
|
+
def remove_allowed_user
|
173
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
174
|
+
au = Kaui::AllowedUser.find(params[:allowed_user][:id])
|
175
|
+
# remove the association
|
176
|
+
au.kaui_tenants.delete current_tenant
|
177
|
+
render :json => '{}', :status => 200
|
178
|
+
end
|
172
179
|
|
173
|
-
|
174
|
-
au = Kaui::AllowedUser.find(params[:allowed_user][:id])
|
175
|
-
# remove the association
|
176
|
-
au.kaui_tenants.delete current_tenant
|
177
|
-
render :json => '{}', :status => 200
|
178
|
-
end
|
180
|
+
private
|
179
181
|
|
180
|
-
|
182
|
+
def safely_find_tenant_by_id(tenant_id)
|
183
|
+
tenant = Kaui::Tenant.find_by_id(tenant_id)
|
184
|
+
raise ActiveRecord::RecordNotFound.new('Could not find tenant ' + tenant_id) unless retrieve_tenants_for_current_user.include?(tenant.kb_tenant_id)
|
185
|
+
tenant
|
186
|
+
end
|
181
187
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
188
|
+
def tenant_options_for_client
|
189
|
+
user = current_user
|
190
|
+
{
|
191
|
+
:username => user.kb_username,
|
192
|
+
:password => user.password,
|
193
|
+
:session_id => user.kb_session_id
|
194
|
+
}
|
195
|
+
end
|
190
196
|
|
191
|
-
|
192
|
-
|
193
|
-
end
|
197
|
+
def comment
|
198
|
+
'Multi-tenant Administrative operation'
|
194
199
|
end
|
195
200
|
end
|
@@ -1,35 +1,17 @@
|
|
1
1
|
class Kaui::BundleTagsController < Kaui::EngineController
|
2
2
|
|
3
|
-
def show
|
4
|
-
bundle_id_or_key = params[:bundle_id]
|
5
|
-
account_id = params[:account_id]
|
6
|
-
|
7
|
-
begin
|
8
|
-
@bundle = Kaui::Bundle::find_by_id_or_key(bundle_id_or_key, account_id, options_for_klient)
|
9
|
-
@account = Kaui::Account::find_by_id_or_key(@bundle.account_id, false, false, options_for_klient)
|
10
|
-
@tags = @bundle.tags(true, 'FULL', options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b }
|
11
|
-
rescue => e
|
12
|
-
flash[:error] = "Error while getting tags: #{as_string(e)}"
|
13
|
-
redirect_to :back
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
3
|
def edit
|
18
|
-
|
19
|
-
account_id = params[:account_id]
|
4
|
+
@bundle_id = params.require(:bundle_id)
|
20
5
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
rescue => e
|
26
|
-
flash[:error] = "Error while editing tags: #{as_string(e)}"
|
27
|
-
redirect_to kaui_engine.bundle_tags_path(:bundle_id => bundle_id_or_key)
|
28
|
-
end
|
6
|
+
fetch_tag_names = lambda { @tag_names = (Kaui::Tag.all_for_bundle(@bundle_id, false, 'NONE', options_for_klient).map { |tag| tag.tag_definition_name }).sort }
|
7
|
+
fetch_available_tags = lambda { @available_tags = Kaui::TagDefinition.all_for_bundle(options_for_klient) }
|
8
|
+
|
9
|
+
run_in_parallel fetch_tag_names, fetch_available_tags
|
29
10
|
end
|
30
11
|
|
31
12
|
def update
|
32
|
-
|
13
|
+
account_id = params.require(:account_id)
|
14
|
+
bundle_id = params.require(:bundle_id)
|
33
15
|
|
34
16
|
tags = []
|
35
17
|
params.each do |tag, tag_name|
|
@@ -38,13 +20,7 @@ class Kaui::BundleTagsController < Kaui::EngineController
|
|
38
20
|
tags << tag_info[1]
|
39
21
|
end
|
40
22
|
|
41
|
-
|
42
|
-
|
43
|
-
bundle.set_tags(tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
44
|
-
redirect_to kaui_engine.bundle_tags_path(:bundle_id => bundle_id), :notice => 'Bundle tags successfully set'
|
45
|
-
rescue => e
|
46
|
-
flash[:error] = "Error while updating tags: #{as_string(e)}"
|
47
|
-
redirect_to kaui_engine.bundle_tags_path(:bundle_id => bundle_id)
|
48
|
-
end
|
23
|
+
Kaui::Tag.set_for_bundle(bundle_id, tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
24
|
+
redirect_to kaui_engine.account_bundles_path(account_id), :notice => 'Bundle tags successfully set'
|
49
25
|
end
|
50
26
|
end
|
@@ -1,82 +1,43 @@
|
|
1
1
|
class Kaui::BundlesController < Kaui::EngineController
|
2
2
|
|
3
3
|
def index
|
4
|
-
|
5
|
-
|
6
|
-
def pagination
|
7
|
-
search_key = params[:sSearch]
|
8
|
-
offset = params[:iDisplayStart] || 0
|
9
|
-
limit = params[:iDisplayLength] || 10
|
10
|
-
|
11
|
-
bundles = Kaui::Bundle.list_or_search(search_key, offset, limit, options_for_klient)
|
4
|
+
@account = Kaui::Account::find_by_id_or_key(params.require(:account_id), false, false, options_for_klient)
|
12
5
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
:aaData => []
|
6
|
+
fetch_bundles = lambda { @bundles = @account.bundles(options_for_klient) }
|
7
|
+
fetch_bundle_tags = lambda {
|
8
|
+
all_bundle_tags = @account.all_tags(:BUNDLE, false, 'NONE', options_for_klient)
|
9
|
+
@tags_per_bundle = all_bundle_tags.inject({}) {|hsh, entry| (hsh[entry.object_id] ||= []) << entry; hsh}
|
18
10
|
}
|
19
11
|
|
20
|
-
|
21
|
-
json[:aaData] << [
|
22
|
-
view_context.link_to(view_context.truncate_uuid(bundle.bundle_id), view_context.url_for(:action => :show, :id => bundle.bundle_id)),
|
23
|
-
view_context.link_to(view_context.truncate_uuid(bundle.account_id), view_context.url_for(:controller => :accounts, :action => :show, :id => bundle.account_id)),
|
24
|
-
bundle.external_key,
|
25
|
-
bundle.subscriptions.nil? ? '' : (bundle.subscriptions.map { |s| s.product_name }).join(', ')
|
26
|
-
]
|
27
|
-
end
|
12
|
+
fetch_available_tags = lambda { @available_tags = Kaui::TagDefinition.all_for_bundle(options_for_klient) }
|
28
13
|
|
29
|
-
|
30
|
-
format.json { render :json => json }
|
31
|
-
end
|
32
|
-
end
|
14
|
+
run_in_parallel fetch_bundles, fetch_bundle_tags, fetch_available_tags
|
33
15
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
render :action => :index
|
16
|
+
@base_subscription = {}
|
17
|
+
@bundles.each do |bundle|
|
18
|
+
bundle.subscriptions.each do |sub|
|
19
|
+
next unless sub.product_category == 'BASE'
|
20
|
+
@base_subscription[bundle.bundle_id] = sub
|
21
|
+
break
|
22
|
+
end
|
42
23
|
end
|
43
24
|
end
|
44
25
|
|
45
26
|
def transfer
|
46
|
-
|
47
|
-
@bundle = Kaui::Bundle::find_by_id_or_key(params[:id], nil, options_for_klient)
|
48
|
-
@account = Kaui::Account::find_by_id(@bundle.account_id, false, false, options_for_klient)
|
49
|
-
rescue => e
|
50
|
-
flash.now[:error] = "Error while preparing to transfer bundle: #{as_string(e)}"
|
51
|
-
render :action => :index
|
52
|
-
end
|
27
|
+
@bundle_id = params.require(:id)
|
53
28
|
end
|
54
29
|
|
55
30
|
def do_transfer
|
56
|
-
|
57
|
-
unless key.present?
|
58
|
-
flash.now[:error] = 'No new account key given'
|
59
|
-
render :action => :index and return
|
60
|
-
end
|
61
|
-
|
62
|
-
begin
|
63
|
-
# Retrieve the new account to get the account id
|
64
|
-
new_account = Kaui::Account::find_by_id_or_key(params[:new_account_key], false, false, options_for_klient)
|
65
|
-
rescue => e
|
66
|
-
flash.now[:error] = "Error while retrieving new account: #{as_string(e)}"
|
67
|
-
render :action => :index and return
|
68
|
-
end
|
31
|
+
new_account = Kaui::Account::find_by_id_or_key(params.require(:new_account_key), false, false, options_for_klient)
|
69
32
|
|
70
|
-
|
71
|
-
|
33
|
+
bundle = Kaui::Bundle::new(:bundle_id => params.require(:id), :account_id => new_account.account_id)
|
34
|
+
bundle.transfer(nil, params[:billing_policy], current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
72
35
|
|
73
|
-
|
74
|
-
|
36
|
+
redirect_to kaui_engine.account_bundles_path(new_account.account_id), :notice => 'Bundle was successfully transferred'
|
37
|
+
end
|
75
38
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
render :action => :index
|
80
|
-
end
|
39
|
+
def restful_show
|
40
|
+
bundle = Kaui::Bundle.find_by_id_or_key(params.require(:id), options_for_klient)
|
41
|
+
redirect_to kaui_engine.account_bundles_path(bundle.account_id)
|
81
42
|
end
|
82
43
|
end
|
@@ -1,20 +1,14 @@
|
|
1
1
|
class Kaui::ChargebacksController < Kaui::EngineController
|
2
2
|
|
3
3
|
def new
|
4
|
-
|
5
|
-
payment = Kaui::Payment::find_by_id(params[:payment_id], options_for_klient)
|
6
|
-
rescue => e
|
7
|
-
flash[:error] = "Error while retrieving payment: #{as_string(e)}"
|
8
|
-
redirect_to :back
|
9
|
-
end
|
10
|
-
|
4
|
+
payment = Kaui::Payment::find_by_id(params.require(:payment_id), options_for_klient)
|
11
5
|
@chargeback = Kaui::Chargeback.new(:payment_id => payment.payment_id,
|
12
|
-
:amount
|
13
|
-
:currency
|
6
|
+
:amount => payment.paid_amount_to_money.to_f,
|
7
|
+
:currency => payment.currency)
|
14
8
|
end
|
15
9
|
|
16
10
|
def create
|
17
|
-
@chargeback
|
11
|
+
@chargeback = Kaui::Chargeback.new(params.require(:chargeback))
|
18
12
|
should_cancel_subs = (params[:cancel_all_subs] == '1')
|
19
13
|
|
20
14
|
begin
|
@@ -44,6 +38,6 @@ class Kaui::ChargebacksController < Kaui::EngineController
|
|
44
38
|
end
|
45
39
|
end
|
46
40
|
|
47
|
-
redirect_to kaui_engine.
|
41
|
+
redirect_to kaui_engine.account_payment_path(payment.account_id, payment.payment_id), :notice => 'Chargeback created'
|
48
42
|
end
|
49
43
|
end
|
@@ -2,31 +2,24 @@ class Kaui::ChargesController < Kaui::EngineController
|
|
2
2
|
|
3
3
|
def new
|
4
4
|
invoice_id = params[:invoice_id]
|
5
|
-
|
6
|
-
currency = params[:currency] || 'USD'
|
5
|
+
amount = params[:amount]
|
7
6
|
|
8
7
|
if invoice_id.present?
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
flash.now[:error] = "Unable to retrieve invoice: #{as_string(e)}"
|
15
|
-
end
|
8
|
+
@invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
|
9
|
+
amount ||= @invoice.balance
|
10
|
+
currency = @invoice.currency
|
11
|
+
else
|
12
|
+
currency = params[:currency] || 'USD'
|
16
13
|
end
|
17
14
|
|
18
|
-
@charge = Kaui::InvoiceItem.new(:account_id => account_id, :invoice_id => invoice_id, :currency => currency)
|
15
|
+
@charge = Kaui::InvoiceItem.new(:account_id => params.require(:account_id), :invoice_id => invoice_id, :amount => amount, :currency => currency)
|
19
16
|
end
|
20
17
|
|
21
18
|
def create
|
22
|
-
|
19
|
+
charge = Kaui::InvoiceItem.new(params.require(:invoice_item).delete_if { |key, value| value.blank? })
|
20
|
+
charge.account_id ||= params.require(:account_id)
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
redirect_to kaui_engine.invoice_path(:id => @charge.invoice_id), :notice => 'Charge was successfully created'
|
27
|
-
rescue => e
|
28
|
-
flash.now[:error] = "Error while creating a charge: #{as_string(e)}"
|
29
|
-
render :action => :new
|
30
|
-
end
|
22
|
+
charge = charge.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
23
|
+
redirect_to kaui_engine.account_invoice_path(charge.account_id, charge.invoice_id), :notice => 'Charge was successfully created'
|
31
24
|
end
|
32
25
|
end
|
@@ -2,36 +2,33 @@ class Kaui::CreditsController < Kaui::EngineController
|
|
2
2
|
|
3
3
|
def new
|
4
4
|
invoice_id = params[:invoice_id]
|
5
|
-
|
6
|
-
amount = params[:amount]
|
7
|
-
currency = params[:currency] || 'USD'
|
5
|
+
amount = params[:amount]
|
8
6
|
|
9
7
|
if invoice_id.present?
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
rescue => e
|
16
|
-
flash.now[:error] = "Unable to retrieve invoice: #{as_string(e)}"
|
17
|
-
end
|
8
|
+
@invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
|
9
|
+
amount ||= @invoice.balance
|
10
|
+
currency = @invoice.currency
|
11
|
+
else
|
12
|
+
currency = params[:currency] || 'USD'
|
18
13
|
end
|
19
14
|
|
20
|
-
|
21
|
-
@credit = Kaui::Credit.new(:invoice_id => invoice_id,
|
22
|
-
:account_id => account_id,
|
23
|
-
:credit_amount => amount)
|
15
|
+
@credit = Kaui::Credit.new(:account_id => params.require(:account_id), :invoice_id => invoice_id, :credit_amount => amount, :currency => currency)
|
24
16
|
end
|
25
17
|
|
26
18
|
def create
|
27
|
-
|
19
|
+
credit = Kaui::Credit.new(params[:credit].delete_if { |key, value| value.blank? })
|
20
|
+
credit.account_id ||= params.require(:account_id)
|
28
21
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
22
|
+
# No need to show the newly created invoice for account level credits
|
23
|
+
should_redirect_to_invoice = credit.invoice_id.present?
|
24
|
+
|
25
|
+
credit = credit.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
26
|
+
flash[:notice] = 'Credit was successfully created'
|
27
|
+
|
28
|
+
if should_redirect_to_invoice
|
29
|
+
redirect_to kaui_engine.account_invoice_path(credit.account_id, credit.invoice_id)
|
30
|
+
else
|
31
|
+
redirect_to kaui_engine.account_path(credit.account_id)
|
35
32
|
end
|
36
33
|
end
|
37
34
|
end
|