kaui 2.1.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +8 -7
  3. data/Rakefile +4 -2
  4. data/app/assets/config/kaui_manifest.js +45 -0
  5. data/app/assets/javascripts/jquery.spin.js +76 -0
  6. data/app/assets/javascripts/kaui/kaui.js +76 -0
  7. data/app/assets/javascripts/kaui_application.js +25 -0
  8. data/app/assets/javascripts/spin.js +76 -0
  9. data/app/assets/stylesheets/bootstrap_and_overrides.scss +240 -0
  10. data/app/assets/stylesheets/kaui/{account.less → account.scss} +4 -0
  11. data/app/assets/stylesheets/kaui/{audit.less → audit.scss} +5 -1
  12. data/app/assets/stylesheets/kaui/{common.less → common.scss} +17 -15
  13. data/app/assets/stylesheets/kaui/{datatable.less → datatable.scss} +6 -3
  14. data/app/assets/stylesheets/kaui/{header.less → header.scss} +16 -12
  15. data/app/assets/stylesheets/kaui/{home.less → home.scss} +7 -4
  16. data/app/assets/stylesheets/kaui/{invoice.less → invoice.scss} +7 -3
  17. data/app/assets/stylesheets/kaui/kaui.scss +265 -0
  18. data/app/assets/stylesheets/kaui/kaui_bootstrap.scss +3 -0
  19. data/app/assets/stylesheets/kaui/{overdue.less → overdue.scss} +3 -1
  20. data/app/assets/stylesheets/kaui/{payment.less → payment.scss} +3 -0
  21. data/app/assets/stylesheets/kaui/{subscription.less → subscription.scss} +4 -1
  22. data/app/assets/stylesheets/kaui/{tags.less → tags.scss} +9 -5
  23. data/app/assets/stylesheets/kaui/timeline.scss +7 -0
  24. data/app/assets/stylesheets/kaui/tooltip.scss +15 -0
  25. data/app/controllers/kaui/account_children_controller.rb +25 -28
  26. data/app/controllers/kaui/account_custom_fields_controller.rb +16 -15
  27. data/app/controllers/kaui/account_emails_controller.rb +28 -25
  28. data/app/controllers/kaui/account_tags_controller.rb +37 -34
  29. data/app/controllers/kaui/account_timelines_controller.rb +38 -33
  30. data/app/controllers/kaui/accounts_controller.rb +268 -250
  31. data/app/controllers/kaui/admin_allowed_users_controller.rb +105 -99
  32. data/app/controllers/kaui/admin_controller.rb +32 -31
  33. data/app/controllers/kaui/admin_tenants_controller.rb +434 -388
  34. data/app/controllers/kaui/audit_logs_controller.rb +86 -83
  35. data/app/controllers/kaui/bundle_tags_controller.rb +24 -20
  36. data/app/controllers/kaui/bundles_controller.rb +96 -82
  37. data/app/controllers/kaui/chargebacks_controller.rb +36 -33
  38. data/app/controllers/kaui/charges_controller.rb +23 -20
  39. data/app/controllers/kaui/credits_controller.rb +28 -25
  40. data/app/controllers/kaui/custom_fields_controller.rb +172 -38
  41. data/app/controllers/kaui/engine_controller.rb +2 -1
  42. data/app/controllers/kaui/engine_controller_util.rb +128 -117
  43. data/app/controllers/kaui/home_controller.rb +230 -217
  44. data/app/controllers/kaui/invoice_items_controller.rb +43 -39
  45. data/app/controllers/kaui/invoice_tags_controller.rb +24 -20
  46. data/app/controllers/kaui/invoices_controller.rb +132 -117
  47. data/app/controllers/kaui/login_proxy_controller.rb +2 -1
  48. data/app/controllers/kaui/payment_methods_controller.rb +102 -94
  49. data/app/controllers/kaui/payments_controller.rb +95 -92
  50. data/app/controllers/kaui/queues_controller.rb +47 -14
  51. data/app/controllers/kaui/refunds_controller.rb +36 -33
  52. data/app/controllers/kaui/registrations_controller.rb +7 -7
  53. data/app/controllers/kaui/role_definitions_controller.rb +17 -14
  54. data/app/controllers/kaui/sessions_controller.rb +7 -4
  55. data/app/controllers/kaui/subscriptions_controller.rb +197 -187
  56. data/app/controllers/kaui/tag_definitions_controller.rb +28 -27
  57. data/app/controllers/kaui/tags_controller.rb +25 -22
  58. data/app/controllers/kaui/tenants_controller.rb +30 -28
  59. data/app/controllers/kaui/transactions_controller.rb +43 -38
  60. data/app/helpers/kaui/account_helper.rb +16 -14
  61. data/app/helpers/kaui/application_helper.rb +8 -3
  62. data/app/helpers/kaui/date_helper.rb +4 -3
  63. data/app/helpers/kaui/home_helper.rb +2 -0
  64. data/app/helpers/kaui/locale_helper.rb +7 -6
  65. data/app/helpers/kaui/money_helper.rb +2 -1
  66. data/app/helpers/kaui/object_helper.rb +11 -10
  67. data/app/helpers/kaui/payment_helper.rb +7 -6
  68. data/app/helpers/kaui/payment_method_helper.rb +3 -2
  69. data/app/helpers/kaui/permissions_helper.rb +9 -9
  70. data/app/helpers/kaui/plugin_helper.rb +25 -23
  71. data/app/helpers/kaui/subscription_helper.rb +27 -29
  72. data/app/helpers/kaui/us_states_helper.rb +7 -6
  73. data/app/helpers/kaui/uuid_helper.rb +8 -6
  74. data/app/models/kaui/ability.rb +19 -12
  75. data/app/models/kaui/account.rb +45 -28
  76. data/app/models/kaui/account_email.rb +23 -20
  77. data/app/models/kaui/account_timeline.rb +5 -1
  78. data/app/models/kaui/admin.rb +65 -64
  79. data/app/models/kaui/admin_tenant.rb +81 -82
  80. data/app/models/kaui/allowed_user.rb +13 -9
  81. data/app/models/kaui/allowed_user_tenant.rb +4 -2
  82. data/app/models/kaui/application_record.rb +2 -0
  83. data/app/models/kaui/audit_log.rb +6 -3
  84. data/app/models/kaui/base.rb +13 -7
  85. data/app/models/kaui/bundle.rb +41 -24
  86. data/app/models/kaui/catalog.rb +118 -113
  87. data/app/models/kaui/chargeback.rb +5 -1
  88. data/app/models/kaui/credit.rb +4 -1
  89. data/app/models/kaui/custom_field.rb +9 -6
  90. data/app/models/kaui/invoice.rb +25 -22
  91. data/app/models/kaui/invoice_item.rb +9 -6
  92. data/app/models/kaui/invoice_payment.rb +49 -54
  93. data/app/models/kaui/killbill_authenticatable.rb +14 -8
  94. data/app/models/kaui/killbill_registerable.rb +7 -0
  95. data/app/models/kaui/overdue.rb +64 -65
  96. data/app/models/kaui/payment.rb +22 -19
  97. data/app/models/kaui/payment_method.rb +48 -39
  98. data/app/models/kaui/payment_state.rb +41 -38
  99. data/app/models/kaui/rails_methods.rb +9 -9
  100. data/app/models/kaui/refund.rb +7 -1
  101. data/app/models/kaui/role_definition.rb +5 -1
  102. data/app/models/kaui/simple_plan.rb +5 -3
  103. data/app/models/kaui/subscription.rb +10 -7
  104. data/app/models/kaui/tag.rb +25 -22
  105. data/app/models/kaui/tag_definition.rb +50 -45
  106. data/app/models/kaui/tenant.rb +6 -5
  107. data/app/models/kaui/transaction.rb +43 -31
  108. data/app/models/kaui/user.rb +10 -16
  109. data/app/models/kaui/user_role.rb +8 -5
  110. data/app/views/kaui/accounts/_billing_info.html.erb +1 -1
  111. data/app/views/kaui/accounts/_form.html.erb +2 -2
  112. data/app/views/kaui/accounts/index.html.erb +2 -0
  113. data/app/views/kaui/admin_allowed_users/_form.html.erb +3 -3
  114. data/app/views/kaui/admin_tenants/_form_catalog_translation.erb +1 -1
  115. data/app/views/kaui/admin_tenants/_form_invoice_template.erb +1 -1
  116. data/app/views/kaui/admin_tenants/_form_invoice_translation.erb +1 -1
  117. data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +11 -5
  118. data/app/views/kaui/admin_tenants/new_catalog.html.erb +2 -2
  119. data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +2 -2
  120. data/app/views/kaui/admin_tenants/new_plan_currency.html.erb +1 -1
  121. data/app/views/kaui/bundles/index.html.erb +1 -1
  122. data/app/views/kaui/bundles/transfer.html.erb +13 -5
  123. data/app/views/kaui/invoices/_invoice_table.html.erb +1 -1
  124. data/app/views/kaui/layouts/kaui_flash.html.erb +24 -0
  125. data/app/views/kaui/layouts/kaui_header.html.erb +19 -2
  126. data/app/views/kaui/payment_methods/_payment_methods_details_table.html.erb +13 -4
  127. data/app/views/kaui/payments/_payment_table.html.erb +21 -11
  128. data/app/views/kaui/payments/index.html.erb +9 -9
  129. data/app/views/kaui/queues/index.html.erb +1 -1
  130. data/app/views/kaui/subscriptions/_cancel_by_date_modal.html.erb +1 -4
  131. data/app/views/kaui/subscriptions/_edit_form.html.erb +1 -1
  132. data/app/views/kaui/subscriptions/_form.html.erb +1 -1
  133. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +3 -3
  134. data/app/views/kaui/subscriptions/edit_bcd.erb +1 -1
  135. data/app/views/kaui/tag_definitions/index.html.erb +2 -2
  136. data/app/views/kaui/tags/index.html.erb +1 -0
  137. data/config/initializers/bootstrap_datepicker_rails.rb +3 -0
  138. data/config/initializers/devise.rb +8 -6
  139. data/config/initializers/js_routes.rb +9 -0
  140. data/config/initializers/kilbill_client_init.rb +13 -0
  141. data/config/initializers/killbill_authenticatable.rb +71 -21
  142. data/config/initializers/killbill_registerable.rb +5 -3
  143. data/config/initializers/time_formats.rb +6 -4
  144. data/config/locales/en.yml +78 -1
  145. data/config/routes.rb +34 -32
  146. data/db/migrate/20130812155313_devise_create_kaui_users.rb +10 -8
  147. data/db/migrate/20150109214021_create_kaui_tenants.rb +10 -8
  148. data/db/migrate/20150112232813_create_kaui_allowed_users.rb +10 -8
  149. data/lib/generators/kaui/install/install_generator.rb +23 -20
  150. data/lib/generators/kaui/install/templates/config/initializers/kaui.rb +3 -1
  151. data/lib/kaui/engine.rb +17 -5
  152. data/lib/kaui/installer/installer.rb +27 -26
  153. data/lib/kaui/version.rb +3 -1
  154. data/lib/kaui.rb +28 -30
  155. data/lib/tasks/kaui_tasks.rake +1 -0
  156. metadata +136 -438
  157. data/app/assets/javascripts/application.js +0 -17
  158. data/app/assets/javascripts/kaui/bootstrap-tweaks.js +0 -172
  159. data/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -44
  160. data/app/assets/stylesheets/kaui/kaui.less +0 -21
  161. data/app/assets/stylesheets/kaui/timeline.less +0 -4
  162. data/config/initializers/asset.rb +0 -1
  163. data/config/initializers/kilbill-client-init.rb +0 -9
  164. data/db/schema.rb +0 -15
  165. data/test/dummy/README.rdoc +0 -261
  166. data/test/dummy/Rakefile +0 -7
  167. data/test/dummy/app/controllers/application_controller.rb +0 -9
  168. data/test/dummy/app/helpers/application_helper.rb +0 -2
  169. data/test/dummy/bin/bundle +0 -3
  170. data/test/dummy/bin/rails +0 -4
  171. data/test/dummy/bin/rake +0 -4
  172. data/test/dummy/bin/setup +0 -38
  173. data/test/dummy/bin/update +0 -29
  174. data/test/dummy/bin/yarn +0 -11
  175. data/test/dummy/config/application.rb +0 -18
  176. data/test/dummy/config/boot.rb +0 -3
  177. data/test/dummy/config/database.yml +0 -27
  178. data/test/dummy/config/environment.rb +0 -5
  179. data/test/dummy/config/environments/development.rb +0 -58
  180. data/test/dummy/config/environments/production.rb +0 -91
  181. data/test/dummy/config/environments/test.rb +0 -49
  182. data/test/dummy/config/initializers/application_controller_renderer.rb +0 -6
  183. data/test/dummy/config/initializers/assets.rb +0 -14
  184. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  185. data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
  186. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  187. data/test/dummy/config/initializers/inflections.rb +0 -16
  188. data/test/dummy/config/initializers/killbill_client.rb +0 -1
  189. data/test/dummy/config/initializers/mime_types.rb +0 -4
  190. data/test/dummy/config/initializers/money.rb +0 -2
  191. data/test/dummy/config/initializers/new_framework_defaults_5_1.rb +0 -14
  192. data/test/dummy/config/initializers/secret_token.rb +0 -7
  193. data/test/dummy/config/initializers/session_store.rb +0 -8
  194. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  195. data/test/dummy/config/locales/en.yml +0 -33
  196. data/test/dummy/config/routes.rb +0 -3
  197. data/test/dummy/config/secrets.yml +0 -32
  198. data/test/dummy/config/symmetric-encryption.yml +0 -135
  199. data/test/dummy/config.ru +0 -4
  200. data/test/dummy/db/schema.rb +0 -52
  201. data/test/dummy/public/404.html +0 -26
  202. data/test/dummy/public/422.html +0 -26
  203. data/test/dummy/public/500.html +0 -25
  204. data/test/dummy/public/favicon.ico +0 -0
  205. data/test/dummy/script/rails +0 -6
  206. data/test/fixtures/SpyCarAdvanced.xml +0 -824
  207. data/test/fixtures/catalog-v1.xml +0 -73
  208. data/test/fixtures/catalog_translation_fr-v1.properties +0 -1
  209. data/test/fixtures/invoice_template-v1.html +0 -100
  210. data/test/fixtures/invoice_translation_fr-v1.properties +0 -23
  211. data/test/fixtures/overdue-v1.xml +0 -49
  212. data/test/fixtures/stripe.yml +0 -2
  213. data/test/functional/kaui/account_children_controller_test.rb +0 -32
  214. data/test/functional/kaui/account_custom_fields_controller_test.rb +0 -29
  215. data/test/functional/kaui/account_emails_controller_test.rb +0 -55
  216. data/test/functional/kaui/account_tags_controller_test.rb +0 -48
  217. data/test/functional/kaui/account_timelines_controller_test.rb +0 -20
  218. data/test/functional/kaui/accounts_controller_test.rb +0 -297
  219. data/test/functional/kaui/admin_allowed_users_controller_test.rb +0 -234
  220. data/test/functional/kaui/admin_controller_test.rb +0 -45
  221. data/test/functional/kaui/admin_tenants_controller_test.rb +0 -352
  222. data/test/functional/kaui/audit_logs_controller_test.rb +0 -71
  223. data/test/functional/kaui/bundle_tags_controller_test.rb +0 -23
  224. data/test/functional/kaui/bundles_controller_test.rb +0 -130
  225. data/test/functional/kaui/chargebacks_controller_test.rb +0 -42
  226. data/test/functional/kaui/charges_controller_test.rb +0 -60
  227. data/test/functional/kaui/credits_controller_test.rb +0 -54
  228. data/test/functional/kaui/custom_fields_controller_test.rb +0 -52
  229. data/test/functional/kaui/functional_test_helper.rb +0 -13
  230. data/test/functional/kaui/functional_test_helper_nosetup.rb +0 -120
  231. data/test/functional/kaui/home_controller_test.rb +0 -407
  232. data/test/functional/kaui/invoice_items_controller_test.rb +0 -82
  233. data/test/functional/kaui/invoices_controller_test.rb +0 -88
  234. data/test/functional/kaui/login_proxy_controller_test.rb +0 -12
  235. data/test/functional/kaui/payment_methods_controller_test.rb +0 -52
  236. data/test/functional/kaui/payments_controller_test.rb +0 -59
  237. data/test/functional/kaui/queues_controller_test.rb +0 -17
  238. data/test/functional/kaui/refunds_controller_test.rb +0 -63
  239. data/test/functional/kaui/registrations_controller_test.rb +0 -49
  240. data/test/functional/kaui/role_definitions_controller_test.rb +0 -47
  241. data/test/functional/kaui/subscriptions_controller_test.rb +0 -194
  242. data/test/functional/kaui/tag_definitions_controller_test.rb +0 -29
  243. data/test/functional/kaui/tags_controller_test.rb +0 -21
  244. data/test/functional/kaui/tenants_controller_test.rb +0 -60
  245. data/test/functional/kaui/transactions_controller_test.rb +0 -90
  246. data/test/integration/kaui/date_helper_integration_test.rb +0 -16
  247. data/test/integration/kaui/integration_test_helper.rb +0 -32
  248. data/test/integration/kaui/navigation_test.rb +0 -43
  249. data/test/killbill_test_helper.rb +0 -219
  250. data/test/test_helper.rb +0 -22
  251. data/test/unit/helpers/kaui/admin_allowed_users_helper_test.rb +0 -6
  252. data/test/unit/helpers/kaui/admin_tenants_helper_test.rb +0 -6
  253. data/test/unit/helpers/kaui/payment_method_helper_test.rb +0 -17
  254. data/test/unit/helpers/kaui/tenants_helper_test.rb +0 -6
  255. data/test/unit/helpers/kaui/uuid_helper_test.rb +0 -16
  256. data/test/unit/kaui/account_email_test.rb +0 -19
  257. data/test/unit/kaui/account_test.rb +0 -14
  258. data/test/unit/kaui/admin_tenant_test.rb +0 -132
  259. data/test/unit/kaui/allowed_user_test.rb +0 -34
  260. data/test/unit/kaui/base_test.rb +0 -23
  261. data/test/unit/kaui/date_helper_test.rb +0 -26
  262. data/test/unit/kaui/invoice_item_test.rb +0 -11
  263. data/test/unit/kaui/invoice_payment_test.rb +0 -42
  264. data/test/unit/kaui/invoice_test.rb +0 -20
  265. data/test/unit/kaui/money_helper_test.rb +0 -16
  266. data/test/unit/kaui/payment_test.rb +0 -42
  267. data/test/unit/kaui/tag_definition_test.rb +0 -11
  268. data/test/unit/kaui/tenant_test.rb +0 -19
  269. /data/app/assets/stylesheets/{application.css → kaui_application.css} +0 -0
