kaui 2.0.4 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (276) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +8 -23
  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} +13 -1
  11. data/app/assets/stylesheets/kaui/{audit.less → audit.scss} +5 -1
  12. data/app/assets/stylesheets/kaui/{common.less → common.scss} +19 -17
  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 +269 -255
  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 +87 -84
  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 +132 -114
  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 +32 -0
  46. data/app/controllers/kaui/invoices_controller.rb +134 -88
  47. data/app/controllers/kaui/login_proxy_controller.rb +2 -1
  48. data/app/controllers/kaui/payment_methods_controller.rb +103 -90
  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 +22 -12
  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 +9 -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 +5 -1
  111. data/app/views/kaui/accounts/_form.html.erb +2 -2
  112. data/app/views/kaui/accounts/_payment_methods.html.erb +3 -0
  113. data/app/views/kaui/accounts/index.html.erb +9 -4
  114. data/app/views/kaui/admin_allowed_users/_form.html.erb +3 -3
  115. data/app/views/kaui/admin_tenants/_form_catalog_translation.erb +1 -1
  116. data/app/views/kaui/admin_tenants/_form_invoice_template.erb +1 -1
  117. data/app/views/kaui/admin_tenants/_form_invoice_translation.erb +1 -1
  118. data/app/views/kaui/admin_tenants/_form_plugin_config.erb +13 -3
  119. data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +11 -5
  120. data/app/views/kaui/admin_tenants/new_catalog.html.erb +2 -2
  121. data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +2 -2
  122. data/app/views/kaui/admin_tenants/new_plan_currency.html.erb +1 -1
  123. data/app/views/kaui/bundles/_bundle_details.html.erb +12 -0
  124. data/app/views/kaui/bundles/index.html.erb +3 -14
  125. data/app/views/kaui/bundles/transfer.html.erb +13 -5
  126. data/app/views/kaui/invoice_tags/_form.html.erb +33 -0
  127. data/app/views/kaui/invoice_tags/_form_bar.html.erb +21 -0
  128. data/app/views/kaui/invoice_tags/edit.html.erb +10 -0
  129. data/app/views/kaui/invoices/_invoice_table.html.erb +29 -8
  130. data/app/views/kaui/invoices/index.html.erb +6 -4
  131. data/app/views/kaui/invoices/show.html.erb +10 -1
  132. data/app/views/kaui/layouts/kaui_flash.html.erb +32 -1
  133. data/app/views/kaui/layouts/kaui_header.html.erb +19 -2
  134. data/app/views/kaui/payment_methods/_payment_methods_details_table.html.erb +13 -4
  135. data/app/views/kaui/payments/_payment_table.html.erb +21 -11
  136. data/app/views/kaui/payments/index.html.erb +12 -10
  137. data/app/views/kaui/queues/index.html.erb +1 -1
  138. data/app/views/kaui/subscriptions/_cancel_by_date_modal.html.erb +1 -4
  139. data/app/views/kaui/subscriptions/_edit_form.html.erb +1 -1
  140. data/app/views/kaui/subscriptions/_form.html.erb +1 -1
  141. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +3 -3
  142. data/app/views/kaui/subscriptions/edit_bcd.erb +1 -1
  143. data/app/views/kaui/tag_definitions/index.html.erb +2 -2
  144. data/app/views/kaui/tags/index.html.erb +1 -0
  145. data/config/initializers/bootstrap_datepicker_rails.rb +3 -0
  146. data/config/initializers/devise.rb +8 -6
  147. data/config/initializers/js_routes.rb +9 -0
  148. data/config/initializers/kilbill_client_init.rb +13 -0
  149. data/config/initializers/killbill_authenticatable.rb +71 -21
  150. data/config/initializers/killbill_registerable.rb +5 -3
  151. data/config/initializers/time_formats.rb +6 -4
  152. data/config/locales/en.yml +78 -1
  153. data/config/routes.rb +40 -32
  154. data/db/migrate/20130812155313_devise_create_kaui_users.rb +10 -8
  155. data/db/migrate/20150109214021_create_kaui_tenants.rb +10 -8
  156. data/db/migrate/20150112232813_create_kaui_allowed_users.rb +10 -8
  157. data/lib/generators/kaui/install/install_generator.rb +23 -20
  158. data/lib/generators/kaui/install/templates/config/initializers/kaui.rb +3 -1
  159. data/lib/kaui/engine.rb +17 -5
  160. data/lib/kaui/installer/installer.rb +27 -26
  161. data/lib/kaui/version.rb +3 -1
  162. data/lib/kaui.rb +76 -23
  163. data/lib/tasks/kaui_tasks.rake +1 -0
  164. metadata +141 -436
  165. data/app/assets/javascripts/application.js +0 -17
  166. data/app/assets/javascripts/kaui/bootstrap-tweaks.js +0 -172
  167. data/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -44
  168. data/app/assets/stylesheets/kaui/kaui.less +0 -21
  169. data/app/assets/stylesheets/kaui/timeline.less +0 -4
  170. data/config/initializers/asset.rb +0 -1
  171. data/config/initializers/kilbill-client-init.rb +0 -9
  172. data/db/schema.rb +0 -15
  173. data/test/dummy/README.rdoc +0 -261
  174. data/test/dummy/Rakefile +0 -7
  175. data/test/dummy/app/controllers/application_controller.rb +0 -9
  176. data/test/dummy/app/helpers/application_helper.rb +0 -2
  177. data/test/dummy/bin/bundle +0 -3
  178. data/test/dummy/bin/rails +0 -4
  179. data/test/dummy/bin/rake +0 -4
  180. data/test/dummy/bin/setup +0 -38
  181. data/test/dummy/bin/update +0 -29
  182. data/test/dummy/bin/yarn +0 -11
  183. data/test/dummy/config/application.rb +0 -18
  184. data/test/dummy/config/boot.rb +0 -3
  185. data/test/dummy/config/database.yml +0 -27
  186. data/test/dummy/config/environment.rb +0 -5
  187. data/test/dummy/config/environments/development.rb +0 -58
  188. data/test/dummy/config/environments/production.rb +0 -91
  189. data/test/dummy/config/environments/test.rb +0 -49
  190. data/test/dummy/config/initializers/application_controller_renderer.rb +0 -6
  191. data/test/dummy/config/initializers/assets.rb +0 -14
  192. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  193. data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
  194. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  195. data/test/dummy/config/initializers/inflections.rb +0 -16
  196. data/test/dummy/config/initializers/killbill_client.rb +0 -1
  197. data/test/dummy/config/initializers/mime_types.rb +0 -4
  198. data/test/dummy/config/initializers/new_framework_defaults_5_1.rb +0 -14
  199. data/test/dummy/config/initializers/secret_token.rb +0 -7
  200. data/test/dummy/config/initializers/session_store.rb +0 -8
  201. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  202. data/test/dummy/config/locales/en.yml +0 -33
  203. data/test/dummy/config/routes.rb +0 -3
  204. data/test/dummy/config/secrets.yml +0 -32
  205. data/test/dummy/config/symmetric-encryption.yml +0 -135
  206. data/test/dummy/config.ru +0 -4
  207. data/test/dummy/db/schema.rb +0 -52
  208. data/test/dummy/public/404.html +0 -26
  209. data/test/dummy/public/422.html +0 -26
  210. data/test/dummy/public/500.html +0 -25
  211. data/test/dummy/public/favicon.ico +0 -0
  212. data/test/dummy/script/rails +0 -6
  213. data/test/fixtures/SpyCarAdvanced.xml +0 -824
  214. data/test/fixtures/catalog-v1.xml +0 -73
  215. data/test/fixtures/catalog_translation_fr-v1.properties +0 -1
  216. data/test/fixtures/invoice_template-v1.html +0 -100
  217. data/test/fixtures/invoice_translation_fr-v1.properties +0 -23
  218. data/test/fixtures/overdue-v1.xml +0 -49
  219. data/test/fixtures/stripe.yml +0 -2
  220. data/test/functional/kaui/account_children_controller_test.rb +0 -32
  221. data/test/functional/kaui/account_custom_fields_controller_test.rb +0 -29
  222. data/test/functional/kaui/account_emails_controller_test.rb +0 -55
  223. data/test/functional/kaui/account_tags_controller_test.rb +0 -48
  224. data/test/functional/kaui/account_timelines_controller_test.rb +0 -20
  225. data/test/functional/kaui/accounts_controller_test.rb +0 -297
  226. data/test/functional/kaui/admin_allowed_users_controller_test.rb +0 -234
  227. data/test/functional/kaui/admin_controller_test.rb +0 -45
  228. data/test/functional/kaui/admin_tenants_controller_test.rb +0 -352
  229. data/test/functional/kaui/audit_logs_controller_test.rb +0 -71
  230. data/test/functional/kaui/bundle_tags_controller_test.rb +0 -23
  231. data/test/functional/kaui/bundles_controller_test.rb +0 -130
  232. data/test/functional/kaui/chargebacks_controller_test.rb +0 -42
  233. data/test/functional/kaui/charges_controller_test.rb +0 -60
  234. data/test/functional/kaui/credits_controller_test.rb +0 -54
  235. data/test/functional/kaui/custom_fields_controller_test.rb +0 -52
  236. data/test/functional/kaui/functional_test_helper.rb +0 -13
  237. data/test/functional/kaui/functional_test_helper_nosetup.rb +0 -120
  238. data/test/functional/kaui/home_controller_test.rb +0 -407
  239. data/test/functional/kaui/invoice_items_controller_test.rb +0 -82
  240. data/test/functional/kaui/invoices_controller_test.rb +0 -88
  241. data/test/functional/kaui/login_proxy_controller_test.rb +0 -12
  242. data/test/functional/kaui/payment_methods_controller_test.rb +0 -52
  243. data/test/functional/kaui/payments_controller_test.rb +0 -59
  244. data/test/functional/kaui/queues_controller_test.rb +0 -17
  245. data/test/functional/kaui/refunds_controller_test.rb +0 -63
  246. data/test/functional/kaui/registrations_controller_test.rb +0 -49
  247. data/test/functional/kaui/role_definitions_controller_test.rb +0 -47
  248. data/test/functional/kaui/subscriptions_controller_test.rb +0 -194
  249. data/test/functional/kaui/tag_definitions_controller_test.rb +0 -29
  250. data/test/functional/kaui/tags_controller_test.rb +0 -21
  251. data/test/functional/kaui/tenants_controller_test.rb +0 -60
  252. data/test/functional/kaui/transactions_controller_test.rb +0 -90
  253. data/test/integration/kaui/date_helper_integration_test.rb +0 -16
  254. data/test/integration/kaui/integration_test_helper.rb +0 -32
  255. data/test/integration/kaui/navigation_test.rb +0 -43
  256. data/test/killbill_test_helper.rb +0 -217
  257. data/test/test_helper.rb +0 -22
  258. data/test/unit/helpers/kaui/admin_allowed_users_helper_test.rb +0 -6
  259. data/test/unit/helpers/kaui/admin_tenants_helper_test.rb +0 -6
  260. data/test/unit/helpers/kaui/payment_method_helper_test.rb +0 -17
  261. data/test/unit/helpers/kaui/tenants_helper_test.rb +0 -6
  262. data/test/unit/helpers/kaui/uuid_helper_test.rb +0 -16
  263. data/test/unit/kaui/account_email_test.rb +0 -19
  264. data/test/unit/kaui/account_test.rb +0 -14
  265. data/test/unit/kaui/admin_tenant_test.rb +0 -132
  266. data/test/unit/kaui/allowed_user_test.rb +0 -34
  267. data/test/unit/kaui/base_test.rb +0 -23
  268. data/test/unit/kaui/date_helper_test.rb +0 -26
  269. data/test/unit/kaui/invoice_item_test.rb +0 -11
  270. data/test/unit/kaui/invoice_payment_test.rb +0 -42
  271. data/test/unit/kaui/invoice_test.rb +0 -20
  272. data/test/unit/kaui/money_helper_test.rb +0 -16
  273. data/test/unit/kaui/payment_test.rb +0 -42
  274. data/test/unit/kaui/tag_definition_test.rb +0 -11
  275. data/test/unit/kaui/tenant_test.rb +0 -19
  276. /data/app/assets/stylesheets/{application.css → kaui_application.css} +0 -0
