kaui 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/Gemfile +1 -1
  4. data/README.md +10 -15
  5. data/app/assets/images/kaui/duck.png +0 -0
  6. data/app/assets/images/kaui/logo.png +0 -0
  7. data/app/assets/images/kaui/search.png +0 -0
  8. data/app/assets/images/kaui/search_white.png +0 -0
  9. data/app/assets/javascripts/application.js +3 -0
  10. data/app/assets/javascripts/kaui/bootstrap-tweaks.js +3 -0
  11. data/app/assets/javascripts/kaui/kaui.js +99 -0
  12. data/app/assets/stylesheets/application.css +3 -1
  13. data/app/assets/stylesheets/bootstrap_and_overrides.less +39 -0
  14. data/app/assets/stylesheets/kaui/common.less +538 -0
  15. data/app/assets/stylesheets/kaui/datatable.less +75 -0
  16. data/app/assets/stylesheets/kaui/header.less +186 -0
  17. data/app/assets/stylesheets/kaui/home.less +82 -0
  18. data/app/assets/stylesheets/kaui/invoice.less +54 -0
  19. data/app/assets/stylesheets/kaui/kaui.less +16 -0
  20. data/app/assets/stylesheets/kaui/payment.less +29 -0
  21. data/app/assets/stylesheets/kaui/subscription.less +5 -0
  22. data/app/assets/stylesheets/kaui/tags.less +175 -0
  23. data/app/assets/stylesheets/kaui/timeline.less +4 -0
  24. data/app/controllers/kaui/account_emails_controller.rb +18 -18
  25. data/app/controllers/kaui/account_tags_controller.rb +8 -30
  26. data/app/controllers/kaui/account_timelines_controller.rb +13 -23
  27. data/app/controllers/kaui/accounts_controller.rb +65 -62
  28. data/app/controllers/kaui/admin_allowed_users_controller.rb +48 -32
  29. data/app/controllers/kaui/admin_tenants_controller.rb +147 -142
  30. data/app/controllers/kaui/bundle_tags_controller.rb +9 -33
  31. data/app/controllers/kaui/bundles_controller.rb +23 -62
  32. data/app/controllers/kaui/chargebacks_controller.rb +5 -11
  33. data/app/controllers/kaui/charges_controller.rb +11 -18
  34. data/app/controllers/kaui/credits_controller.rb +19 -22
  35. data/app/controllers/kaui/custom_fields_controller.rb +44 -16
  36. data/app/controllers/kaui/engine_controller.rb +56 -3
  37. data/app/controllers/kaui/engine_controller_util.rb +75 -1
  38. data/app/controllers/kaui/home_controller.rb +19 -0
  39. data/app/controllers/kaui/invoice_items_controller.rb +16 -21
  40. data/app/controllers/kaui/invoices_controller.rb +31 -53
  41. data/app/controllers/kaui/payment_methods_controller.rb +14 -46
  42. data/app/controllers/kaui/payments_controller.rb +60 -69
  43. data/app/controllers/kaui/refunds_controller.rb +11 -25
  44. data/app/controllers/kaui/registrations_controller.rb +38 -0
  45. data/app/controllers/kaui/subscriptions_controller.rb +82 -95
  46. data/app/controllers/kaui/tag_definitions_controller.rb +1 -5
  47. data/app/controllers/kaui/tags_controller.rb +17 -17
  48. data/app/controllers/kaui/tenants_controller.rb +38 -55
  49. data/app/controllers/kaui/transactions_controller.rb +8 -15
  50. data/app/helpers/kaui/application_helper.rb +4 -0
  51. data/app/helpers/kaui/object_helper.rb +24 -0
  52. data/app/helpers/kaui/payment_method_helper.rb +9 -0
  53. data/app/helpers/kaui/subscription_helper.rb +1 -1
  54. data/app/helpers/kaui/uuid_helper.rb +1 -0
  55. data/app/models/kaui/ability.rb +7 -1
  56. data/app/models/kaui/account.rb +6 -2
  57. data/app/models/kaui/account_email.rb +10 -0
  58. data/app/models/kaui/allowed_user.rb +16 -4
  59. data/app/models/kaui/audit_log.rb +5 -3
  60. data/app/models/kaui/bundle.rb +6 -11
  61. data/app/models/kaui/credit.rb +3 -0
  62. data/app/models/kaui/invoice.rb +10 -15
  63. data/app/models/kaui/invoice_payment.rb +10 -13
  64. data/app/models/kaui/killbill_registerable.rb +7 -0
  65. data/app/models/kaui/payment.rb +19 -12
  66. data/app/models/kaui/payment_method.rb +9 -0
  67. data/app/models/kaui/payment_state.rb +52 -0
  68. data/app/models/kaui/tag.rb +14 -0
  69. data/app/models/kaui/tag_definition.rb +8 -2
  70. data/app/models/kaui/user.rb +5 -4
  71. data/app/views/kaui/account_emails/_account_emails_table.html.erb +12 -9
  72. data/app/views/kaui/account_emails/_form.html.erb +9 -9
  73. data/app/views/kaui/account_emails/new.html.erb +9 -2
  74. data/app/views/kaui/account_tags/_form.html.erb +20 -29
  75. data/app/views/kaui/account_tags/_form_bar.html.erb +21 -0
  76. data/app/views/kaui/account_tags/edit.html.erb +9 -4
  77. data/app/views/kaui/account_timelines/show.html.erb +204 -287
  78. data/app/views/kaui/accounts/_account_info.html.erb +108 -0
  79. data/app/views/kaui/accounts/_billing_info.html.erb +129 -0
  80. data/app/views/kaui/accounts/_form.html.erb +127 -115
  81. data/app/views/kaui/accounts/_payment_methods.html.erb +28 -0
  82. data/app/views/kaui/accounts/edit.html.erb +10 -0
  83. data/app/views/kaui/accounts/index.html.erb +38 -23
  84. data/app/views/kaui/accounts/new.html.erb +9 -4
  85. data/app/views/kaui/accounts/show.html.erb +4 -106
  86. data/app/views/kaui/admin_allowed_users/_form.html.erb +19 -0
  87. data/app/views/kaui/admin_allowed_users/index.html.erb +35 -18
  88. data/app/views/kaui/admin_allowed_users/new.html.erb +9 -21
  89. data/app/views/kaui/admin_allowed_users/show.html.erb +42 -50
  90. data/app/views/kaui/admin_tenants/_form.html.erb +25 -0
  91. data/app/views/kaui/admin_tenants/_tenants_table.html.erb +27 -0
  92. data/app/views/kaui/admin_tenants/index.html.erb +14 -23
  93. data/app/views/kaui/admin_tenants/new.html.erb +8 -37
  94. data/app/views/kaui/admin_tenants/show.html.erb +128 -113
  95. data/app/views/kaui/bundle_tags/_form.html.erb +20 -28
  96. data/app/views/kaui/bundle_tags/_form_bar.html.erb +21 -0
  97. data/app/views/kaui/bundle_tags/edit.html.erb +9 -4
  98. data/app/views/kaui/bundles/index.html.erb +76 -29
  99. data/app/views/kaui/bundles/transfer.html.erb +28 -28
  100. data/app/views/kaui/chargebacks/_form.html.erb +31 -29
  101. data/app/views/kaui/chargebacks/new.html.erb +9 -4
  102. data/app/views/kaui/charges/_form.html.erb +35 -59
  103. data/app/views/kaui/charges/new.html.erb +9 -4
  104. data/app/views/kaui/credits/_form.html.erb +32 -59
  105. data/app/views/kaui/credits/new.html.erb +9 -4
  106. data/app/views/kaui/custom_fields/_form.html.erb +31 -0
  107. data/app/views/kaui/custom_fields/index.html.erb +33 -20
  108. data/app/views/kaui/custom_fields/new.html.erb +10 -0
  109. data/app/views/kaui/home/index.html.erb +12 -9
  110. data/app/views/kaui/invoice_items/_edit_form.html.erb +30 -0
  111. data/app/views/kaui/invoice_items/edit.html.erb +10 -91
  112. data/app/views/kaui/invoices/_invoice_table.html.erb +113 -0
  113. data/app/views/kaui/invoices/index.html.erb +31 -22
  114. data/app/views/kaui/invoices/show.html.erb +77 -91
  115. data/app/views/kaui/layouts/kaui_account_navbar.html.erb +11 -0
  116. data/app/views/kaui/layouts/kaui_application.html.erb +14 -53
  117. data/app/views/kaui/layouts/kaui_flash.html.erb +17 -0
  118. data/app/views/kaui/layouts/kaui_footer.html.erb +2 -0
  119. data/app/views/kaui/layouts/kaui_header.html.erb +17 -0
  120. data/app/views/kaui/layouts/kaui_navbar.html.erb +75 -0
  121. data/app/views/kaui/payment_methods/_form.html.erb +26 -23
  122. data/app/views/kaui/payment_methods/_new_creditcard_payment_method.html.erb +46 -41
  123. data/app/views/kaui/payment_methods/_payment_methods_details_table.html.erb +25 -0
  124. data/app/views/kaui/payment_methods/_payment_methods_table.html.erb +50 -52
  125. data/app/views/kaui/payment_methods/new.html.erb +9 -4
  126. data/app/views/kaui/payments/_form.html.erb +55 -0
  127. data/app/views/kaui/payments/_payment_table.html.erb +117 -0
  128. data/app/views/kaui/payments/index.html.erb +31 -22
  129. data/app/views/kaui/payments/new.html.erb +9 -92
  130. data/app/views/kaui/payments/show.html.erb +38 -2
  131. data/app/views/kaui/refunds/_form.html.erb +240 -0
  132. data/app/views/kaui/refunds/new.html.erb +8 -280
  133. data/app/views/kaui/registrations/_form.html.erb +19 -0
  134. data/app/views/kaui/registrations/new.html.erb +10 -0
  135. data/app/views/kaui/sessions/_form.html.erb +19 -0
  136. data/app/views/kaui/sessions/new.html.erb +7 -18
  137. data/app/views/kaui/subscriptions/_edit_form.html.erb +26 -0
  138. data/app/views/kaui/subscriptions/_form.html.erb +34 -31
  139. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +37 -24
  140. data/app/views/kaui/subscriptions/edit.html.erb +10 -30
  141. data/app/views/kaui/subscriptions/new.html.erb +14 -11
  142. data/app/views/kaui/tag_definitions/_form.html.erb +14 -11
  143. data/app/views/kaui/tag_definitions/index.html.erb +56 -30
  144. data/app/views/kaui/tag_definitions/new.html.erb +9 -2
  145. data/app/views/kaui/tags/_tags_table.html.erb +7 -10
  146. data/app/views/kaui/tags/index.html.erb +29 -20
  147. data/app/views/kaui/tenants/_form.html.erb +13 -0
  148. data/app/views/kaui/tenants/index.html.erb +9 -16
  149. data/app/views/kaui/transactions/_form.html.erb +47 -67
  150. data/app/views/kaui/transactions/new.html.erb +9 -2
  151. data/config/initializers/killbill_registerable.rb +4 -0
  152. data/config/routes.rb +88 -93
  153. data/kaui.gemspec +11 -2
  154. data/lib/kaui/engine.rb +6 -4
  155. data/lib/kaui/version.rb +1 -1
  156. data/lib/kaui.rb +24 -1
  157. data/test/dummy/config/application.rb +2 -0
  158. data/test/dummy/config/database.yml +6 -3
  159. data/test/dummy/config/initializers/killbill_client.rb +0 -2
  160. data/test/fixtures/catalog-v1.xml +74 -0
  161. data/test/fixtures/catalog_translation_fr-v1.properties +1 -0
  162. data/test/fixtures/invoice_template-v1.html +100 -0
  163. data/test/fixtures/invoice_translation_fr-v1.properties +23 -0
  164. data/test/fixtures/overdue-v1.xml +49 -0
  165. data/test/fixtures/stripe.yml +2 -0
  166. data/test/functional/kaui/account_emails_controller_test.rb +35 -8
  167. data/test/functional/kaui/account_tags_controller_test.rb +8 -8
  168. data/test/functional/kaui/account_timelines_controller_test.rb +6 -7
  169. data/test/functional/kaui/accounts_controller_test.rb +72 -10
  170. data/test/functional/kaui/admin_allowed_users_controller_test.rb +6 -5
  171. data/test/functional/kaui/admin_tenants_controller_test.rb +104 -48
  172. data/test/functional/kaui/bundle_tags_controller_test.rb +14 -9
  173. data/test/functional/kaui/bundles_controller_test.rb +59 -23
  174. data/test/functional/kaui/chargebacks_controller_test.rb +29 -7
  175. data/test/functional/kaui/charges_controller_test.rb +31 -10
  176. data/test/functional/kaui/credits_controller_test.rb +25 -6
  177. data/test/functional/kaui/custom_fields_controller_test.rb +25 -1
  178. data/test/functional/kaui/functional_test_helper_nosetup.rb +6 -4
  179. data/test/functional/kaui/home_controller_test.rb +24 -0
  180. data/test/functional/kaui/invoice_items_controller_test.rb +56 -8
  181. data/test/functional/kaui/invoices_controller_test.rb +27 -18
  182. data/test/functional/kaui/payment_methods_controller_test.rb +2 -22
  183. data/test/functional/kaui/payments_controller_test.rb +8 -3
  184. data/test/functional/kaui/refunds_controller_test.rb +40 -21
  185. data/test/functional/kaui/subscriptions_controller_test.rb +77 -24
  186. data/test/functional/kaui/tag_definitions_controller_test.rb +1 -7
  187. data/test/functional/kaui/tags_controller_test.rb +1 -1
  188. data/test/functional/kaui/tenants_controller_test.rb +9 -9
  189. data/test/functional/kaui/transactions_controller_test.rb +41 -16
  190. data/test/integration/kaui/integration_test_helper.rb +0 -1
  191. data/test/integration/kaui/navigation_test.rb +4 -6
  192. data/test/test_helper.rb +2 -0
  193. metadata +155 -28
  194. data/Gemfile.lock +0 -210
  195. data/app/assets/stylesheets/bootstrap_and_overrides.css +0 -7
  196. data/app/assets/stylesheets/datatables.scss +0 -14
  197. data/app/assets/stylesheets/layout.scss +0 -19
  198. data/app/views/kaui/account_emails/show.html.erb +0 -25
  199. data/app/views/kaui/account_tags/_account_tags_table.html.erb +0 -32
  200. data/app/views/kaui/account_tags/show.html.erb +0 -6
  201. data/app/views/kaui/account_timelines/index.html.erb +0 -14
  202. data/app/views/kaui/bundle_tags/_bundle_tags_table.html.erb +0 -31
  203. data/app/views/kaui/bundle_tags/show.html.erb +0 -6
  204. data/app/views/kaui/bundles/show.html.erb +0 -18
  205. data/app/views/kaui/payment_methods/index.html.erb +0 -30
  206. data/app/views/kaui/payment_methods/show.html.erb +0 -3
  207. data/app/views/kaui/payments/_payments_table.html.erb +0 -41
  208. data/app/views/kaui/subscriptions/index.html.erb +0 -15
  209. data/app/views/kaui/subscriptions/show.html.erb +0 -33
  210. data/app/views/kaui/tag_definitions/show.html.erb +0 -15
  211. data/vendor/assets/images/img/glyphicons-halflings-white.png +0 -0
  212. data/vendor/assets/images/img/glyphicons-halflings.png +0 -0
  213. data/vendor/assets/stylesheets/css/bootstrap-datepicker.cd46d38.css +0 -274