@@ -1,288 +1,301 @@
1
- class Kaui::HomeController < Kaui::EngineController
1
+ # frozen_string_literal: true
2
2
 
3
- QUERY_PARSE_REGEX = ['FIND:(?<object_type>.*) BY:(?<search_by>.*) FOR:(?<search_for>.*) ONLY_FIRST:(?<fast>.*)',
4
- 'FIND:(?<object_type>.*) BY:(?<search_by>.*) FOR:(?<search_for>.*)',
5
- 'FIND:(?<object_type>.*) FOR:(?<search_for>.*) ONLY_FIRST:(?<fast>.*)',
6
- 'FIND:(?<object_type>.*) FOR:(?<search_for>.*)']
3
+ module Kaui
4
+ class HomeController < Kaui::EngineController
5
+ QUERY_PARSE_REGEX = ['FIND:(?<object_type>.*) BY:(?<search_by>.*) FOR:(?<search_for>.*) ONLY_FIRST:(?<fast>.*)',
6
+ 'FIND:(?<object_type>.*) BY:(?<search_by>.*) FOR:(?<search_for>.*)',
7
+ 'FIND:(?<object_type>.*) FOR:(?<search_for>.*) ONLY_FIRST:(?<fast>.*)',
8
+ 'FIND:(?<object_type>.*) FOR:(?<search_for>.*)'].freeze
7
9
 