@@ -1,44 +1,94 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'devise/strategies/authenticatable'
4
+ require 'jwt'
2
5
 
3
6
  module Devise
4
7
  module Strategies
8
+ module KillbillHelpers
9
+ def kb_authenticate!(kb_username, creds)
10
+ # Find the associated user object (see find_for_killbill_authentication in app/models/kaui/killbill_authenticatable.rb)
11
+ resource = mapping.to.find_for_killbill_authentication(kb_username)
12
+
13
+ # Validate the credentials (see valid_killbill_password? in app/models/kaui/killbill_authenticatable.rb)
14
+ return unless validate(resource) { resource.valid_killbill_password?(creds) }
15
+
16
+ # Create the user if needed
17
+ resource.after_killbill_authentication
18
+ # Tell warden to halt the strategy and set the user in the appropriate scope
19
+ success!(resource)
20
+ end
21
+ end
22
+
5
23
  class KillbillAuthenticatable < Authenticatable
6
- # Invoked by warden to execute the strategy
24
+ include KillbillHelpers
25
+
26
+ # Invoked by Warden::Strategies::Base#_run! to execute the strategy
27
+ def authenticate!
28
+ return false unless valid_password?
29
+
30
+ user = params[:user] || {}
31
+ kb_authenticate!(user[:kb_username], { username: user[:kb_username], password: })
32
+ end
33
+ end
34
+
35
+ # Warden strategy to authenticate an user through a JWT token in the `Authorization` request header
36
+ class KillbillJWTAuthenticatable < Authenticatable
37
+ # Must match the Kill Bill configuration (e.g. org.killbill.security.auth0.usernameClaim)
38
+ mattr_accessor :username_claim
39
+ self.username_claim = 'sub'
40
+
41
+ include KillbillHelpers
42
+
43
+ # Invoked by Warden::Strategies::Base#_run! to execute the strategy
7
44
  def authenticate!