@@ -1,195 +1,200 @@
1
- module Kaui
2
- class AdminTenantsController < Kaui::EngineController
1
+ class Kaui::AdminTenantsController < Kaui::EngineController
3
2
 
4
- skip_before_filter :check_for_redirect_to_tenant_screen
3
+ skip_before_filter :check_for_redirect_to_tenant_screen
5
4
 
6
- def index
7
- # Display the configured tenants in KAUI (which could be different than the existing tenants known by Kill Bill)
8
- @tenants = Kaui::Tenant.all
9
- render
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
- def new
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
- def create
17
- param_tenant = params[:tenant]
18
- old_tenant = Kaui::Tenant.find_by_name(param_tenant[:name])
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 = tenant_options_for_client
27
- new_tenant = nil
28
-
29
- if params[:create_tenant]
30
- # Create the tenant in Kill Bill
31
- new_tenant = Kaui::AdminTenant.new
32
- new_tenant.external_key = param_tenant[:name]
33
- new_tenant.api_key = param_tenant[:api_key]
34
- new_tenant.api_secret = param_tenant[:api_secret]
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
- redirect_to admin_tenant_path(tenant_model[:id]), :notice => 'Tenant was successfully configured'
57
- end
58
-
59
- def show
60
- @tenant = Kaui::Tenant.find(params[:id])
61
- user = current_user
62
- if @tenant.kaui_allowed_users.index { |e| e.kb_username == user.kb_username}.nil?
63
- flash[:error] = "Does not have permissions to see tenant id #{params[:id]}"
64
- redirect_to admin_tenants_path and return
65
- end
66
- render
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
- def upload_catalog
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
- current_tenant = Kaui::Tenant.find_by_id(params[:id])
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
- def upload_overdue_config
86
- current_tenant = Kaui::Tenant.find_by_id(params[:id])
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
- options = tenant_options_for_client
89
- options[:api_key] = current_tenant.api_key
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
- uploaded_overdue_config = params[:overdue]
93
- overdue_config_xml = uploaded_overdue_config.read
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
- Kaui::AdminTenant.upload_overdue_config(overdue_config_xml, options[:username], nil, comment, options)
84
+ uploaded_catalog = params[:catalog]
85
+ catalog_xml = uploaded_catalog.read
96
86
 