8
- SIMPLE_PARSE_REGEX = '(?<search_for>.*)'
10
+ SIMPLE_PARSE_REGEX = '(?<search_for>.*)'
9
11
 
10
- def index
11
- @search_query = params[:q]
12
- end
12
+ def index
13
+ @search_query = params[:q]
14
+ end
15
+
16
+ def search
17
+ object_type, search_query, search_by, fast = parse_query(params[:q])
13
18
 
14
- def search
15
- object_type, search_query, search_by, fast = parse_query(params[:q])
19
+ return if object_type.nil?
16
20
 
17
- unless object_type.nil?
18
21
  cached_options_for_klient = options_for_klient
19
22
  send("#{object_type}_search", search_query, search_by, fast, cached_options_for_klient)
20
23
  end
21
- end
22
24
 
23
- private
25
+ private
24
26
 
25
- def account_search(search_query, search_by = nil, fast = 0, options = {})
26
- if search_by == 'ID'
27
- begin
28
- account = Kaui::Account.find_by_id(search_query, false, false, options)
29
- redirect_to account_path(account.account_id) and return
30
- rescue KillBillClient::API::NotFound => _
31
- search_error("No account matches \"#{search_query}\"")
32
- end
33
- elsif search_by == 'EXTERNAL_KEY'
34
- begin
35
- account = Kaui::Account.find_by_external_key(search_query, false, false, options)
36
- redirect_to account_path(account.account_id) and return
37
- rescue KillBillClient::API::NotFound => _
38
- search_error("No account matches \"#{search_query}\"")
39
- end
40
- else
41
- account = Kaui::Account.list_or_search(search_query, 0, 1, options).first
42
- if account.blank?
43
- search_error("No account matches \"#{search_query}\"")
44
- elsif true?(fast)
45
- redirect_to account_path(account.account_id) and return
27
+ def account_search(search_query, search_by = nil, fast = 0, options = {})
28
+ if search_by == 'ID'
29
+ begin
30
+ account = Kaui::Account.find_by_id(search_query, false, false, options)
31
+ redirect_to account_path(account.account_id) and return
32
+ rescue KillBillClient::API::NotFound => _e
33
+ search_error("No account matches \"#{search_query}\"")
34
+ end
35
+ elsif search_by == 'EXTERNAL_KEY'
36
+ begin
37
+ account = Kaui::Account.find_by_external_key(search_query, false, false, options)
38
+ redirect_to account_path(account.account_id) and return
39
+ rescue KillBillClient::API::NotFound => _e
40
+ search_error("No account matches \"#{search_query}\"")
41
+ end
46
42
  else