45
+ payload, = ::JWT.decode(token, nil, false)
46
+ kb_username = payload[username_claim].presence
47
+ return false unless kb_username
48
+
49
+ kb_authenticate!(kb_username, { bearer: token })
50
+ end
51
+
52
+ def valid?
53
+ !token.nil?
54
+ end
8
55
 
9
- creds = params[:user] || {}
10
- kb_username = creds[:kb_username]
11
- kb_password = password
12
- # Find the associated user object
13
- resource = valid_password? && mapping.to.find_for_killbill_authentication(kb_username)
14
- return fail(:not_found_in_database) unless resource
15
-
16
- # Validate the credentials
17
- if validate(resource){ resource.valid_killbill_password?(kb_username, kb_password) }
18
- # Create the user if needed
19
- resource.after_killbill_authentication
20
- # Tell warden to halt the strategy and set the user in the appropriate scope
21
- success!(resource)
56
+ private
57
+
58
+ def token
59
+ @token ||= begin
60
+ auth = env['HTTP_AUTHORIZATION']
61
+ if auth
62
+ method, token = auth.split
63
+ method == 'Bearer' ? token : nil
64
+ else
65
+ nil
66
+ end
22
67
  end
23
- rescue Errno::ECONNREFUSED => _
24
- return fail(:killbill_not_available)
25
68
  end