97
- redirect_to admin_tenants_path, :notice => 'Overdue config was successfully uploaded'
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
- def upload_invoice_template
102
- current_tenant = Kaui::Tenant.find_by_id(params[:id])
92
+ def upload_overdue_config
93
+ current_tenant = safely_find_tenant_by_id(params[:id])
103
94
 
104
- options = tenant_options_for_client
105
- options[:api_key] = current_tenant.api_key
106
- options[:api_secret] = current_tenant.api_secret
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
- is_manual_pay = params[:manual_pay]
109
- uploaded_invoice_template = params[:invoice_template]
110
- invoice_template = uploaded_invoice_template.read
99
+ uploaded_overdue_config = params[:overdue]
100
+ overdue_config_xml = uploaded_overdue_config.read
111
101
 
112
- Kaui::AdminTenant.upload_invoice_template(invoice_template, is_manual_pay, true, options[:username], nil, comment, options)
102
+ Kaui::AdminTenant.upload_overdue_config(overdue_config_xml, options[:username], nil, comment, options)
113
103
 
114
- redirect_to admin_tenants_path, :notice => 'Invoice template was successfully uploaded'
104
+ redirect_to admin_tenant_path(current_tenant.id), :notice => 'Overdue config was successfully uploaded'
105
+ end
115
106
 