47
- redirect_to accounts_path(:q => search_query, :fast => fast) and return
43
+ account = Kaui::Account.list_or_search(search_query, 0, 1, options).first
44
+ if account.blank?
45
+ search_error("No account matches \"#{search_query}\"")
46
+ elsif true?(fast)
47
+ redirect_to account_path(account.account_id) and return
48
+ else
49
+ redirect_to accounts_path(q: search_query, fast:) and return
50
+ end
48
51
  end
49
52
  end
50
- end
51
53
 
52
- def invoice_search(search_query, search_by = nil, fast = 0, options = {})
53
- if search_by == 'ID'
54
- begin
55
- invoice = Kaui::Invoice.find_by_id(search_query, 'NONE', options)
56
- redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
57
- rescue KillBillClient::API::NotFound => _
58
- search_error("No invoice matches \"#{search_query}\"")
59
- end
60
- elsif search_by == 'EXTERNAL_KEY'
61
- unsupported_external_key_search('INVOICE')
62
- else
63
- invoice = Kaui::Invoice.list_or_search(search_query, 0, 1, options).first
64
- if invoice.blank?
54
+ def invoice_search(search_query, search_by = nil, fast = 0, options = {})
55
+ if search_by == 'ID'
65
56
  begin
66
- invoice = Kaui::Invoice.find_by_invoice_item_id(search_query, false, 'NONE', options)
57
+ invoice = Kaui::Invoice.find_by_id(search_query, 'NONE', options)
67
58
  redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