26
69
  end
27
70
  end
28
71
  end
29
72
 
30
73
  Warden::Strategies.add(:killbill_authenticatable, Devise::Strategies::KillbillAuthenticatable)
74
+ Warden::Strategies.add(:killbill_jwt, Devise::Strategies::KillbillJWTAuthenticatable)
31
75
 
32
76
  Warden::Manager.after_set_user do |user, auth, opts|
33
77
  unless user.authenticated_with_killbill?
34
78
  scope = opts[:scope]
35
79
  auth.logout(scope)
36
- throw(:warden, :scope => scope, :reason => "Kill Bill session expired")
80
+ throw(:warden, scope:, reason: 'Kill Bill session expired')
37
81
  end
38
82
  end
39
83
 
40
84
  Devise.add_module(:killbill_authenticatable,
41
- :strategy => true,
42
- :route => :session,
43
- :controller => :sessions,
44
- :model => 'kaui/killbill_authenticatable')
85
+ strategy: true,
86
+ route: :session,
87
+ controller: :sessions,
88
+ model: 'kaui/killbill_authenticatable')
89
+
90
+ Devise::Strategies::KillbillJWTAuthenticatable.username_claim = if defined?(JRUBY_VERSION)
91
+ java.lang.System.getProperty('kaui.jwt.username_claim', ENV['KAUI_USERNAME_CLAIM'] || 'sub')
92
+ else
93
+ ENV['KAUI_USERNAME_CLAIM'] || 'sub'
94
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Devise.add_module(:killbill_registerable,
2
- :route => :registration,
3
- :controller => :registrations,
4
- :model => 'kaui/killbill_registerable')
4
+ route: :registration,
5
+ controller: :registrations,
6
+ model: 'kaui/killbill_registerable')
@@ -1,4 +1,6 @@
1
- Time::DATE_FORMATS[:pretty] = "%b %d %Y at %H:%M"
2
- Date::DATE_FORMATS[:pretty] = "%b %d %Y at %H:%M"
3
- Time::DATE_FORMATS[:date_only] = "%Y-%m-%d"
4
- Date::DATE_FORMATS[:date_only] = "%Y-%m-%d"
1
+ # frozen_string_literal: true
2
+
3
+ Time::DATE_FORMATS[:pretty] = '%b %d %Y at %H:%M'
4
+ Date::DATE_FORMATS[:pretty] = '%b %d %Y at %H:%M'
5
+ Time::DATE_FORMATS[:date_only] = '%Y-%m-%d'
6
+ Date::DATE_FORMATS[:date_only] = '%Y-%m-%d'
@@ -1,3 +1,80 @@
1
1
  en:
2
2
  account: "Account"