116
- end
117
107
 
118
- def upload_invoice_translation
119
- current_tenant = Kaui::Tenant.find_by_id(params[:id])
108
+ def upload_invoice_template
109
+ current_tenant = safely_find_tenant_by_id(params[:id])
120
110
 
121
- options = tenant_options_for_client
122
- options[:api_key] = current_tenant.api_key
123
- options[:api_secret] = current_tenant.api_secret
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
- locale = params[:translation_locale]
126
- uploaded_invoice_translation = params[:invoice_translation]
127
- invoice_translation = uploaded_invoice_translation.read
115
+ is_manual_pay = params[:manual_pay]
116
+ uploaded_invoice_template = params[:invoice_template]
117
+ invoice_template = uploaded_invoice_template.read
128
118
 
129
- Kaui::AdminTenant.upload_invoice_translation(invoice_translation, locale, true, options[:username], nil, comment, options)
119
+ Kaui::AdminTenant.upload_invoice_template(invoice_template, is_manual_pay, true, options[:username], nil, comment, options)
130
120
 
131
- redirect_to admin_tenants_path, :notice => 'Invoice translation was successfully uploaded'
121
+ redirect_to admin_tenant_path(current_tenant.id), :notice => 'Invoice template was successfully uploaded'
122
+ end
132
123
 