68
- rescue KillBillClient::API::NotFound => _
59
+ rescue KillBillClient::API::NotFound => _e
69
60
  search_error("No invoice matches \"#{search_query}\"")
70
61
  end
71
- elsif true?(fast)
72
- redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
62
+ elsif search_by == 'EXTERNAL_KEY'
63
+ unsupported_external_key_search('INVOICE')
73
64
  else
74
- redirect_to account_invoices_path(:account_id => invoice.account_id, :q => search_query, :fast => fast) and return
65
+ invoice = Kaui::Invoice.list_or_search(search_query, 0, 1, options).first
66
+ if invoice.blank?
67
+ begin
68
+ invoice = Kaui::Invoice.find_by_invoice_item_id(search_query, false, 'NONE', options)
69
+ redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
70
+ rescue KillBillClient::API::NotFound => _e
71
+ search_error("No invoice matches \"#{search_query}\"")
72
+ end
73
+ elsif true?(fast)
74
+ redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
75
+ else
76
+ redirect_to account_invoices_path(account_id: invoice.account_id, q: search_query, fast:) and return
77
+ end
75
78
  end
76
79
  end
77
- end
78
80
 
79
- def payment_search(search_query, search_by = nil, fast = 0, options = {})
80
- if search_by == 'ID'
81
- begin
82
- payment = Kaui::Payment.find_by_id(search_query, false, false, options)
83
- redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
84
- rescue KillBillClient::API::NotFound => _
85
- search_error("No payment matches \"#{search_query}\"")
86
- end
87
- elsif search_by == 'EXTERNAL_KEY'
88
- begin
89
- payment = Kaui::Payment.find_by_external_key(search_query, false, false, options)
90
- redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
91
- rescue KillBillClient::API::NotFound => _
92
- search_error("No payment matches \"#{search_query}\"")
93
- end
94
- else
95
- payment = Kaui::Payment.list_or_search(search_query, 0, 1, options).first
96
- if payment.blank?
97
- search_error("No payment matches \"#{search_query}\"")
98
- elsif true?(fast)
99
- redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
81
+ def payment_search(search_query, search_by = nil, fast = 0, options = {})
82
+ if search_by == 'ID'
83
+ begin
84
+ payment = Kaui::Payment.find_by_id(search_query, false, false, options)
85
+ redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
86
+ rescue KillBillClient::API::NotFound => _e
87
+ search_error("No payment matches \"#{search_query}\"")
88
+ end
89
+ elsif search_by == 'EXTERNAL_KEY'
90
+ begin
91
+ payment = Kaui::Payment.find_by_external_key(search_query, false, false, options)
92
+ redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
93
+ rescue KillBillClient::API::NotFound => _e
94
+ search_error("No payment matches \"#{search_query}\"")
95
+ end
100
96
  else
101
- redirect_to account_payments_path(:account_id => payment.account_id, :q => search_query, :fast => fast) and return
97
+ payment = Kaui::Payment.list_or_search(search_query, 0, 1, options).first
98
+ if payment.blank?
99
+ search_error("No payment matches \"#{search_query}\"")
100
+ elsif true?(fast)
101
+ redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
102
+ else
103
+ redirect_to account_payments_path(account_id: payment.account_id, q: search_query, fast:) and return
104
+ end
102
105
  end
103
106
  end
104
- end
105
107
 
106
- def transaction_search(search_query, search_by = nil, fast = 0, options = {})
107
- if search_by.blank? || search_by == 'ID'
108
- begin
109
- payment = Kaui::Payment.find_by_transaction_id(search_query, false, true, options)
110
- redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
111
- rescue KillBillClient::API::NotFound => _
112
- search_error("No transaction matches \"#{search_query}\"")
113
- end
114
- else
115
- begin
116
- payment = Kaui::Payment.find_by_transaction_external_key(search_query, false, true, 'NONE', options)
117
- redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
118
- rescue KillBillClient::API::NotFound => _
119
- search_error("No transaction matches \"#{search_query}\"")
108
+ def transaction_search(search_query, search_by = nil, _fast = 0, options = {})
109
+ if search_by.blank? || search_by == 'ID'
110
+ begin
111
+ payment = Kaui::Payment.find_by_transaction_id(search_query, false, true, options)
112
+ redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
113
+ rescue KillBillClient::API::NotFound => _e
114
+ search_error("No transaction matches \"#{search_query}\"")
115
+ end
116
+ else
117
+ begin
118
+ payment = Kaui::Payment.find_by_transaction_external_key(search_query, false, true, 'NONE', options)
119
+ redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
120
+ rescue KillBillClient::API::NotFound => _e
121
+ search_error("No transaction matches \"#{search_query}\"")
122
+ end
120
123
  end
121
124
  end
122
- end
123
125
 