3
- unknown_bcd: "Unknown bill cycle day"
3
+ new_account: "New Account"
4
+ transfer: "Transfer"
5
+ comment: "Comment"
6
+ change: "Change"
7
+ unknown_bcd: "Unknown bill cycle day"
8
+ payment_method_id: "Payment Method ID:"
9
+ external_key_with_colon: "External Key:"
10
+ external_id_with_colon: "External ID:"
11
+ name_with_colon: "Name:"
12
+ custom_field_created_success: "Custom field was successfully created"
13
+ custom_field_uuid_exist_in_account_db: "UUID do exist in ACCOUNT object database."
14
+ custom_field_uuid_exist_in_bundle_db: "UUID do exist in BUNDLE object database."
15
+ custom_field_uuid_exist_in_subscription_db: "UUID do exist in SUBSCRIPTION object database."
16
+ custom_field_uuid_exist_in_invoice_db: "UUID do exist in INVOICE object database."
17
+ custom_field_uuid_exist_in_payment_db: "UUID do exist in PAYMENT object database."
18
+ custom_field_uuid_exist_in_invoice_payment_db: "UUID do exist in INVOICE PAYMENT object database."
19
+ custom_field_uuid_do_not_exist_in_db: "UUID do not exist in object database."
20
+ custom_field_uuid_exist_in_invoice_item_db: "UUID do exist in INVOICE ITEMS object database."
21
+ immediate: "Immediate"
22
+ start_of_term: "Start of term"
23
+ end_of_term: "End of term"
24
+ billing_policy: "Billing Policy"
25
+ new_account_id_or_external_key: "New account id or external key"
26
+ object_invalid_dont_exist: "Object type INVALID or object id do not exist."
27
+ date: "Date"
28
+ type: "Type"
29
+ amount: "Amount"
30
+ processed_amount: "Processed Amount"
31
+ transaction_external_key: "Transaction external key"
32
+ first_id: "First id"
33
+ second_id: "Second id"
34
+ gateway_code: "Gateway code"
35
+ gateway_message: "Gateway message"
36
+ status: "Status"
37
+ payments: "Payments"
38
+ number: "Number"
39
+ auth_amount: "Auth amount"
40
+ capture_amount: "Capture amount"
41
+ refund_amount: "Refund amount"
42
+ last_transaction_status: "Last transaction status"
43
+ external_key: "External key"
44
+ loading_data_from_server: "Loading data from server"
45
+ requested_amount_colon: "Requested amount: "
46
+
47
+ flashes:
48
+ notices:
49
+ clock_updated_successfully: "Clock was successfully updated to %{new_date}"
50
+ clock_reset_successfully: 'Clock was successfully reset'
51
+ overdue_uploaded_successfully: 'Overdue config was successfully uploaded'
52
+ overdue_added_successfully: 'Overdue config was successfully added'
53
+ invoice_template_uploaded_successfully: 'Invoice template was successfully uploaded'
54
+ invoice_translation_uploaded_successfully: 'Invoice translation was successfully uploaded'
55
+ catalog_translation_uploaded_successfully: 'Catalog translation was successfully uploaded'
56
+ catalog_uploaded_successfully: 'Catalog was successfully uploaded'
57
+
58
+ errors:
59
+ messages:
60
+ invalid_object_type: "Invalid Object Type: %{error}"
61
+ invalid_phone: "Invalid phone number!"
62
+ invalid_bill_cycle_day_local: "Incorrect day of the billing cycle. It should be in the range from 1 to 31."
63
+ invalid_xml: "Invalid XML: %{error}"
64
+ invalid_min_date: "Invalid min date format"
65
+ invalid_max_date: "Invalid max date format"
66
+ views:
67
+ subscriptions:
68
+ requested_date_for_billing_notice: <ul>
69
+ <li>When <span class="label label-default">Use requested date for billing?</span> is checked, then entitlement date and billing date are going to be equal to the requested date.</li>
70
+ <li>When <strong>not</strong> checked, then the entitlement date will be set with requested date, and billing date will be derived from the catalog policy.</li>
71
+ </ul>
72
+ catalogs:
73
+ show:
74
+ plan_table:
75
+ plan_id: "Plan Id"
76
+ product: "Product"
77
+ category: "Category"
78
+ billing_period: "Billing Period"
79
+ trial: "Trial"
80
+ final_phase_duration: "Final Phase Duration"
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionDispatch
2
4
  module Routing
3
5
  class Mapper
@@ -14,13 +16,12 @@ module ActionDispatch
14
16
  end
15
17
 
16
18
  Kaui::Engine.routes.draw do
17
-
18
19
  devise_for :users,
19
- :class_name => 'Kaui::User',
20
- :module => :devise,
21
- :controllers => { :sessions => 'kaui/sessions', :registrations => 'kaui/registrations' }
20
+ class_name: 'Kaui::User',
21
+ module: :devise,
22
+ controllers: { sessions: 'kaui/sessions', registrations: 'kaui/registrations' }
22
23
 
23
- root :to => 'home#index', as: 'kaui'
24
+ root to: 'home#index', as: 'kaui'
24
25
 
25
26
  scope '/accounts' do
26
27
  match '/pagination' => 'accounts#pagination', :via => :get, :as => 'accounts_pagination'
@@ -46,6 +47,10 @@ Kaui::Engine.routes.draw do
46
47
  match '/edit' => 'bundle_tags#edit', :via => :get, :as => 'edit_bundle_tags'
47
48
  match '/edit' => 'bundle_tags#update', :via => :post, :as => 'update_bundle_tags'
48
49
  end
50
+ scope '/invoice_tags' do
51
+ match '/edit' => 'invoice_tags#edit', :via => :get, :as => 'edit_invoice_tags'
52
+ match '/edit' => 'invoice_tags#update', :via => :post, :as => 'update_invoice_tags'
53
+ end
49
54
  scope '/timeline' do
50
55
  match '/' => 'account_timelines#show', :via => :get, :as => 'account_timeline'
51
56
  end
@@ -61,7 +66,7 @@ Kaui::Engine.routes.draw do
61
66
  end
62
67
  end
63
68
  end
64
- resources :accounts, :only => [ :index, :new, :create, :edit, :update, :show, :destroy ], :param => :account_id do
69
+ resources :accounts, only: %i[index new create edit update show destroy], param: :account_id do
65
70
  member do
66
71
  put :set_default_payment_method
67
72
  delete :delete_payment_method
@@ -70,44 +75,46 @@ Kaui::Engine.routes.draw do
70
75
  end
71
76
 
72
77
  # The id is the email itself