133
- end
124
+ def upload_invoice_translation
125
+ current_tenant = safely_find_tenant_by_id(params[:id])
134
126
 
135
- def upload_catalog_translation
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
- current_tenant = Kaui::Tenant.find_by_id(params[:id])
131
+ locale = params[:translation_locale]
132
+ uploaded_invoice_translation = params[:invoice_translation]
133
+ invoice_translation = uploaded_invoice_translation.read
138
134
 
139
- options = tenant_options_for_client
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
- locale = params[:translation_locale]
144
- uploaded_catalog_translation = params[:catalog_translation]
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
- Kaui::AdminTenant.upload_catalog_translation(catalog_translation, locale, true, options[:username], nil, comment, options)
140
+ def upload_catalog_translation
141
+ current_tenant = safely_find_tenant_by_id(params[:id])
148
142
 
149
- redirect_to admin_tenants_path, :notice => 'Catalog translation was successfully uploaded'
150
- end
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
- def upload_plugin_config
151
+ Kaui::AdminTenant.upload_catalog_translation(catalog_translation, locale, true, options[:username], nil, comment, options)
154
152
 
155
- current_tenant = Kaui::Tenant.find_by_id(params[:id])
153
+ redirect_to admin_tenant_path(current_tenant.id), :notice => 'Catalog translation was successfully uploaded'
154
+ end
156
155
 