124
- def bundle_search(search_query, search_by = nil, fast = 0, options = {})
125
- if search_by == 'ID'
126
- begin
127
- bundle = Kaui::Bundle.find_by_id(search_query, options)
128
- redirect_to kaui_engine.account_bundles_path(bundle.account_id) and return
129
- rescue KillBillClient::API::NotFound => _
130
- search_error("No bundle matches \"#{search_query}\"")
131
- end
132
- elsif search_by == 'EXTERNAL_KEY'
133
- begin
134
- bundle = Kaui::Bundle.find_by_external_key(search_query, false, options)
135
- redirect_to kaui_engine.account_bundles_path(bundle.account_id) and return
136
- rescue KillBillClient::API::NotFound => _
137
- search_error("No bundle matches \"#{search_query}\"")
138
- end
139
- else
140
- bundle = Kaui::Bundle.list_or_search(search_query, 0, 1, options).first
141
- if bundle.blank?
142
- search_error("No bundle matches \"#{search_query}\"")
126
+ def bundle_search(search_query, search_by = nil, _fast = 0, options = {})
127
+ if search_by == 'ID'
128
+ begin
129
+ bundle = Kaui::Bundle.find_by_id(search_query, options)
130
+ redirect_to kaui_engine.account_bundles_path(bundle.account_id)
131
+ rescue KillBillClient::API::NotFound => _e
132
+ search_error("No bundle matches \"#{search_query}\"")
133
+ end
134
+ elsif search_by == 'EXTERNAL_KEY'
135
+ begin
136
+ bundle = Kaui::Bundle.find_by_external_key(search_query, false, options)
137
+ redirect_to kaui_engine.account_bundles_path(bundle.account_id) and return
138
+ rescue KillBillClient::API::NotFound => _e
139
+ search_error("No bundle matches \"#{search_query}\"")
140
+ end
143
141
  else
144
- redirect_to kaui_engine.account_bundles_path(bundle.account_id) and return
142
+ bundle = Kaui::Bundle.list_or_search(search_query, 0, 1, options).first
143
+ if bundle.blank?
144
+ search_error("No bundle matches \"#{search_query}\"")
145
+ else
146
+ redirect_to kaui_engine.account_bundles_path(bundle.account_id)
147
+ end
145
148
  end
146
149
  end
147
- end
148
150
 
149
- def credit_search(search_query, search_by = nil, fast = 0, options = {})
150
- if search_by.blank? || search_by == 'ID'
151
- begin
152
- credit = Kaui::Credit.find_by_id(search_query, options)
153
- redirect_to account_invoice_path(credit.account_id, credit.invoice_id) and return
154
- rescue KillBillClient::API::NotFound => _
155
- search_error("No credit matches \"#{search_query}\"")
151
+ def credit_search(search_query, search_by = nil, _fast = 0, options = {})
152
+ if search_by.blank? || search_by == 'ID'
153
+ begin
154
+ credit = Kaui::Credit.find_by_id(search_query, options)
155
+ redirect_to account_invoice_path(credit.account_id, credit.invoice_id) and return
156
+ rescue KillBillClient::API::NotFound => _e
157
+ search_error("No credit matches \"#{search_query}\"")
158
+ end
159
+ else
160
+ unsupported_external_key_search('CREDIT')
156
161
  end
157
- else
158
- unsupported_external_key_search('CREDIT')
159
162
  end
160
- end
161
163
 
162
- def custom_field_search(search_query, search_by = nil, fast = 0, options = {})
163
- if search_by.blank? || search_by == 'ID'
164
- custom_field = Kaui::CustomField.list_or_search(search_query, 0, 1, options)
165
- if custom_field.blank?
166
- search_error("No custom field matches \"#{search_query}\"")
164
+ def custom_field_search(search_query, search_by = nil, fast = 0, options = {})
165
+ if search_by.blank? || search_by == 'ID'
166
+ custom_field = Kaui::CustomField.list_or_search(search_query, 0, 1, options)
167
+ if custom_field.blank?
168
+ search_error("No custom field matches \"#{search_query}\"")
169
+ else
170
+ redirect_to custom_fields_path(q: search_query, fast:)
171
+ end
167
172
  else
168
- redirect_to custom_fields_path(:q => search_query, :fast => fast) and return
173
+ unsupported_external_key_search('CUSTOM FIELD')
169
174
  end
170
- else
171
- unsupported_external_key_search('CUSTOM FIELD')
172
175
  end
173
- end
174
176
 
175
- def invoice_payment_search(search_query, search_by = nil, fast = 0, options = {})
176
- if search_by.blank? || search_by == 'ID'
177
- begin
178
- invoice_payment = Kaui::InvoicePayment.find_safely_by_id(search_query, options)
179
- redirect_to account_payment_path(invoice_payment.account_id, invoice_payment.payment_id) and return
180
- rescue KillBillClient::API::NotFound => _
181
- search_error("No invoice payment matches \"#{search_query}\"")
177
+ def invoice_payment_search(search_query, search_by = nil, _fast = 0, options = {})
178
+ if search_by.blank? || search_by == 'ID'
179
+ begin
180
+ invoice_payment = Kaui::InvoicePayment.find_safely_by_id(search_query, options)
181
+ redirect_to account_payment_path(invoice_payment.account_id, invoice_payment.payment_id) and return
182
+ rescue KillBillClient::API::NotFound => _e
183
+ search_error("No invoice payment matches \"#{search_query}\"")
184
+ end
185
+ else
186
+ unsupported_external_key_search('INVOICE PAYMENT')
182
187
  end
183
- else
184
- unsupported_external_key_search('INVOICE PAYMENT')
185
188
  end
186
- end
187
189
 
188
- def subscription_search(search_query, search_by = nil, fast = 0, options = {})
189
- if search_by.blank? || search_by == 'ID'
190
- begin
191
- subscription = Kaui::Subscription.find_by_id(search_query, options)
192
- redirect_to account_bundles_path(subscription.account_id) and return
193
- rescue KillBillClient::API::NotFound => _
194
- search_error("No subscription matches \"#{search_query}\"")
190
+ def subscription_search(search_query, search_by = nil, _fast = 0, options = {})
191
+ if search_by.blank? || search_by == 'ID'
192
+ begin
193
+ subscription = Kaui::Subscription.find_by_id(search_query, options)
194
+ redirect_to account_bundles_path(subscription.account_id) and return
195
+ rescue KillBillClient::API::NotFound => _e
196
+ search_error("No subscription matches \"#{search_query}\"")
197
+ end
198
+ else
199
+ unsupported_external_key_search('SUBSCRIPTION')
195
200
  end