73
- resources :account_emails, :only => [:new, :create, :destroy], :constraints => { :id => /[\w+\-;@\.]+/ }, :path => 'emails'
74
- resources :bundles, :only => [:index]
75
- resources :charges, :only => [:new, :create]
76
- resources :chargebacks, :only => [:new, :create]
77
- resources :credits, :only => [:new, :create]
78
- resources :invoices, :only => [:index, :show]
79
- resources :invoice_items, :only => [:edit]
80
- resources :payments, :only => [:index, :show, :new, :create]
81
- resources :refunds, :only => [:new, :create]
82
- resources :transactions, :only => [:new, :create]
83
- resources :queues, :only => [:index]
84
- resources :audit_logs, :only => [:index]
78
+ resources :account_emails, only: %i[new create destroy], constraints: { id: /[\w+\-;@.]+/ }, path: 'emails'
79
+ resources :bundles, only: [:index]
80
+ resources :charges, only: %i[new create]
81
+ resources :chargebacks, only: %i[new create]
82
+ resources :credits, only: %i[new create]
83
+ resources :invoices, only: %i[index show]
84
+ resources :invoice_items, only: [:edit]
85
+ resources :payments, only: %i[index show new create]
86
+ resources :refunds, only: %i[new create]
87
+ resources :transactions, only: %i[new create]
88
+ resources :queues, only: [:index]
89
+ resources :audit_logs, only: [:index]
85
90
  end
86
91
 
87
92
  scope '/payment_methods' do
88
93
  match '/validate_external_key' => 'payment_methods#validate_external_key', :via => :get, :as => 'payment_methods_validate_external_key'
94
+ match '/refresh' => 'payment_methods#refresh', :via => :post, :as => 'refresh_payment_methods'
89
95
  end
90
- resources :payment_methods, :only => [:new, :create, :show, :destroy]
96
+ resources :payment_methods, only: %i[new create show destroy]
91
97
 
92
98
  scope '/invoices' do
93
99
  match '/pagination' => 'invoices#pagination', :via => :get, :as => 'invoices_pagination'
94
100
  match '/:id/show_html' => 'invoices#show_html', :via => :get, :as => 'show_html_invoice'
95
101
  match '/:id' => 'invoices#restful_show', :via => :get, :as => 'invoice'
96
102
  match '/commit' => 'invoices#commit_invoice', :via => :post, :as => 'commit_invoice'
103
+ match '/void' => 'invoices#void_invoice', :via => :delete, :as => 'void_invoice'
97
104
  end
98
- resources :invoices, :only => [ :index ]
105
+ resources :invoices, only: [:index]
99
106
 
100
107
  scope '/invoice_items' do
101
108
  match '/:id/tags' => 'invoice_items#update_tags', :via => :post, :as => 'update_invoice_items_tags'
102
109
  end
103
- resources :invoice_items, :only => [:update, :destroy]
110
+ resources :invoice_items, only: %i[update destroy]
104
111
 
105
112
  scope '/payments' do
106
113
  match '/pagination' => 'payments#pagination', :via => :get, :as => 'payments_pagination'
107
114
  match '/:id' => 'payments#restful_show', :via => :get, :as => 'payment'
108
115
  match '/:id/cancel_scheduled_payment' => 'payments#cancel_scheduled_payment', :via => :delete, :as => 'payment_cancel_scheduled_payment'
109
116
  end
110
- resources :payments, :only => [ :index ]
117
+ resources :payments, only: [:index]
111
118
 
112
119
  scope '/transactions' do
113
120
  match '/:id' => 'transactions#restful_show', :via => :get, :as => 'transaction'
@@ -115,10 +122,10 @@ Kaui::Engine.routes.draw do
115
122
  end
116
123
 
117
124
  scope '/bundles' do
118
- put '/:id/do_pause_resume', :to => 'bundles#do_pause_resume', :as => 'do_pause_resume_bundle'
119
- get '/:id/pause_resume', :to => 'bundles#pause_resume', :as => 'pause_resume_bundle'
120
- put '/:id/do_transfer', :to => 'bundles#do_transfer', :as => 'do_transfer_bundle'
121
- get '/:id/transfer', :to => 'bundles#transfer', :as => 'transfer_bundle'
125
+ put '/:id/do_pause_resume', to: 'bundles#do_pause_resume', as: 'do_pause_resume_bundle'
126
+ get '/:id/pause_resume', to: 'bundles#pause_resume', as: 'pause_resume_bundle'
127
+ put '/:id/do_transfer', to: 'bundles#do_transfer', as: 'do_transfer_bundle'
128
+ get '/:id/transfer', to: 'bundles#transfer', as: 'transfer_bundle'
122
129
  match '/:id' => 'bundles#restful_show', :via => :get, :as => 'bundle'
123
130
  end
124
131
 
@@ -130,19 +137,20 @@ Kaui::Engine.routes.draw do
130
137
  match '/validate_external_key' => 'subscriptions#validate_external_key', :via => :get, :as => 'subscriptions_validate_external_key'
131
138
  match '/validate_bundle_external_key' => 'subscriptions#validate_bundle_external_key', :via => :get, :as => 'subscriptions_validate_bundle_external_key'
132
139
  end
133
- resources :subscriptions, :only => [:new, :create, :show, :edit, :update, :destroy]
140
+ resources :subscriptions, only: %i[new create show edit update destroy]
134
141
 
135
142
  scope '/tags' do
136
143
  match '/pagination' => 'tags#pagination', :via => :get, :as => 'tags_pagination'
137
144
  end
138
- resources :tags, :only => [:index]
145
+ resources :tags, only: [:index]
139
146
 