157
- options = tenant_options_for_client
158
- options[:api_key] = current_tenant.api_key
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
- plugin_name = params[:plugin_name]
162
- uploaded_plugin_config = params[:plugin_config]
163
- plugin_config = uploaded_plugin_config.read
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
- Kaui::AdminTenant.upload_tenant_plugin_config(plugin_name, plugin_config, options[:username], nil, comment, options)
163
+ plugin_name = params[:plugin_name]
164
+ uploaded_plugin_config = params[:plugin_config]
165
+ plugin_config = uploaded_plugin_config.read
166
166
 
167
- redirect_to admin_tenants_path, :notice => 'Config for plugin was successfully uploaded'
167
+ Kaui::AdminTenant.upload_tenant_plugin_config(plugin_name, plugin_config, options[:username], nil, comment, options)
168
168
 
169
- end
169
+ redirect_to admin_tenant_path(current_tenant.id), :notice => 'Config for plugin was successfully uploaded'
170
+ end
170
171
 
171
- def remove_allowed_user
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
- current_tenant = Kaui::Tenant.find_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
180
+ private
179
181
 
180
- private
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
- def tenant_options_for_client
183
- user = current_user
184
- {
185
- :username => user.kb_username,
186
- :password => user.password,
187
- :session_id => user.kb_session_id
188
- }
189
- end
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
- def comment
192
- 'Multi-tenant Administrative operation'
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
- bundle_id_or_key = params[:bundle_id]
19
- account_id = params[:account_id]
4
+ @bundle_id = params.require(:bundle_id)
20
5
 