196
- else
197
- unsupported_external_key_search('SUBSCRIPTION')
198
201
  end
199
- end
200
202
 
201
- def tag_search(search_query, search_by = nil, fast = 0, options = {})
202
- if search_by.blank? || search_by == 'ID'
203
- tag = Kaui::Tag.list_or_search(search_query, 0, 1, options)
204
- if tag.blank?
205
- search_error("No tag matches \"#{search_query}\"")
203
+ def tag_search(search_query, search_by = nil, fast = 0, options = {})
204
+ if search_by.blank? || search_by == 'ID'
205
+ tag = Kaui::Tag.list_or_search(search_query, 0, 1, options)
206
+ if tag.blank?
207
+ search_error("No tag matches \"#{search_query}\"")
208
+ else
209
+ redirect_to tags_path(q: search_query, fast:)
210
+ end
206
211
  else
207
- redirect_to tags_path(:q => search_query, :fast => fast) and return
212
+ unsupported_external_key_search('TAG')
208
213
  end
209
- else
210
- unsupported_external_key_search('TAG')
211
214
  end
212
- end
213
215
 
214
- def tag_definition_search(search_query, search_by = nil, fast = 0, options = {})
215
- if search_by == 'ID'
216
- begin
217
- Kaui::TagDefinition.find_by_id(search_query, 'NONE', options)
218
- redirect_to tag_definitions_path(:q => search_query, :fast => fast) and return
219
- rescue KillBillClient::API::NotFound => _
220
- search_error("No tag definition matches \"#{search_query}\"")
221
- end
222
- elsif search_by == 'EXTERNAL_KEY'
223
- unsupported_external_key_search('TAG DEFINITION')
224
- else
225
- tag_definition = Kaui::TagDefinition.find_by_name(search_query, 'NONE', options)
226
- if tag_definition.blank?
216
+ def tag_definition_search(search_query, search_by = nil, fast = 0, options = {})
217
+ if search_by == 'ID'
227
218
  begin
228
219
  Kaui::TagDefinition.find_by_id(search_query, 'NONE', options)
229
- redirect_to tag_definitions_path(:q => search_query, :fast => fast) and return
230
- rescue KillBillClient::API::NotFound => _
220
+ redirect_to tag_definitions_path(q: search_query, fast:)
221
+ rescue KillBillClient::API::NotFound => _e
231
222
  search_error("No tag definition matches \"#{search_query}\"")
232
223
  end
224
+ elsif search_by == 'EXTERNAL_KEY'
225
+ unsupported_external_key_search('TAG DEFINITION')
233
226
  else
234
- redirect_to tag_definitions_path(:q => search_query, :fast => fast) and return
227
+ tag_definition = Kaui::TagDefinition.find_by_name(search_query, 'NONE', options)
228
+ if tag_definition.blank?
229
+ begin
230
+ Kaui::TagDefinition.find_by_id(search_query, 'NONE', options)
231
+ redirect_to tag_definitions_path(q: search_query, fast:) and return
232
+ rescue KillBillClient::API::NotFound => _e
233
+ search_error("No tag definition matches \"#{search_query}\"")
234
+ end
235
+ else
236
+ redirect_to tag_definitions_path(q: search_query, fast:)
237
+ end
235
238
  end
236
239
  end
237
- end
238
240
 
239
- def unsupported_external_key_search(object_type)
240
- search_error("\"#{object_type}\": Search by \"EXTERNAL KEY\" is not supported.")
241
- end
241
+ def unsupported_external_key_search(object_type)
242
+ search_error("\"#{object_type}\": Search by \"EXTERNAL KEY\" is not supported.")
243
+ end
242
244
 
243
- def search_error(message)
244
- flash[:error] = message
245
- redirect_to kaui_engine.home_path and return
246
- end
245
+ def search_error(message)
246
+ flash[:error] = message
247
+ redirect_to kaui_engine.home_path
248
+ end
247
249
 
248
- def parse_query(query)
249
- statements, simple_regex_used = regex_parse_query(query)
250
+ def parse_query(query)
251
+ statements, simple_regex_used = regex_parse_query(query)
252
+
253
+ object_type = begin
254
+ statements[:object_type].strip.downcase
255
+ rescue StandardError
256
+ 'account'
257
+ end
258
+ search_for = statements[:search_for].strip
259
+ search_by = begin
260
+ statements[:search_by].strip.upcase
261
+ rescue StandardError
262
+ simple_regex_used && uuid?(search_for) ? 'ID' : nil
263
+ end
264
+ fast = begin
265
+ statements[:fast]
266
+ rescue StandardError
267
+ '0'
268
+ end
250
269
 
251
- object_type = statements[:object_type].strip.downcase rescue 'account'
252
- search_for = statements[:search_for].strip
253
- search_by = statements[:search_by].strip.upcase rescue simple_regex_used && uuid?(search_for) ? 'ID' : nil
254
- fast = statements[:fast] rescue '0'
270
+ search_error("\"#{search_by}\" is not a valid search by value") if !search_by.blank? && !%w[ID EXTERNAL_KEY].include?(search_by)
255
271
 
256
- if !search_by.blank? && !(search_by == 'ID' || search_by == 'EXTERNAL_KEY')
257
- search_error("\"#{search_by}\" is not a valid search by value")
272
+ [object_type, search_for, search_by, fast]
258
273
  end
259
274
 
260
- return object_type, search_for, search_by, fast
261
- end
275
+ def regex_parse_query(query)
276
+ statements = nil
277
+ simple_regex_used = false
278
+ QUERY_PARSE_REGEX.each do |query_regex|
279
+ regex_exp = Regexp.new(query_regex, true)
280
+ statements = regex_exp.match(query)
281
+ break unless statements.nil?
282
+ end
262
283
 