140
- resources :tag_definitions, :only => [:index, :new, :create, :destroy]
147
+ resources :tag_definitions, only: %i[index new create destroy]
141
148
 
142
149
  scope '/custom_fields' do
143
150
  match '/pagination' => 'custom_fields#pagination', :via => :get, :as => 'custom_fields_pagination'
151
+ match '/check_object_exist' => 'custom_fields#check_object_exist', :via => :get, :as => 'custom_fields_check_object_exist'
144
152
  end
145
- resources :custom_fields, :only => [:index, :new, :create]
153
+ resources :custom_fields, only: %i[index new create check_object_exist]
146
154
 
147
155
  scope '/tenants' do
148
156
  match '/' => 'tenants#index', :via => :get, :as => 'tenants'
@@ -189,12 +197,12 @@ Kaui::Engine.routes.draw do
189
197
  match '/switch' => 'admin_tenants#switch_tenant', :via => :get, :as => 'switch_tenant'
190
198
  match '/:id/download_catalog' => 'admin_tenants#download_catalog_xml', :via => :get, :as => 'download_catalog_xml'
191
199
  end
192
- resources :admin_tenants, :only => [ :index, :new, :create, :show ]
200
+ resources :admin_tenants, only: %i[index new create show]
193
201
 
194
202
  resources :admin_allowed_users
195
203
  scope '/admin_allowed_users' do
196
204
  match '/add_tenant' => 'admin_allowed_users#add_tenant', :via => :post, :as => 'add_tenant'
197
205
  end
198
206
 
199
- resources :role_definitions, :only => [ :new, :create ]
207
+ resources :role_definitions, only: %i[new create]
200
208
  end
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DeviseCreateKauiUsers < ActiveRecord::Migration[5.0]
2
4
  def change
3
- unless table_exists?(:kaui_users)
4
- create_table(:kaui_users) do |t|
5
- # From Kill Bill
6
- t.string :kb_username, :null => false
7
- t.string :kb_session_id, :null => true
8
- t.timestamps
9
- end
5
+ return if table_exists?(:kaui_users)
10
6
 
11
- add_index :kaui_users, [:kb_username], :unique => true
7
+ create_table(:kaui_users) do |t|
8
+ # From Kill Bill
9
+ t.string :kb_username, null: false
10
+ t.string :kb_session_id, null: true
11
+ t.timestamps
12
12
  end
13
+
14
+ add_index :kaui_users, [:kb_username], unique: true
13
15
  end
14
16
  end
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateKauiTenants < ActiveRecord::Migration[5.0]
2
4
  def change
3
- unless table_exists?(:kaui_tenants)
4
- create_table :kaui_tenants do |t|
5
- t.string :name
6
- t.string :kb_tenant_id
7
- t.string :api_key
8
- t.string :encrypted_api_secret
5
+ return if table_exists?(:kaui_tenants)
6
+
7
+ create_table :kaui_tenants do |t|
8
+ t.string :name
9
+ t.string :kb_tenant_id
10
+ t.string :api_key
11
+ t.string :encrypted_api_secret
9
12
 
10
- t.timestamps
11
- end
13
+ t.timestamps
12
14
  end
13
15
  end
14
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateKauiAllowedUsers < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  unless table_exists?(:kaui_allowed_users)
@@ -7,17 +9,17 @@ class CreateKauiAllowedUsers < ActiveRecord::Migration[5.0]
7
9
  t.timestamps
8
10
  end
9
11
 
10
- add_index :kaui_allowed_users, [:kb_username], :unique => true
12
+ add_index :kaui_allowed_users, [:kb_username], unique: true
11
13
  end
12
14
 
13
- unless table_exists?(:kaui_allowed_user_tenants)
14
- create_table :kaui_allowed_user_tenants do |t|
15
- t.belongs_to :kaui_allowed_user
16
- t.belongs_to :kaui_tenant
17
- t.timestamps null: false
18
- end
15
+ return if table_exists?(:kaui_allowed_user_tenants)
19
16
 
20
- add_index :kaui_allowed_user_tenants, [:kaui_allowed_user_id, :kaui_tenant_id], :unique => true, :name => 'kaui_allowed_user_tenants_uniq'
17
+ create_table :kaui_allowed_user_tenants do |t|
18
+ t.belongs_to :kaui_allowed_user
19
+ t.belongs_to :kaui_tenant
20
+ t.timestamps null: false
21
21
  end
22
+
23
+ add_index :kaui_allowed_user_tenants, %i[kaui_allowed_user_id kaui_tenant_id], unique: true, name: 'kaui_allowed_user_tenants_uniq'
22
24
  end
23
25
  end
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators'
2
4
  require 'kaui/version'
3
5
 
4
6
  module Kaui
5
7
  class InstallGenerator < Rails::Generators::Base
6
- class_option :lib_name, :type => :string, :default => 'kaui'
8
+ class_option :lib_name, type: :string, default: 'kaui'
7
9
 
8
10
  def self.source_paths
9
- paths = self.superclass.source_paths
11
+ paths = superclass.source_paths
10
12
  paths << File.expand_path('../templates', "../../#{__FILE__}")