21
- begin
22
- @bundle = Kaui::Bundle::find_by_id_or_key(bundle_id_or_key, account_id, options_for_klient)
23
- @tag_names = (@bundle.tags(false, 'NONE', options_for_klient).map { |tag| tag.tag_definition_name }).sort
24
- @available_tags = Kaui::TagDefinition.all_for_bundle(options_for_klient)
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
- bundle_id = params[:bundle_id]
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
- begin
42
- bundle = Kaui::Bundle.new(:bundle_id => bundle_id)
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
- end
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
- json = {
14
- :sEcho => params[:sEcho],
15
- :iTotalRecords => bundles.pagination_max_nb_records,
16
- :iTotalDisplayRecords => bundles.pagination_total_nb_records,
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
- bundles.each do |bundle|
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
- respond_to do |format|
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
- def show
35
- begin
36
- @bundle = Kaui::Bundle::find_by_id_or_key(params[:id], nil, options_for_klient)
37
- @account = Kaui::Account::find_by_id(@bundle.account_id, false, false, options_for_klient)
38
- @tags = @bundle.tags(false, 'NONE', options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b }
39
- rescue => e
40
- flash.now[:error] = "Error while retrieving bundle information: #{as_string(e)}"
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
- begin
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
- key = params[:new_account_key]
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
- begin
71
- billing_policy = params[:billing_policy]
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
- bundle = Kaui::Bundle::new(:bundle_id => params[:id], :account_id => new_account.account_id)
74
- bundle.transfer(nil, billing_policy, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
36
+ redirect_to kaui_engine.account_bundles_path(new_account.account_id), :notice => 'Bundle was successfully transferred'
37
+ end
75
38
 
76
- redirect_to account_path(new_account.account_id), :notice => 'Bundle was successfully transferred'
77
- rescue => e
78
- flash.now[:error] = "Error while transferring bundle: #{as_string(e)}"
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
- begin
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 => payment.paid_amount_to_money.to_f,
13
- :currency => payment.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 = Kaui::Chargeback.new(params[: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.account_timeline_path(:id => payment.account_id), :notice => 'Chargeback created'
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
- account_id = params[:account_id]
6
- currency = params[:currency] || 'USD'
5
+ amount = params[:amount]
7
6
 
8
7
  if invoice_id.present?
9
- begin
10
- @invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
11
- account_id = @invoice.account_id
12
- currency = @invoice.currency
13
- rescue => e
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
- @charge = Kaui::InvoiceItem.new(params[:invoice_item].delete_if { |key, value| value.blank? })
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
- begin
25
- @charge = @charge.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
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
- account_id = params[:account_id]
6
- amount = params[:amount]
7
- currency = params[:currency] || 'USD'
5
+ amount = params[:amount]
8
6
 
9
7
  if invoice_id.present?
10
- begin
11
- @invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
12
- account_id = @invoice.account_id
13
- amount ||= @invoice.balance
14
- currency = @invoice.currency
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
- # TODO Specifying a custom currency is not supported yet
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
- @credit = Kaui::Credit.new(params[:credit].delete_if { |key, value| value.blank? })
19
+ credit = Kaui::Credit.new(params[:credit].delete_if { |key, value| value.blank? })
20
+ credit.account_id ||= params.require(:account_id)
28
21
 
29
- begin
30
- @credit = @credit.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
31
- redirect_to kaui_engine.invoice_path(:id => @credit.invoice_id), :notice => 'Credit was successfully created'
32
- rescue => e
33
- flash.now[:error] = "Error while creating a credit: #{as_string(e)}"
34
- render :action => :new
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