263
- def regex_parse_query(query)
264
- statements = nil
265
- simple_regex_used = false
266
- QUERY_PARSE_REGEX.each do |query_regex|
267
- regex_exp = Regexp.new(query_regex, true)
268
- statements = regex_exp.match(query)
269
- break unless statements.nil?
270
- end
284
+ if statements.nil?
285
+ regex_exp = Regexp.new(SIMPLE_PARSE_REGEX, true)
286
+ statements = regex_exp.match(query)
287
+ simple_regex_used = true
288
+ end
271
289
 
272
- if statements.nil?
273
- regex_exp = Regexp.new(SIMPLE_PARSE_REGEX, true)
274
- statements = regex_exp.match(query)
275
- simple_regex_used = true
290
+ [statements, simple_regex_used]
276
291
  end
277
292
 
278
- return statements, simple_regex_used
279
- end
280
-
281
- def true?(statement)
282
- [1,'1',true,'true'].include? ((statement.instance_of? String) ? statement.downcase : statement)
283
- end
293
+ def true?(statement)
294
+ [1, '1', true, 'true'].include?(statement.instance_of?(String) ? statement.downcase : statement)
295
+ end
284
296
 
285
- def uuid?(value)
286
- value =~ /[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}/
297
+ def uuid?(value)
298
+ value =~ /[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}/
299
+ end
287
300
  end
288
301
  end
@@ -1,54 +1,58 @@
1
- class Kaui::InvoiceItemsController < Kaui::EngineController
1
+ # frozen_string_literal: true
2
2
 
3
- def edit
4
- invoice_item_id = params.require(:id)
5
- invoice_id = params.require(:invoice_id)
3
+ module Kaui
4
+ class InvoiceItemsController < Kaui::EngineController
5
+ def edit
6
+ invoice_item_id = params.require(:id)
7
+ invoice_id = params.require(:invoice_id)
6
8
 
7
- # See https://github.com/killbill/killbill/issues/7
8
- invoice = Kaui::Invoice.find_by_id(invoice_id, 'NONE', options_for_klient)
9
- @invoice_item = invoice.items.find { |ii| ii.invoice_item_id == invoice_item_id }
9
+ # See https://github.com/killbill/killbill/issues/7
10
+ invoice = Kaui::Invoice.find_by_id(invoice_id, 'NONE', options_for_klient)
11
+ @invoice_item = invoice.items.find { |ii| ii.invoice_item_id == invoice_item_id }
12
+
13
+ return unless @invoice_item.nil?
10
14
 
11
- if @invoice_item.nil?
12
15
  flash[:error] = "Unable to find invoice item #{invoice_item_id}"
13
16
  redirect_to account_invoice_path(params.require(:account_id), invoice_id)
14
17
  end
15
- end
16
18
 
17
- def update
18
- @invoice_item = Kaui::InvoiceItem.new(params.require(:invoice_item))
19
+ def update
20
+ @invoice_item = Kaui::InvoiceItem.new(params.require(:invoice_item))
19
21
 
20
- begin
21
- invoice = @invoice_item.update(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
22
- redirect_to kaui_engine.account_invoice_path(invoice.account_id, invoice.invoice_id), :notice => 'Adjustment item was successfully created'
23
- rescue => e
24
- flash.now[:error] = "Error while adjusting invoice item: #{as_string(e)}"
25
- render :action => :edit
22
+ begin
23
+ invoice = @invoice_item.update(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
24
+ redirect_to kaui_engine.account_invoice_path(invoice.account_id, invoice.invoice_id), notice: 'Adjustment item was successfully created'
25
+ rescue StandardError => e
26
+ flash.now[:error] = "Error while adjusting invoice item: #{as_string(e)}"
27
+ render action: :edit
28
+ end
26
29
  end
27
- end
28
30
 
29
- def destroy
30
- invoice_item = Kaui::InvoiceItem.new(:invoice_item_id => params.require(:id),
31
- :invoice_id => params.require(:invoice_id),
32
- :account_id => params.require(:account_id))
33
-
34
- invoice_item.delete(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
35
- redirect_to kaui_engine.account_invoice_path(invoice_item.account_id, invoice_item.invoice_id), :notice => 'CBA item was successfully deleted'
36
- end
31
+ def destroy
32
+ invoice_item = Kaui::InvoiceItem.new(invoice_item_id: params.require(:id),
33
+ invoice_id: params.require(:invoice_id),
34
+ account_id: params.require(:account_id))
37
35
 
38
- def update_tags
39
- @invoice_item = Kaui::InvoiceItem.new(:invoice_item_id => params.require(:id))
40
- invoice_id = params.require(:invoice_id)
41
- account_id = params.require(:account_id)
42
- @invoice_item.account_id = account_id
43
-
44
- tags = []
45
- params.each do |tag|
46
- tag_info = tag.split('_')
47
- next if tag_info.size != 2 or tag_info[0] != 'tag'
48
- tags << tag_info[1]
36
+ invoice_item.delete(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
37
+ redirect_to kaui_engine.account_invoice_path(invoice_item.account_id, invoice_item.invoice_id), notice: 'CBA item was successfully deleted'
49
38
  end
50
39
 
51
- @invoice_item.set_tags(tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
52
- redirect_to account_invoice_path(account_id, invoice_id), :notice => 'Invoice Item tags successfully set'
40
+ def update_tags
41
+ @invoice_item = Kaui::InvoiceItem.new(invoice_item_id: params.require(:id))
42
+ invoice_id = params.require(:invoice_id)
43
+ account_id = params.require(:account_id)
44
+ @invoice_item.account_id = account_id
45
+
46
+ tags = []
47
+ params.each do |tag|
48
+ tag_info = tag.split('_')
49
+ next if (tag_info.size != 2) || (tag_info[0] != 'tag')
50
+
51
+ tags << tag_info[1]
52
+ end
53
+
54
+ @invoice_item.set_tags(tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
55
+ redirect_to account_invoice_path(account_id, invoice_id), notice: 'Invoice Item tags successfully set'
56
+ end
53
57
  end
54
58
  end