11
13
  paths << File.expand_path('../templates', "../#{__FILE__}")
12
- paths << File.expand_path('../templates', __FILE__)
14
+ paths << File.expand_path('templates', __dir__)
13
15
  paths.flatten
14
16
  end
15
17
 
@@ -18,7 +20,7 @@ module Kaui
18
20
  end
19
21
 
20
22
  def config_kaui_yml
21
- create_file "config/kaui.yml" do
23
+ create_file 'config/kaui.yml' do
22
24
  settings = { 'version' => Kaui::VERSION }
23
25
 
24
26
  settings.to_yaml
@@ -26,43 +28,44 @@ module Kaui
26
28
  end
27
29
 
28
30
  def additional_tweaks
29
- return unless File.exists? 'public/robots.txt'
30
- append_file "public/robots.txt", <<-ROBOTS
31
- User-agent: *
32
- Disallow: /kaui
31
+ return unless File.exist? 'public/robots.txt'
32
+
33
+ append_file 'public/robots.txt', <<~ROBOTS
34
+ User-agent: *
35
+ Disallow: /kaui
33
36
  ROBOTS
34
37
  end
35
38
 
36
39
  def setup_assets
37
40
  @lib_name = 'kaui'
38
- %w{javascripts stylesheets images}.each do |path|
41
+ %w[javascripts stylesheets images].each do |path|
39
42
  empty_directory "app/assets/#{path}/kaui"
40
43
  end
41
44
 
42
- template "app/assets/javascripts/kaui/all.js"
43
- template "app/assets/stylesheets/kaui/all.css"
45
+ template 'app/assets/javascripts/kaui/all.js'
46
+ template 'app/assets/stylesheets/kaui/all.css'
44
47
  end
45
48
 
46
49
  def update_routes
47
- insert_into_file File.join('config', 'routes.rb'), :after => "Application.routes.draw do\n" do
48
- %Q{
50
+ insert_into_file File.join('config', 'routes.rb'), after: "Application.routes.draw do\n" do
51
+ %(
49
52
  # This line mounts Kaui's routes at the root of your application.
50
53
  # If you're mounting this engine into an existing application, change it to e.g.
51
54
  # mount Kaui::Engine, :at => '/kaui', :as => "kaui_engine"
52
55
  #
53
56
  # Don't modify the :as => "kaui_engine" option though.
54
57
  mount Kaui::Engine, :at => '/', :as => "kaui_engine"
55
- }
58
+ )
56
59
  end
57
60
  end
58
61
 
59
62
  def complete
60
- unless options[:quiet]
61
- puts "*" * 50
62
- puts "Kaui has been installed successfully. You're all ready to go!"
63
- puts " "
64
- puts "Enjoy!"
65
- end
63
+ return if options[:quiet]
64
+
65
+ puts '*' * 50
66
+ puts "Kaui has been installed successfully. You're all ready to go!"
67
+ puts ' '
68
+ puts 'Enjoy!'
66
69
  end
67
70
  end
68
71
  end
@@ -1,3 +1,5 @@
1
- # Configure Kaui Preferences
1
+ # frozen_string_literal: true
2
+
2
3
  Kaui.config do |config|
4
+ # Configure Kaui Preferences
3
5
  end
data/lib/kaui/engine.rb CHANGED
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Dependencies
2
4
  #
3
5
  # Sigh. Rails autoloads the gems specified in the Gemfile and nothing else.
4
6
  # We need to explicitly require all of our dependencies listed in kaui.gemspec
5
7
  #
6
8
  # See also https://github.com/carlhuda/bundler/issues/49
9
+
7
10
  require 'js-routes'
8
11
  require 'jquery-rails'
9
12
  require 'jquery-ui-rails'
10
13
  require 'jquery-datatables-rails'
11
- require 'font-awesome-rails'
12
- require 'twitter-bootstrap-rails'
14
+ require 'font-awesome-sass'
15
+ require 'bootstrap-sass'
13
16
  require 'bootstrap-datepicker-rails'
14
- require 'less-rails'
15
17
  require 'json'
16
18
  require 'money-rails'
17
19
  require 'killbill_client'
@@ -21,13 +23,23 @@ require 'cancan'
21
23
  require 'country_select'
22
24
  require 'concurrent'
23
25
  require 'mustache-js-rails'
26
+ require 'nokogiri'
27
+ require 'time'
28
+ require 'd3-rails'
29
+ require 'spinjs-rails'
30
+ require 'popper_js'
24
31
 
25
32
  module Kaui
26
33
  class Engine < ::Rails::Engine
27
34
  isolate_namespace Kaui
35
+ config.autoload_once_paths = %W[
36
+ #{root}/app/controllers
37
+ #{root}/app/helpers
38
+ #{root}/app/models
39
+ ]
28
40
 
29
- initializer 'kaui_engine.action_controller' do |app|
30
- ActiveSupport.on_load :action_controller do
41
+ initializer 'kaui_engine.action_controller', before: :load_config_initializers do |_app|
42
+ ActiveSupport.on_load :action_controller_base do
31
43
  helper Kaui::Engine.helpers
32
44
  end
33
45